-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(orca-clouddriver): replace getType() with StageDefinitionBuilder.…
…getType() for DestroyServerGroup (#4761) * refactor(clouddriver): replace getType() with StageDefinitionBuilder.getType() for destroyServerGroupStage * chore(tests): Adding DestroyServerGroupStage tests --------- Co-authored-by: Jason <[email protected]>
- Loading branch information
1 parent
6d8a721
commit 8424982
Showing
2 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...etflix/spinnaker/orca/clouddriver/pipeline/servergroup/DestroyServerGroupStageSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup | ||
|
||
import com.netflix.spinnaker.kork.dynamicconfig.DynamicConfigService | ||
import com.netflix.spinnaker.orca.api.pipeline.graph.StageDefinitionBuilder | ||
import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionType | ||
import com.netflix.spinnaker.orca.pipeline.graph.StageGraphBuilderImpl | ||
import com.netflix.spinnaker.orca.pipeline.model.PipelineExecutionImpl | ||
import com.netflix.spinnaker.orca.pipeline.model.StageExecutionImpl | ||
import spock.lang.Specification | ||
|
||
class DestroyServerGroupStageSpec extends Specification { | ||
|
||
DynamicConfigService dynamicConfigService = Mock(DynamicConfigService) | ||
DestroyServerGroupStage destroyServerGroupStage = new DestroyServerGroupStage(dynamicConfigService) | ||
PipelineExecutionImpl pipelineExecution = new PipelineExecutionImpl(ExecutionType.PIPELINE, 'foo') | ||
def context = [ | ||
credentials : 'test', | ||
cluster: 'foo-main', | ||
moniker : [ | ||
app: 'foo', | ||
cluster: 'foo-main', | ||
stack: 'main'], | ||
regions : ['us-west-2'], | ||
target: 'current_asg_dynamic', | ||
] | ||
StageExecutionImpl parentStage = new StageExecutionImpl(pipelineExecution, "destroyServerGroup", context) | ||
|
||
def "should add disable stage to graph when skipDisableBeforeDestroy is false"() { | ||
given: | ||
def context = [skipDisableBeforeDestroy: false] | ||
def graph = StageGraphBuilderImpl.beforeStages(parentStage) | ||
|
||
when: | ||
destroyServerGroupStage.preStatic(context, graph) | ||
|
||
then: | ||
def stages = graph.build().collect { it } | ||
stages.size() == 1 | ||
def stage = stages.first() | ||
stage.name == "disableServerGroup" | ||
stage.type == StageDefinitionBuilder.getType(DisableServerGroupStage) | ||
stage.context == context | ||
} | ||
|
||
def "should add disable stage in preStatic method"() { | ||
given: | ||
def context = [skipDisableBeforeDestroy: false] | ||
def graph = StageGraphBuilderImpl.beforeStages(parentStage) | ||
|
||
when: | ||
destroyServerGroupStage.preStatic(context, graph) | ||
|
||
then: | ||
def stages = graph.build().collect { it } | ||
stages.size() == 1 | ||
def stage = stages.first() | ||
stage.name == "disableServerGroup" | ||
stage.type == StageDefinitionBuilder.getType(DisableServerGroupStage) | ||
stage.context == context | ||
} | ||
|
||
def "should add disable stage in preDynamic method"() { | ||
given: | ||
def context = [skipDisableBeforeDestroy: false] | ||
def graph = StageGraphBuilderImpl.beforeStages(parentStage) | ||
|
||
when: | ||
destroyServerGroupStage.preDynamic(context, graph) | ||
|
||
then: | ||
def stages = graph.build().collect { it } | ||
stages.size() == 1 | ||
def stage = stages.first() | ||
stage.name == "disableServerGroup" | ||
stage.type == StageDefinitionBuilder.getType(DisableServerGroupStage) | ||
stage.context == context | ||
} | ||
|
||
def "should not add disable stage in preStatic method when skipDisableBeforeDestroy is true"() { | ||
given: | ||
def context = [skipDisableBeforeDestroy: true] | ||
def graph = StageGraphBuilderImpl.beforeStages(parentStage) | ||
|
||
when: | ||
destroyServerGroupStage.preStatic(context, graph) | ||
|
||
then: | ||
graph.build().size() == 0 | ||
} | ||
|
||
def "should not add disable stage in preDynamic method when skipDisableBeforeDestroy is true"() { | ||
given: | ||
def context = [skipDisableBeforeDestroy: true] | ||
def graph = StageGraphBuilderImpl.beforeStages(parentStage) | ||
|
||
when: | ||
destroyServerGroupStage.preDynamic(context, graph) | ||
|
||
then: | ||
graph.build().size() == 0 | ||
} | ||
} |