github.com/chenbh/concourse/v6@v6.4.2/fly/integration/delete_target_test.go (about) 1 package integration_test 2 3 import ( 4 "os/exec" 5 6 "github.com/chenbh/concourse/v6/fly/rc" 7 "github.com/chenbh/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("delete target", func() { 19 Describe("valid configuration", func() { 20 BeforeEach(func() { 21 createFlyRc(rc.Targets{ 22 "test1": { 23 API: "https://example.com/test1", 24 TeamName: "main", 25 Token: &rc.TargetToken{Type: "Bearer", Value: validAccessToken(date(2020, 1, 1))}, 26 }, 27 "test2": { 28 API: "https://example.com/test2", 29 TeamName: "main", 30 Token: &rc.TargetToken{Type: "Bearer", Value: validAccessToken(date(2020, 1, 2))}, 31 }, 32 }) 33 34 flyCmd := exec.Command(flyPath, "targets") 35 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 36 Expect(err).NotTo(HaveOccurred()) 37 38 Eventually(sess).Should(gexec.Exit(0)) 39 40 Expect(sess.Out).To(PrintTable(ui.Table{ 41 Headers: ui.TableRow{ 42 {Contents: "name", Color: color.New(color.Bold)}, 43 {Contents: "url", Color: color.New(color.Bold)}, 44 {Contents: "team", Color: color.New(color.Bold)}, 45 {Contents: "expiry", Color: color.New(color.Bold)}, 46 }, 47 Data: []ui.TableRow{ 48 {{Contents: "test1"}, {Contents: "https://example.com/test1"}, {Contents: "main"}, {Contents: "Wed, 01 Jan 2020 00:00:00 UTC"}}, 49 {{Contents: "test2"}, {Contents: "https://example.com/test2"}, {Contents: "main"}, {Contents: "Thu, 02 Jan 2020 00:00:00 UTC"}}, 50 }, 51 })) 52 }) 53 54 Context("when fly target is specified", func() { 55 It("should delete target", func() { 56 flyCmd := exec.Command(flyPath, "-t", "test1", "delete-target") 57 58 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 59 Expect(err).NotTo(HaveOccurred()) 60 61 <-sess.Exited 62 Expect(sess.ExitCode()).To(Equal(0)) 63 64 Expect(sess.Out).To(gbytes.Say(`deleted target: test1`)) 65 66 flyCmd = exec.Command(flyPath, "targets") 67 sess, err = gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 68 Expect(err).NotTo(HaveOccurred()) 69 70 Eventually(sess).Should(gexec.Exit(0)) 71 Expect(sess.Out).To(PrintTable(ui.Table{ 72 Headers: ui.TableRow{ 73 {Contents: "name", Color: color.New(color.Bold)}, 74 {Contents: "url", Color: color.New(color.Bold)}, 75 {Contents: "team", Color: color.New(color.Bold)}, 76 {Contents: "expiry", Color: color.New(color.Bold)}, 77 }, 78 Data: []ui.TableRow{ 79 {{Contents: "test2"}, {Contents: "https://example.com/test2"}, {Contents: "main"}, {Contents: "Thu, 02 Jan 2020 00:00:00 UTC"}}, 80 }, 81 })) 82 }) 83 }) 84 85 Context("when configuration all", func() { 86 It("should delete all targets", func() { 87 flyCmd := exec.Command(flyPath, "-t", "test1", "delete-target", "--all") 88 89 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 90 Expect(err).NotTo(HaveOccurred()) 91 92 <-sess.Exited 93 Expect(sess.ExitCode()).To(Equal(0)) 94 95 Expect(sess.Out).To(gbytes.Say(`deleted all targets`)) 96 97 flyCmd = exec.Command(flyPath, "targets") 98 sess, err = gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 99 Expect(err).NotTo(HaveOccurred()) 100 101 Eventually(sess).Should(gexec.Exit(0)) 102 Expect(sess.Out).To(PrintTable(ui.Table{ 103 Headers: ui.TableRow{ 104 {Contents: "name", Color: color.New(color.Bold)}, 105 {Contents: "url", Color: color.New(color.Bold)}, 106 {Contents: "team", Color: color.New(color.Bold)}, 107 {Contents: "expiry", Color: color.New(color.Bold)}, 108 }, 109 Data: []ui.TableRow{}, 110 })) 111 }) 112 }) 113 }) 114 }) 115 })