github.com/sleungcy-sap/cli@v7.1.0+incompatible/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", "APPS", "Lists revisions for 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 - Lists revisions for an app")) 43 Eventually(session).Should(Say("USAGE:")) 44 Eventually(session).Should(Say("cf revisions APP_NAME")) 45 Eventually(session).Should(Exit(0)) 46 }) 47 }) 48 }) 49 50 When("targetting and org and space", func() { 51 BeforeEach(func() { 52 helpers.SetupCF(orgName, spaceName) 53 }) 54 55 AfterEach(func() { 56 helpers.QuickDeleteOrg(orgName) 57 }) 58 59 When("An app name is not provided", func() { 60 It("Returns the incorrect usage text and help information", func() { 61 session := helpers.CF("revisions") 62 Eventually(session).Should(Exit(1)) 63 Expect(session.Err.Contents()).Should(ContainSubstring("Incorrect Usage: the required argument `APP_NAME` was not provided")) 64 Expect(session).Should(Say("revisions - Lists revisions for an app")) 65 }) 66 }) 67 68 When("the provided app does not exist", func() { 69 It("properly displays app not found error", func() { 70 fakeAppName := helpers.PrefixedRandomName("test-fake-app") 71 session := helpers.CF("revisions", fakeAppName) 72 Eventually(session).Should(Exit(1)) 73 Expect(session).Should(Say(regexp.QuoteMeta(`Getting revisions for app %s in org %s / space %s as %s...`), fakeAppName, orgName, spaceName, username)) 74 Expect(session.Err).Should(Say(regexp.QuoteMeta(`App '%s' not found`), fakeAppName)) 75 Expect(session).To(Say("FAILED")) 76 }) 77 }) 78 79 When("an app has been pushed without staging", func() { 80 BeforeEach(func() { 81 helpers.WithHelloWorldApp(func(appDir string) { 82 Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start")).Should(Exit(0)) 83 }) 84 }) 85 86 It("prints a 'not found' message without failing", func() { 87 session := helpers.CF("revisions", appName) 88 Eventually(session).Should(Exit(0)) 89 Expect(session).Should(Say(`No \w+ found`)) 90 }) 91 }) 92 93 When("An app has been pushed several times", func() { 94 BeforeEach(func() { 95 helpers.WithHelloWorldApp(func(appDir string) { 96 Eventually(helpers.CF("push", appName, "-p", appDir)).Should(Exit(0)) 97 Eventually(helpers.CF("push", appName, "-p", appDir)).Should(Exit(0)) 98 }) 99 }) 100 101 It("Retrieves the revisions", func() { 102 session := helpers.CF("revisions", appName) 103 Eventually(session).Should(Exit(0)) 104 Expect(session).Should(Say(regexp.QuoteMeta(`Getting revisions for app %s in org %s / space %s as %s...`), appName, orgName, spaceName, username)) 105 106 Expect(session).Should(Say("New droplet deployed")) 107 Expect(session).Should(Say("Initial revision")) 108 }) 109 110 When("revisions are disabled for the app", func() { 111 112 BeforeEach(func() { 113 session := helpers.CF("app", appName, "--guid") 114 Eventually(session).Should(Exit(0)) 115 116 appGuid := bytes.TrimSpace(session.Out.Contents()) 117 routeToDisableRevisions := fmt.Sprintf(`/v3/apps/%s/features/revisions`, appGuid) 118 session = helpers.CF("curl", routeToDisableRevisions, "-X", "PATCH", "-d", `{ "enabled": false }`) 119 Eventually(session).Should(Exit(0)) 120 }) 121 It("outputs the revisions with a warning", func() { 122 session := helpers.CF("revisions", appName) 123 Eventually(session).Should(Exit(0)) 124 Expect(session).Should(Say(regexp.QuoteMeta(`Getting revisions for app %s in org %s / space %s as %s...`), appName, orgName, spaceName, username)) 125 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))) 126 Expect(session).Should(Say("New droplet deployed")) 127 Expect(session).Should(Say("Initial revision")) 128 }) 129 }) 130 }) 131 }) 132 })