Skip to content

Commit

Permalink
chore(orca): removed test usage of PipelineBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
robfletcher committed Aug 29, 2017
1 parent 5555874 commit ceeef10
Show file tree
Hide file tree
Showing 156 changed files with 1,836 additions and 1,554 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
* limitations under the License.
*/


package com.netflix.spinnaker.orca.applications.tasks

import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spinnaker.orca.ExecutionStatus
import com.netflix.spinnaker.orca.front50.Front50Service
import com.netflix.spinnaker.orca.front50.model.Application
import com.netflix.spinnaker.orca.pipeline.model.Pipeline
import com.netflix.spinnaker.orca.pipeline.model.Stage
import spock.lang.Specification
import spock.lang.Subject
import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.pipeline
import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.stage

class DeleteApplicationTaskSpec extends Specification {
@Subject
Expand All @@ -33,9 +32,15 @@ class DeleteApplicationTaskSpec extends Specification {
def config = [
account : "test",
application: [
"name" : "application"
"name": "application"
]
]
def pipeline = pipeline {
stage {
type = "DeleteApplication"
context = config
}
}

void "should delete global application if it was only associated with a single account"() {
given:
Expand All @@ -47,7 +52,7 @@ class DeleteApplicationTaskSpec extends Specification {
}

when:
def taskResult = task.execute(new Stage<>(new Pipeline(), "DeleteApplication", config))
def taskResult = task.execute(pipeline.stages.first())

then:
taskResult.status == ExecutionStatus.SUCCEEDED
Expand All @@ -64,7 +69,7 @@ class DeleteApplicationTaskSpec extends Specification {
}

when:
def taskResult = task.execute(new Stage<>(new Pipeline(), "DeleteApplication", config))
def taskResult = task.execute(pipeline.stages.first())

then:
taskResult.context.previousState == application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,32 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spinnaker.orca.ExecutionStatus
import com.netflix.spinnaker.orca.front50.Front50Service
import com.netflix.spinnaker.orca.front50.model.Application
import com.netflix.spinnaker.orca.pipeline.model.Pipeline
import com.netflix.spinnaker.orca.pipeline.model.Stage
import spock.lang.Specification
import spock.lang.Subject
import spock.lang.Unroll
import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.pipeline
import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.stage

class UpsertApplicationTaskSpec extends Specification {
@Subject
def task = new UpsertApplicationTask(mapper: new ObjectMapper())

def config

void setup() {
config = [
application: [
"name" : "application",
"owner": "owner",
"repoProjectKey" : "project-key",
"repoSlug" : "repo-slug",
"repoType" : "github"
],
user: "testUser"
]
def config = [
application: [
"name" : "application",
"owner" : "owner",
"repoProjectKey": "project-key",
"repoSlug" : "repo-slug",
"repoType" : "github"
],
user : "testUser"
]

def pipeline = pipeline {
stage {
type = "UpsertApplication"
context = config
}
}

void "should create an application in global registries"() {
Expand All @@ -57,7 +60,7 @@ class UpsertApplicationTaskSpec extends Specification {
}

when:
def result = task.execute(new Stage<>(new Pipeline(), "UpsertApplication", config))
def result = task.execute(pipeline.stages.first())

then:
result.status == ExecutionStatus.SUCCEEDED
Expand All @@ -79,7 +82,7 @@ class UpsertApplicationTaskSpec extends Specification {
}

when:
def result = task.execute(new Stage<>(new Pipeline(), "UpsertApplication", config))
def result = task.execute(pipeline.stages.first())

then:
result.status == ExecutionStatus.SUCCEEDED
Expand All @@ -99,7 +102,7 @@ class UpsertApplicationTaskSpec extends Specification {
}

when:
def result = task.execute(new Stage<>(new Pipeline(), "UpsertApplication", config))
def result = task.execute(pipeline.stages.first())

then:
result.context.previousState == (initialState ?: [:])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,26 @@
* limitations under the License.
*/


package com.netflix.spinnaker.orca.applications.tasks

import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spinnaker.orca.ExecutionStatus
import com.netflix.spinnaker.orca.pipeline.model.Pipeline
import com.netflix.spinnaker.orca.pipeline.model.Stage
import com.netflix.spinnaker.orca.pipeline.model.Task
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll
import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.pipeline
import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.stage

class VerifyApplicationHasNoDependenciesTaskSpec extends Specification {
@Shared
def config = [application: ["name": "application"]]
def pipeline = pipeline {
stage {
type = "VerifyApplication"
context = config
}
}

@Unroll
void "should be TERMINAL when application has clusters or security groups"() {
Expand All @@ -49,7 +54,7 @@ class VerifyApplicationHasNoDependenciesTaskSpec extends Specification {
task.objectMapper = new ObjectMapper()

and:
def stage = new Stage<>(new Pipeline(), "VerifyApplication", config)
def stage = pipeline.stages.first()
stage.tasks = [new Task(name: "T1"), new Task(name: "T2")]

when:
Expand All @@ -59,10 +64,10 @@ class VerifyApplicationHasNoDependenciesTaskSpec extends Specification {
taskResult.status == executionStatus

where:
clusters | securityGroups || executionStatus
[] | [] || ExecutionStatus.SUCCEEDED
[['a cluster']] | [] || ExecutionStatus.TERMINAL
[] | [["application": config.application.name]] || ExecutionStatus.TERMINAL
[['a cluster']] | [["application": config.application.name]] || ExecutionStatus.TERMINAL
clusters | securityGroups || executionStatus
[] | [] || ExecutionStatus.SUCCEEDED
[['a cluster']] | [] || ExecutionStatus.TERMINAL
[] | [["application": config.application.name]] || ExecutionStatus.TERMINAL
[['a cluster']] | [["application": config.application.name]] || ExecutionStatus.TERMINAL
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,26 @@
package com.netflix.spinnaker.orca.bakery.pipeline

import com.netflix.spinnaker.orca.ExecutionStatus
import com.netflix.spinnaker.orca.pipeline.model.Pipeline
import com.netflix.spinnaker.orca.pipeline.model.Stage
import groovy.time.TimeCategory
import spock.lang.Specification
import spock.lang.Unroll
import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.pipeline
import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.stage

class BakeStageSpec extends Specification {
@Unroll
def "should build contexts corresponding to locally specified bake region and all target deploy regions"() {
given:
def pipelineBuilder = new Pipeline().builder()
deployAvailabilityZones?.each {
pipelineBuilder = pipelineBuilder.withStage("deploy", "Deploy!", it)
def pipeline = pipeline {
deployAvailabilityZones?.each { zones ->
stage {
type = "deploy"
name = "Deploy!"
context = zones
}
}
}
def pipeline = pipelineBuilder.build()

def bakeStage = new Stage<>(pipeline, "bake", "Bake!", bakeStageContext)
def builder = Spy(BakeStage, {
Expand Down Expand Up @@ -75,21 +80,37 @@ class BakeStageSpec extends Specification {

def "should include per-region stage contexts as global deployment details"() {
given:
def pipeline = Pipeline.builder()
.withStage(BakeStage.PIPELINE_CONFIG_TYPE, "Bake", ["ami": 1])
.withStage(BakeStage.PIPELINE_CONFIG_TYPE, "Bake", ["ami": 2])
.withStage(BakeStage.PIPELINE_CONFIG_TYPE, "Bake", ["ami": 3])
.build()

def pipelineStage = new Stage<>(pipeline, "bake")
pipeline.stages.each {
it.status = ExecutionStatus.RUNNING
it.parentStageId = pipelineStage.parentStageId
it.id = pipelineStage.parentStageId
def pipeline = pipeline {
stage {
id = "1"
type = "bake"
status = ExecutionStatus.RUNNING
}
stage {
parentStageId = "1"
type = "bake"
name = "Bake"
context = ["ami": 1]
status = ExecutionStatus.RUNNING
}
stage {
parentStageId = "1"
type = "bake"
name = "Bake"
context = ["ami": 2]
status = ExecutionStatus.RUNNING
}
stage {
parentStageId = "1"
type = "bake"
name = "Bake"
context = ["ami": 3]
status = ExecutionStatus.RUNNING
}
}

when:
def taskResult = new BakeStage.CompleteParallelBakeTask().execute(pipelineStage)
def taskResult = new BakeStage.CompleteParallelBakeTask().execute(pipeline.stageById("1"))

then:
taskResult.outputs == [
Expand All @@ -102,7 +123,10 @@ class BakeStageSpec extends Specification {
@Unroll
def "should return a different stage name when parallel flows are present"() {
given:
def stage = new Stage<>(new Pipeline(), "type", stageName, [:])
def stage = stage {
type = "type"
name = stageName
}

expect:
new BakeStage().parallelStageName(stage, hasParallelFlows) == expectedStageName
Expand All @@ -113,9 +137,12 @@ class BakeStageSpec extends Specification {
"Default" | true || "Multi-region Bake"
}

private static List<Map> deployAz(String cloudProvider, String prefix, String... regions) {
private
static List<Map> deployAz(String cloudProvider, String prefix, String... regions) {
if (prefix == "clusters") {
return [[clusters: regions.collect { [cloudProvider: cloudProvider, availabilityZones: [(it): []]] }]]
return [[clusters: regions.collect {
[cloudProvider: cloudProvider, availabilityZones: [(it): []]]
}]]
}

return regions.collect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ import rx.Observable
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Subject
import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.pipeline
import static java.net.HttpURLConnection.HTTP_NOT_FOUND

class CompletedBakeTaskSpec extends Specification {

@Subject task = new CompletedBakeTask()

@Shared Pipeline pipeline = new Pipeline()
@Shared Pipeline pipeline = pipeline()

@Shared notFoundError = RetrofitError.httpError(
null,
Expand Down
Loading

0 comments on commit ceeef10

Please sign in to comment.