github.com/chenbh/concourse/v6@v6.4.2/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/chenbh/concourse/v6/fly/commands/internal/templatehelpers" 9 "github.com/chenbh/concourse/v6/fly/commands/internal/validatepipelinehelpers" 10 11 "github.com/chenbh/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 24 BeforeEach(func() { 25 var err error 26 27 tmpdir, err = ioutil.TempDir("", "validate-test") 28 Expect(err).NotTo(HaveOccurred()) 29 30 err = ioutil.WriteFile( 31 filepath.Join(tmpdir, "good-pipeline.yml"), 32 []byte(`--- 33 resource_types: 34 - name: foo 35 type: registry-image 36 source: 37 repository: foo/foo 38 - name: bar 39 type: registry-image 40 source: 41 repository: bar/bar 42 jobs: 43 - name: hello-world 44 plan: 45 - task: say-hello 46 config: 47 platform: linux 48 image_resource: 49 type: registry-image 50 source: {repository: ubuntu} 51 run: 52 path: echo 53 args: ["Hello, world!"] 54 `), 55 0644, 56 ) 57 Expect(err).NotTo(HaveOccurred()) 58 59 err = ioutil.WriteFile( 60 filepath.Join(tmpdir, "dupkey-pipeline.yml"), 61 []byte(`--- 62 resource_types: 63 - name: foo 64 type: registry-image 65 source: 66 repository: foo/foo 67 - name: bar 68 type: registry-image 69 source: 70 repository: bar/bar 71 jobs: 72 - name: hello-world 73 plan: 74 - task: say-hello 75 config: 76 platform: linux 77 image_resource: 78 type: registry-image 79 source: {repository: ubuntu} 80 run: 81 path: echo 82 args: ["Hello, world!"] 83 resource_types: 84 - name: baz 85 type: registry-image 86 source: 87 repository: baz/baz 88 `), 89 0644, 90 ) 91 Expect(err).NotTo(HaveOccurred()) 92 93 goodPipeline = templatehelpers.NewYamlTemplateWithParams(atc.PathFlag(filepath.Join(tmpdir, "good-pipeline.yml")), nil, nil, nil) 94 dupkeyPipeline = templatehelpers.NewYamlTemplateWithParams(atc.PathFlag(filepath.Join(tmpdir, "dupkey-pipeline.yml")), nil, nil, nil) 95 }) 96 97 AfterEach(func() { 98 os.RemoveAll(tmpdir) 99 }) 100 101 It("validates a good pipeline", func() { 102 err := validatepipelinehelpers.Validate(goodPipeline, false, false) 103 Expect(err).To(BeNil()) 104 }) 105 It("validates a good pipeline with strict", func() { 106 err := validatepipelinehelpers.Validate(goodPipeline, true, false) 107 Expect(err).To(BeNil()) 108 }) 109 It("validates a good pipeline with output", func() { 110 err := validatepipelinehelpers.Validate(goodPipeline, true, true) 111 Expect(err).To(BeNil()) 112 }) 113 It("do not fail validating a pipeline with repeated resource types (probably should but for compat doesn't)", func() { 114 err := validatepipelinehelpers.Validate(dupkeyPipeline, false, false) 115 Expect(err).To(BeNil()) 116 }) 117 It("fail validating a pipeline with repeated resource types with strict", func() { 118 err := validatepipelinehelpers.Validate(dupkeyPipeline, true, false) 119 Expect(err).ToNot(BeNil()) 120 }) 121 }) 122 })