github.com/chenbh/concourse/v6@v6.4.2/fly/integration/logout_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("logout Command", func() { 18 19 BeforeEach(func() { 20 createFlyRc(rc.Targets{ 21 "test1": { 22 API: "https://example.com/test1", 23 TeamName: "main", 24 Token: &rc.TargetToken{Type: "Bearer", Value: validAccessToken(date(2020, 1, 1))}, 25 }, 26 "test2": { 27 API: "https://example.com/test2", 28 TeamName: "main", 29 Token: &rc.TargetToken{Type: "Bearer", Value: validAccessToken(date(2020, 1, 2))}, 30 }, 31 }) 32 33 flyCmd := exec.Command(flyPath, "targets") 34 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 35 Expect(err).NotTo(HaveOccurred()) 36 37 Eventually(sess).Should(gexec.Exit(0)) 38 39 Expect(sess.Out).To(PrintTable(ui.Table{ 40 Headers: ui.TableRow{ 41 {Contents: "name", Color: color.New(color.Bold)}, 42 {Contents: "url", Color: color.New(color.Bold)}, 43 {Contents: "team", Color: color.New(color.Bold)}, 44 {Contents: "expiry", Color: color.New(color.Bold)}, 45 }, 46 Data: []ui.TableRow{ 47 {{Contents: "test1"}, {Contents: "https://example.com/test1"}, {Contents: "main"}, {Contents: "Wed, 01 Jan 2020 00:00:00 UTC"}}, 48 {{Contents: "test2"}, {Contents: "https://example.com/test2"}, {Contents: "main"}, {Contents: "Thu, 02 Jan 2020 00:00:00 UTC"}}, 49 }, 50 })) 51 }) 52 53 Describe("missing parameters", func() { 54 Context("when validating parameters", func() { 55 It("instructs the user to specify --target or --all if both are missing", func() { 56 flyCmd := exec.Command(flyPath, "logout") 57 58 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 59 Expect(err).NotTo(HaveOccurred()) 60 61 <-sess.Exited 62 Expect(sess.ExitCode()).To(Equal(1)) 63 64 Expect(sess.Err).To(gbytes.Say(`must specify either --target or --all`)) 65 }) 66 67 It("instructs the user to specify --target or --all if both are present", func() { 68 flyCmd := exec.Command(flyPath, "logout", "--target", "some-target", "--all") 69 70 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 71 Expect(err).NotTo(HaveOccurred()) 72 73 <-sess.Exited 74 Expect(sess.ExitCode()).To(Equal(1)) 75 76 Expect(sess.Err).To(gbytes.Say(`must specify either --target or --all`)) 77 }) 78 }) 79 }) 80 81 Describe("delete all", func() { 82 It("removes all tokens and all targets remain in flyrc", func() { 83 flyCmd := exec.Command(flyPath, "logout", "--all") 84 85 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 86 Expect(err).NotTo(HaveOccurred()) 87 88 <-sess.Exited 89 Expect(sess.ExitCode()).To(Equal(0)) 90 91 Expect(sess.Out).To(gbytes.Say(`logged out of all targets`)) 92 93 flyCmd = exec.Command(flyPath, "targets") 94 sess, err = gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 95 Expect(err).NotTo(HaveOccurred()) 96 97 Eventually(sess).Should(gexec.Exit(0)) 98 Expect(sess.Out).To(PrintTable(ui.Table{ 99 Headers: ui.TableRow{ 100 {Contents: "name", Color: color.New(color.Bold)}, 101 {Contents: "url", Color: color.New(color.Bold)}, 102 {Contents: "expiry", Color: color.New(color.Bold)}, 103 }, 104 Data: []ui.TableRow{ 105 {{Contents: "test1"}, {Contents: "https://example.com/test1"}, {Contents: "main"}, {Contents: "n/a"}}, 106 {{Contents: "test2"}, {Contents: "https://example.com/test2"}, {Contents: "main"}, {Contents: "n/a"}}, 107 }, 108 })) 109 }) 110 }) 111 112 Describe("delete one", func() { 113 It("removes token of the target and the target should remain in .flyrc", func() { 114 flyCmd := exec.Command(flyPath, "logout", "-t", "test2") 115 116 sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 117 Expect(err).NotTo(HaveOccurred()) 118 119 <-sess.Exited 120 Expect(sess.ExitCode()).To(Equal(0)) 121 122 Expect(sess.Out).To(gbytes.Say(`logged out of target: test2`)) 123 124 flyCmd = exec.Command(flyPath, "targets") 125 sess, err = gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 126 Expect(err).NotTo(HaveOccurred()) 127 128 Eventually(sess).Should(gexec.Exit(0)) 129 Expect(sess.Out).To(PrintTable(ui.Table{ 130 Headers: ui.TableRow{ 131 {Contents: "name", Color: color.New(color.Bold)}, 132 {Contents: "url", Color: color.New(color.Bold)}, 133 {Contents: "expiry", Color: color.New(color.Bold)}, 134 }, 135 Data: []ui.TableRow{ 136 {{Contents: "test1"}, {Contents: "https://example.com/test1"}, {Contents: "main"}, {Contents: "Wed, 01 Jan 2020 00:00:00 UTC"}}, 137 {{Contents: "test2"}, {Contents: "https://example.com/test2"}, {Contents: "main"}, {Contents: "n/a"}}, 138 }, 139 })) 140 }) 141 }) 142 })