github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/fly/integration/edit_target_test.go (about) 1 package integration_test 2 3 import ( 4 "os/exec" 5 6 "github.com/pf-qiu/concourse/v6/fly/rc" 7 "github.com/pf-qiu/concourse/v6/fly/ui" 8 "github.com/fatih/color" 9 10 "github.com/onsi/gomega/gbytes" 11 "github.com/onsi/gomega/gexec" 12 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 ) 16 17 var _ = Describe("Fly CLI", func() { 18 Describe("edit target", func() { 19 var ( 20 flyCmd *exec.Cmd 21 ) 22 23 Context("when no configuration is specified", func() { 24 It("should error out", func() { 25 flyCmd = exec.Command(flyPath, "-t", targetName, "edit-target") 26 27 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 28 Expect(err).NotTo(HaveOccurred()) 29 30 <-sess.Exited 31 Expect(sess.ExitCode()).To(Equal(1)) 32 33 Expect(sess.Err).To(gbytes.Say("error: no attributes specified to update")) 34 }) 35 }) 36 37 Describe("valid configuration", func() { 38 BeforeEach(func() { 39 createFlyRc(rc.Targets{ 40 "test1": { 41 API: "https://example.com/test1", 42 TeamName: "main", 43 Token: &rc.TargetToken{Type: "Bearer", Value: validAccessToken(date(2020, 1, 1))}, 44 }, 45 "test2": { 46 API: "https://example.com/test2", 47 TeamName: "main", 48 Token: &rc.TargetToken{Type: "Bearer", Value: validAccessToken(date(2020, 1, 2))}, 49 }, 50 }) 51 52 flyCmd := exec.Command(flyPath, "targets") 53 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 54 Expect(err).NotTo(HaveOccurred()) 55 56 Eventually(sess).Should(gexec.Exit(0)) 57 58 Expect(sess.Out).To(PrintTable(ui.Table{ 59 Headers: ui.TableRow{ 60 {Contents: "name", Color: color.New(color.Bold)}, 61 {Contents: "url", Color: color.New(color.Bold)}, 62 {Contents: "team", Color: color.New(color.Bold)}, 63 {Contents: "expiry", Color: color.New(color.Bold)}, 64 }, 65 Data: []ui.TableRow{ 66 {{Contents: "test1"}, {Contents: "https://example.com/test1"}, {Contents: "main"}, {Contents: "Wed, 01 Jan 2020 00:00:00 UTC"}}, 67 {{Contents: "test2"}, {Contents: "https://example.com/test2"}, {Contents: "main"}, {Contents: "Thu, 02 Jan 2020 00:00:00 UTC"}}, 68 }, 69 })) 70 }) 71 72 Context("when url configuration is specified", func() { 73 It("should update url field of target", func() { 74 flyCmd = exec.Command(flyPath, "-t", "test1", "edit-target", "--concourse-url", "new-url") 75 76 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 77 Expect(err).NotTo(HaveOccurred()) 78 79 <-sess.Exited 80 Expect(sess.ExitCode()).To(Equal(0)) 81 82 Expect(sess.Out).To(gbytes.Say(`Updated target: test1`)) 83 84 flyCmd = exec.Command(flyPath, "targets") 85 sess, err = gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 86 Expect(err).NotTo(HaveOccurred()) 87 88 Eventually(sess).Should(gexec.Exit(0)) 89 Expect(sess.Out).To(PrintTable(ui.Table{ 90 Headers: ui.TableRow{ 91 {Contents: "name", Color: color.New(color.Bold)}, 92 {Contents: "url", Color: color.New(color.Bold)}, 93 {Contents: "team", Color: color.New(color.Bold)}, 94 {Contents: "expiry", Color: color.New(color.Bold)}, 95 }, 96 Data: []ui.TableRow{ 97 {{Contents: "test1"}, {Contents: "new-url"}, {Contents: "main"}, {Contents: "Wed, 01 Jan 2020 00:00:00 UTC"}}, 98 {{Contents: "test2"}, {Contents: "https://example.com/test2"}, {Contents: "main"}, {Contents: "Thu, 02 Jan 2020 00:00:00 UTC"}}, 99 }, 100 })) 101 }) 102 }) 103 104 Context("when team name configuration is specified", func() { 105 It("should update team name of target", func() { 106 flyCmd = exec.Command(flyPath, "-t", "test2", "edit-target", "--team-name", "new-team") 107 108 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 109 Expect(err).NotTo(HaveOccurred()) 110 111 <-sess.Exited 112 Expect(sess.ExitCode()).To(Equal(0)) 113 114 Expect(sess.Out).To(gbytes.Say(`Updated target: test2`)) 115 116 flyCmd = exec.Command(flyPath, "targets") 117 sess, err = gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 118 Expect(err).NotTo(HaveOccurred()) 119 120 Eventually(sess).Should(gexec.Exit(0)) 121 Expect(sess.Out).To(PrintTable(ui.Table{ 122 Headers: ui.TableRow{ 123 {Contents: "name", Color: color.New(color.Bold)}, 124 {Contents: "url", Color: color.New(color.Bold)}, 125 {Contents: "team", Color: color.New(color.Bold)}, 126 {Contents: "expiry", Color: color.New(color.Bold)}, 127 }, 128 Data: []ui.TableRow{ 129 {{Contents: "test1"}, {Contents: "https://example.com/test1"}, {Contents: "main"}, {Contents: "Wed, 01 Jan 2020 00:00:00 UTC"}}, 130 {{Contents: "test2"}, {Contents: "https://example.com/test2"}, {Contents: "new-team"}, {Contents: "Thu, 02 Jan 2020 00:00:00 UTC"}}, 131 }, 132 })) 133 }) 134 }) 135 136 Context("when target name configuration is specified", func() { 137 It("should update the target name", func() { 138 flyCmd = exec.Command(flyPath, "-t", "test2", "edit-target", "--target-name", "new-target") 139 140 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 141 Expect(err).NotTo(HaveOccurred()) 142 143 <-sess.Exited 144 Expect(sess.ExitCode()).To(Equal(0)) 145 146 Expect(sess.Out).To(gbytes.Say(`Updated target: test2`)) 147 148 flyCmd = exec.Command(flyPath, "targets") 149 sess, err = gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 150 Expect(err).NotTo(HaveOccurred()) 151 152 Eventually(sess).Should(gexec.Exit(0)) 153 Expect(sess.Out).To(PrintTable(ui.Table{ 154 Headers: ui.TableRow{ 155 {Contents: "name", Color: color.New(color.Bold)}, 156 {Contents: "url", Color: color.New(color.Bold)}, 157 {Contents: "team", Color: color.New(color.Bold)}, 158 {Contents: "expiry", Color: color.New(color.Bold)}, 159 }, 160 Data: []ui.TableRow{ 161 {{Contents: "new-target"}, {Contents: "https://example.com/test2"}, {Contents: "main"}, {Contents: "Thu, 02 Jan 2020 00:00:00 UTC"}}, 162 {{Contents: "test1"}, {Contents: "https://example.com/test1"}, {Contents: "main"}, {Contents: "Wed, 01 Jan 2020 00:00:00 UTC"}}, 163 }, 164 })) 165 }) 166 }) 167 }) 168 }) 169 170 })