github.com/chenbh/concourse/v6@v6.4.2/fly/integration/rename_team_test.go (about)

     1  package integration_test
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"os/exec"
     7  
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  
    11  	"github.com/onsi/gomega/gbytes"
    12  	"github.com/onsi/gomega/gexec"
    13  	"github.com/onsi/gomega/ghttp"
    14  )
    15  
    16  var _ = Describe("RenameTeam", func() {
    17  	var newName string
    18  	BeforeEach(func() {
    19  		expectedURL := "/api/v1/teams/a-team/rename"
    20  		newName = "b-team"
    21  
    22  		atcServer.AppendHandlers(
    23  			ghttp.CombineHandlers(
    24  				ghttp.VerifyRequest("PUT", expectedURL),
    25  				ghttp.VerifyJSON(fmt.Sprintf(`{"name":%q}`, newName)),
    26  				ghttp.RespondWith(http.StatusNoContent, ""),
    27  			),
    28  		)
    29  	})
    30  
    31  	Context("when not specifying a team name", func() {
    32  		It("fails and says you should provide a team name", func() {
    33  			flyCmd := exec.Command(flyPath, "-t", targetName, "rename-team", "-n", "b-team")
    34  
    35  			sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
    36  			Expect(err).NotTo(HaveOccurred())
    37  
    38  			Eventually(sess).Should(gexec.Exit(1))
    39  
    40  			Expect(sess.Err).To(gbytes.Say("error: the required flag `" + osFlag("o", "old-name") + "' was not specified"))
    41  		})
    42  	})
    43  
    44  	Context("when not specifying a new name", func() {
    45  		It("fails and says you should provide a new name for the team", func() {
    46  			flyCmd := exec.Command(flyPath, "-t", targetName, "rename-team", "-o", "a-team")
    47  
    48  			sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
    49  			Expect(err).NotTo(HaveOccurred())
    50  
    51  			Eventually(sess).Should(gexec.Exit(1))
    52  
    53  			Expect(sess.Err).To(gbytes.Say("error: the required flag `" + osFlag("n", "new-name") + "' was not specified"))
    54  		})
    55  	})
    56  
    57  	Context("when all the inputs are provided", func() {
    58  		It("successfully renames the team to the provided name", func() {
    59  			flyCmd := exec.Command(flyPath, "-t", targetName, "rename-team", "-o", "a-team", "-n", newName)
    60  
    61  			sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
    62  			Expect(err).NotTo(HaveOccurred())
    63  
    64  			Eventually(sess).Should(gexec.Exit(0))
    65  			Expect(atcServer.ReceivedRequests()).To(HaveLen(5))
    66  			Expect(sess.Out).To(gbytes.Say(fmt.Sprintf("Team successfully renamed to %s", newName)))
    67  		})
    68  
    69  		Context("when the team is not found", func() {
    70  			BeforeEach(func() {
    71  				atcServer.SetHandler(4, ghttp.RespondWith(http.StatusNotFound, ""))
    72  			})
    73  
    74  			It("returns an error", func() {
    75  				flyCmd := exec.Command(flyPath, "-t", targetName, "rename-team", "-o", "a-team", "-n", newName)
    76  
    77  				sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
    78  				Expect(err).NotTo(HaveOccurred())
    79  
    80  				Eventually(sess).Should(gexec.Exit(1))
    81  				Expect(atcServer.ReceivedRequests()).To(HaveLen(5))
    82  				Expect(sess.Err).To(gbytes.Say("Team 'a-team' not found"))
    83  			})
    84  		})
    85  
    86  		Context("when an error occurs", func() {
    87  			BeforeEach(func() {
    88  				atcServer.SetHandler(3, ghttp.RespondWith(http.StatusTeapot, ""))
    89  			})
    90  
    91  			It("returns an error", func() {
    92  				flyCmd := exec.Command(flyPath, "-t", targetName, "rename-team", "-o", "a-team", "-n", newName)
    93  
    94  				sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
    95  				Expect(err).NotTo(HaveOccurred())
    96  
    97  				Eventually(sess).Should(gexec.Exit(1))
    98  				Expect(atcServer.ReceivedRequests()).To(HaveLen(4))
    99  				Expect(sess.Err).To(gbytes.Say("418 I'm a teapot"))
   100  			})
   101  		})
   102  	})
   103  })