github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/fly/commands/internal/flaghelpers/job_flag_test.go (about) 1 package flaghelpers_test 2 3 import ( 4 "github.com/pf-qiu/concourse/v6/atc" 5 . "github.com/pf-qiu/concourse/v6/fly/commands/internal/flaghelpers" 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 ) 9 10 var _ = Describe("JobFlag", func() { 11 var ( 12 flag *JobFlag 13 ) 14 15 BeforeEach(func() { 16 flag = &JobFlag{} 17 }) 18 19 Describe("UnmarshalFlag", func() { 20 for _, tt := range []struct { 21 desc string 22 flag string 23 pipelineRef atc.PipelineRef 24 jobName string 25 err string 26 }{ 27 { 28 desc: "basic", 29 flag: "some-pipeline/some-job", 30 pipelineRef: atc.PipelineRef{Name: "some-pipeline"}, 31 jobName: "some-job", 32 }, 33 { 34 desc: "instance vars", 35 flag: "some-pipeline/branch:master,foo.bar:baz/some-job", 36 pipelineRef: atc.PipelineRef{ 37 Name: "some-pipeline", 38 InstanceVars: atc.InstanceVars{"branch": "master", "foo": map[string]interface{}{"bar": "baz"}}, 39 }, 40 jobName: "some-job", 41 }, 42 { 43 desc: "instance var with a '/'", 44 flag: "some-pipeline/branch:feature/do_things,foo:bar/some-job", 45 pipelineRef: atc.PipelineRef{ 46 Name: "some-pipeline", 47 InstanceVars: atc.InstanceVars{"branch": "feature/do_things", "foo": "bar"}, 48 }, 49 jobName: "some-job", 50 }, 51 { 52 desc: "instance var with special chars", 53 flag: `some-pipeline/foo."bar.baz":'abc,def:ghi'/some-job`, 54 pipelineRef: atc.PipelineRef{ 55 Name: "some-pipeline", 56 InstanceVars: atc.InstanceVars{ 57 "foo": map[string]interface{}{ 58 "bar.baz": "abc,def:ghi", 59 }, 60 }, 61 }, 62 jobName: "some-job", 63 }, 64 { 65 desc: "only pipeline specified", 66 flag: "some-pipeline", 67 err: "argument format should be <pipeline>/<job>", 68 }, 69 { 70 desc: "job name not specified", 71 flag: "some-pipeline/", 72 err: "argument format should be <pipeline>/<job>", 73 }, 74 { 75 desc: "malformed instance var", 76 flag: "some-pipeline/branch=master/some-job", 77 err: "argument format should be <pipeline>/<key:value>/<job>", 78 }, 79 } { 80 tt := tt 81 It(tt.desc, func() { 82 err := flag.UnmarshalFlag(tt.flag) 83 if tt.err == "" { 84 Expect(err).ToNot(HaveOccurred()) 85 Expect(flag.PipelineRef).To(Equal(tt.pipelineRef)) 86 Expect(flag.JobName).To(Equal(tt.jobName)) 87 } else { 88 Expect(err).To(MatchError(tt.err)) 89 } 90 }) 91 } 92 }) 93 })