github.com/chenbh/concourse/v6@v6.4.2/fly/integration/destroy_team_test.go (about) 1 package integration_test 2 3 import ( 4 "fmt" 5 "io" 6 "os/exec" 7 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 "github.com/onsi/gomega/gbytes" 11 "github.com/onsi/gomega/gexec" 12 "github.com/onsi/gomega/ghttp" 13 ) 14 15 var _ = Describe("Fly CLI", func() { 16 Describe("destroy-team", func() { 17 var ( 18 stdin io.Writer 19 args []string 20 sess *gexec.Session 21 ) 22 23 BeforeEach(func() { 24 stdin = nil 25 args = []string{} 26 }) 27 28 JustBeforeEach(func() { 29 var err error 30 31 flyCmd := exec.Command(flyPath, append([]string{"-t", targetName, "destroy-team"}, args...)...) 32 stdin, err = flyCmd.StdinPipe() 33 Expect(err).NotTo(HaveOccurred()) 34 35 sess, err = gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) 36 Expect(err).NotTo(HaveOccurred()) 37 }) 38 39 Context("when the team name is not specified", func() { 40 It("asks the user for the team name", func() { 41 Eventually(sess).Should(gexec.Exit(1)) 42 Expect(sess.Err).To(gbytes.Say("error: the required flag `" + osFlag("n", "team-name") + "' was not specified")) 43 }) 44 }) 45 46 Context("when the team name is secified", func() { 47 BeforeEach(func() { 48 args = append(args, "-n", "some-team") 49 }) 50 51 typesName := func(name string) { 52 fmt.Fprintf(stdin, "%s\n", name) 53 } 54 55 It("reminds the user this is a destructive operation", func() { 56 Eventually(sess).Should(gbytes.Say("!!! this will remove all data for team `some-team`")) 57 }) 58 59 It("asks the user to type in the team name again", func() { 60 Eventually(sess).Should(gbytes.Say("please type the team name to confirm")) 61 }) 62 63 Context("when the user types in the name again successfully", func() { 64 JustBeforeEach(func() { 65 typesName("some-team") 66 }) 67 68 Context("when the api call returns 204 (successful)", func() { 69 BeforeEach(func() { 70 atcServer.AppendHandlers( 71 ghttp.CombineHandlers( 72 ghttp.VerifyRequest("DELETE", "/api/v1/teams/some-team"), 73 ghttp.RespondWith(204, ""), 74 ), 75 ) 76 }) 77 78 It("tells the user the team has been destroyed", func() { 79 Eventually(sess).Should(gbytes.Say("`some-team` deleted")) 80 }) 81 }) 82 83 Context("when the api call returns 403 Forbidden", func() { 84 BeforeEach(func() { 85 atcServer.AppendHandlers( 86 ghttp.CombineHandlers( 87 ghttp.VerifyRequest("DELETE", "/api/v1/teams/some-team"), 88 ghttp.RespondWith(403, ""), 89 ), 90 ) 91 }) 92 93 It("tells the user that they are not allowed to do this", func() { 94 Eventually(sess).Should(gbytes.Say("could not destroy `some-team`")) 95 Eventually(sess).Should(gbytes.Say(`either your team is not an admin or it is the last admin team`)) 96 }) 97 }) 98 }) 99 100 Context("when the user fails to type in the team name again successfully", func() { 101 JustBeforeEach(func() { 102 typesName("not-the-correct-team-name") 103 }) 104 105 It("asks them to try again", func() { 106 Eventually(sess).Should(gexec.Exit(1)) 107 Expect(sess.Err).To(gbytes.Say(`incorrect team name; bailing out`)) 108 }) 109 }) 110 }) 111 }) 112 })