github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/fly/commands/internal/validatepipelinehelpers/validate_test.go (about) 1 package validatepipelinehelpers_test 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 8 "github.com/pf-qiu/concourse/v6/fly/commands/internal/templatehelpers" 9 "github.com/pf-qiu/concourse/v6/fly/commands/internal/validatepipelinehelpers" 10 11 "github.com/pf-qiu/concourse/v6/atc" 12 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 ) 16 17 var _ = Describe("Validate Pipeline", func() { 18 19 Describe("validating", func() { 20 var tmpdir string 21 var goodPipeline templatehelpers.YamlTemplateWithParams 22 var dupkeyPipeline templatehelpers.YamlTemplateWithParams 23 var goodAcrossPipeline templatehelpers.YamlTemplateWithParams 24 25 BeforeEach(func() { 26 var err error 27 28 tmpdir, err = ioutil.TempDir("", "validate-test") 29 Expect(err).NotTo(HaveOccurred()) 30 31 err = ioutil.WriteFile( 32 filepath.Join(tmpdir, "good-pipeline.yml"), 33 []byte(`--- 34 resource_types: 35 - name: foo 36 type: registry-image 37 source: 38 repository: foo/foo 39 - name: bar 40 type: registry-image 41 source: 42 repository: bar/bar 43 jobs: 44 - name: hello-world 45 plan: 46 - task: say-hello 47 config: 48 platform: linux 49 image_resource: 50 type: registry-image 51 source: {repository: ubuntu} 52 run: 53 path: echo 54 args: ["Hello, world!"] 55 `), 56 0644, 57 ) 58 Expect(err).NotTo(HaveOccurred()) 59 60 err = ioutil.WriteFile( 61 filepath.Join(tmpdir, "dupkey-pipeline.yml"), 62 []byte(`--- 63 resource_types: 64 - name: foo 65 type: registry-image 66 source: 67 repository: foo/foo 68 - name: bar 69 type: registry-image 70 source: 71 repository: bar/bar 72 jobs: 73 - name: hello-world 74 plan: 75 - task: say-hello 76 config: 77 platform: linux 78 image_resource: 79 type: registry-image 80 source: {repository: ubuntu} 81 run: 82 path: echo 83 args: ["Hello, world!"] 84 resource_types: 85 - name: baz 86 type: registry-image 87 source: 88 repository: baz/baz 89 `), 90 0644, 91 ) 92 Expect(err).NotTo(HaveOccurred()) 93 94 err = ioutil.WriteFile( 95 filepath.Join(tmpdir, "good-across-pipeline.yml"), 96 []byte(`--- 97 resource_types: 98 - name: foo 99 type: registry-image 100 source: 101 repository: foo/foo 102 - name: bar 103 type: registry-image 104 source: 105 repository: bar/bar 106 jobs: 107 - name: hello-world 108 plan: 109 - task: say-hello 110 across: 111 - var: foo_version 112 values: ["2.4", "2.5"] 113 config: 114 platform: linux 115 image_resource: 116 type: registry-image 117 source: {repository: ubuntu, tag: "foo-((foo))"} 118 run: 119 path: echo 120 args: ["Hello, world!"] 121 `), 122 0644, 123 ) 124 Expect(err).NotTo(HaveOccurred()) 125 126 goodPipeline = templatehelpers.NewYamlTemplateWithParams(atc.PathFlag(filepath.Join(tmpdir, "good-pipeline.yml")), nil, nil, nil, nil) 127 dupkeyPipeline = templatehelpers.NewYamlTemplateWithParams(atc.PathFlag(filepath.Join(tmpdir, "dupkey-pipeline.yml")), nil, nil, nil, nil) 128 goodAcrossPipeline = templatehelpers.NewYamlTemplateWithParams(atc.PathFlag(filepath.Join(tmpdir, "good-across-pipeline.yml")), nil, nil, nil, nil) 129 }) 130 131 AfterEach(func() { 132 os.RemoveAll(tmpdir) 133 }) 134 135 It("validates a good pipeline", func() { 136 err := validatepipelinehelpers.Validate(goodPipeline, false, false, false) 137 Expect(err).To(BeNil()) 138 }) 139 It("validates a good pipeline with strict", func() { 140 err := validatepipelinehelpers.Validate(goodPipeline, true, false, false) 141 Expect(err).To(BeNil()) 142 }) 143 It("validates a good pipeline with output", func() { 144 err := validatepipelinehelpers.Validate(goodPipeline, true, true, false) 145 Expect(err).To(BeNil()) 146 }) 147 It("do not fail validating a pipeline with repeated resource types (probably should but for compat doesn't)", func() { 148 err := validatepipelinehelpers.Validate(dupkeyPipeline, false, false, false) 149 Expect(err).To(BeNil()) 150 }) 151 It("fail validating a pipeline with repeated resource types with strict", func() { 152 err := validatepipelinehelpers.Validate(dupkeyPipeline, true, false, false) 153 Expect(err).ToNot(BeNil()) 154 }) 155 It("fail validating a pipeline using experimental `across` without the command flag enabling it", func() { 156 err := validatepipelinehelpers.Validate(goodAcrossPipeline, false, false, false) 157 Expect(err).ToNot(BeNil()) 158 }) 159 It("validates a pipeline using experimental `across` when the command flag enabling it is present", func() { 160 err := validatepipelinehelpers.Validate(goodAcrossPipeline, false, false, true) 161 Expect(err).To(BeNil()) 162 }) 163 }) 164 })