github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/integration/v7/isolated/revisions_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"regexp"
     7  
     8  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     9  	"code.cloudfoundry.org/cli/integration/helpers"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/gbytes"
    13  	. "github.com/onsi/gomega/gexec"
    14  )
    15  
    16  var _ = Describe("revisions command", func() {
    17  	var (
    18  		orgName   string
    19  		spaceName string
    20  		appName   string
    21  		username  string
    22  	)
    23  
    24  	BeforeEach(func() {
    25  		username, _ = helpers.GetCredentials()
    26  		orgName = helpers.NewOrgName()
    27  		spaceName = helpers.NewSpaceName()
    28  		appName = helpers.PrefixedRandomName("app")
    29  	})
    30  
    31  	Describe("help", func() {
    32  		When("--help flag is set", func() {
    33  			It("appears in cf help -a", func() {
    34  				session := helpers.CF("help", "-a")
    35  				Eventually(session).Should(Exit(0))
    36  				Expect(session).To(HaveCommandInCategoryWithDescription("revisions", "EXPERIMENTAL COMMANDS", "List revisions of an app"))
    37  			})
    38  
    39  			It("Displays command usage to output", func() {
    40  				session := helpers.CF("revisions", "--help")
    41  				Eventually(session).Should(Say("NAME:"))
    42  				Eventually(session).Should(Say("revisions - List revisions of an app"))
    43  				Eventually(session).Should(Say("USAGE:"))
    44  				Eventually(session).Should(Say("cf revisions APP_NAME"))
    45  				Eventually(session).Should(Say("SEE ALSO:"))
    46  				Eventually(session).Should(Say("rollback"))
    47  				Eventually(session).Should(Exit(0))
    48  			})
    49  		})
    50  	})
    51  
    52  	When("targeting and org and space", func() {
    53  		BeforeEach(func() {
    54  			helpers.SetupCF(orgName, spaceName)
    55  		})
    56  
    57  		AfterEach(func() {
    58  			helpers.QuickDeleteOrg(orgName)
    59  		})
    60  
    61  		When("An app name is not provided", func() {
    62  			It("Returns the incorrect usage text and help information", func() {
    63  				session := helpers.CF("revisions")
    64  				Eventually(session).Should(Exit(1))
    65  				Expect(session.Err.Contents()).Should(ContainSubstring("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    66  				Expect(session).Should(Say("revisions - List revisions of an app"))
    67  			})
    68  		})
    69  
    70  		When("the provided app does not exist", func() {
    71  			It("properly displays app not found error", func() {
    72  				fakeAppName := helpers.PrefixedRandomName("test-fake-app")
    73  				session := helpers.CF("revisions", fakeAppName)
    74  				Eventually(session).Should(Exit(1))
    75  				Expect(session).Should(Say(regexp.QuoteMeta(`Getting revisions for app %s in org %s / space %s as %s...`), fakeAppName, orgName, spaceName, username))
    76  				Expect(session.Err).Should(Say(regexp.QuoteMeta(`App '%s' not found`), fakeAppName))
    77  				Expect(session).To(Say("FAILED"))
    78  			})
    79  		})
    80  
    81  		When("an app has been pushed without staging", func() {
    82  			BeforeEach(func() {
    83  				helpers.WithHelloWorldApp(func(appDir string) {
    84  					Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start")).Should(Exit(0))
    85  				})
    86  			})
    87  
    88  			It("prints a 'not found' message without failing", func() {
    89  				session := helpers.CF("revisions", appName)
    90  				Eventually(session).Should(Exit(0))
    91  				Expect(session).Should(Say(`No \w+ found`))
    92  			})
    93  		})
    94  
    95  		When("An app has been pushed several times", func() {
    96  			BeforeEach(func() {
    97  				helpers.WithHelloWorldApp(func(appDir string) {
    98  					Eventually(helpers.CF("push", appName, "-p", appDir)).Should(Exit(0))
    99  					Eventually(helpers.CF("push", appName, "-p", appDir)).Should(Exit(0))
   100  				})
   101  			})
   102  
   103  			It("Retrieves the revisions", func() {
   104  				session := helpers.CF("revisions", appName)
   105  				Eventually(session).Should(Exit(0))
   106  				Expect(session).Should(Say(regexp.QuoteMeta(`Getting revisions for app %s in org %s / space %s as %s...`), appName, orgName, spaceName, username))
   107  
   108  				Expect(session).Should(Say(`2\(deployed\)\s+New droplet deployed.\s+true`))
   109  				Expect(session).Should(Say(`1\s+Initial revision.\s+true`))
   110  			})
   111  
   112  			When("revisions are disabled for the app", func() {
   113  
   114  				BeforeEach(func() {
   115  					session := helpers.CF("app", appName, "--guid")
   116  					Eventually(session).Should(Exit(0))
   117  
   118  					appGuid := bytes.TrimSpace(session.Out.Contents())
   119  					routeToDisableRevisions := fmt.Sprintf(`/v3/apps/%s/features/revisions`, appGuid)
   120  					session = helpers.CF("curl", routeToDisableRevisions, "-X", "PATCH", "-d", `{ "enabled": false }`)
   121  					Eventually(session).Should(Exit(0))
   122  				})
   123  				It("outputs the revisions with a warning", func() {
   124  					session := helpers.CF("revisions", appName)
   125  					Eventually(session).Should(Exit(0))
   126  					Expect(session).Should(Say(regexp.QuoteMeta(`Getting revisions for app %s in org %s / space %s as %s...`), appName, orgName, spaceName, username))
   127  					Expect(session.Err.Contents()).To(ContainSubstring(fmt.Sprintf("Warning: Revisions for app '%s' are disabled. Updates to the app will not create new revisions.", appName)))
   128  					Expect(session).Should(Say("New droplet deployed"))
   129  					Expect(session).Should(Say("Initial revision"))
   130  				})
   131  			})
   132  		})
   133  	})
   134  })