Skip to content

Commit

Permalink
fix(web): Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nandak522 committed Jun 3, 2024
1 parent b01bdc1 commit 9c9630b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ List<String> getDependentConfigs(String templateId) {
objectMapper.convertValue(templatedPipeline, V2TemplateConfiguration.class);
source = config.getTemplate().getReference();
} catch (Exception e) {
e.printStackTrace();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@

package com.netflix.spinnaker.front50.controllers

import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spinnaker.front50.exceptions.InvalidEntityException
import static com.netflix.spinnaker.front50.api.model.pipeline.Pipeline.TYPE_TEMPLATED;
import static com.netflix.spinnaker.front50.model.pipeline.TemplateConfiguration.TemplateSource.SPINNAKER_PREFIX;
import com.netflix.spinnaker.front50.api.model.pipeline.Pipeline;
import com.netflix.spinnaker.front50.model.pipeline.V2TemplateConfiguration;
import com.netflix.spinnaker.front50.model.pipeline.PipelineDAO
import com.netflix.spinnaker.front50.model.pipeline.PipelineTemplate
import com.netflix.spinnaker.front50.model.pipeline.PipelineTemplateDAO
Expand All @@ -34,7 +39,9 @@ class V2PipelineTemplateControllerSpec extends Specification {
def controller = new V2PipelineTemplateController(
pipelineDAO: pipelineDAO,
pipelineTemplateDAO: pipelineTemplateDAO,
objectMapper: new ObjectMapper(),
// V2TemplateConfiguration doesn't expect `id` attribute as part of pipeline config.
// Hence has to ignore unknown properties when converting the value.
objectMapper: new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
)

def template1 = [
Expand Down Expand Up @@ -156,6 +163,68 @@ class V2PipelineTemplateControllerSpec extends Specification {
hash1 == hash2
}

def "getDependentConfigs returns empty list when there are no templated pipelines"() {
given:
pipelineDAO.all() >> []

when:
List<String> dependentConfigIds = controller.getDependentConfigs("myPipelineTemplateId")

then:
dependentConfigIds.isEmpty()
}

def "getDependentConfigs returns empty list when templated pipelines have no dependencies"() {
given:
Pipeline normalPipeline = new Pipeline()
Pipeline templatedPipeline = new Pipeline(id: "id-of-my-templated-pipeline", type: TYPE_TEMPLATED)
pipelineDAO.all() >> [normalPipeline, templatedPipeline]

when:
List<String> dependentConfigIds = controller.getDependentConfigs("a-different-pipeline-template-id")

then:
dependentConfigIds.isEmpty()
}

def "getDependentConfigs returns list of dependent pipeline IDs"() {
given:

def normalPipeline = new Pipeline(
id: "normalPipeline",
name: "normalPipeline",
application: "application",
)
def templatedPipeline = new Pipeline(
id: "id-of-my-templated-pipeline",
name: "name-of-my-templated-pipeline",
application: "application",
type: TYPE_TEMPLATED,
schema: "v2",
template: [
reference: SPINNAKER_PREFIX + "myPipelineTemplateId"
]
)
def oneOtherTemplatedPipeline = new Pipeline(
id: "id-of-one-other-templated-pipeline",
name: "name-of-one-other-templated-pipeline",
application: "application",
type: TYPE_TEMPLATED,
schema: "v2",
template: [
reference: SPINNAKER_PREFIX + "oneOtherPipelineTemplateId"
]
)

pipelineDAO.all() >> [normalPipeline, templatedPipeline, oneOtherTemplatedPipeline]

when:
List<String> dependentConfigIds = controller.getDependentConfigs("myPipelineTemplateId")

then:
dependentConfigIds == ["id-of-my-templated-pipeline"]
}

@Unroll
def 'should fail with InvalidEntityException if Id(#id) is not provided or empty'() {
when:
Expand All @@ -168,4 +237,3 @@ class V2PipelineTemplateControllerSpec extends Specification {
id << [null, "", " "]
}
}

0 comments on commit 9c9630b

Please sign in to comment.