github.com/loafoe/cli@v7.1.0+incompatible/integration/v7/isolated/rollback_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "path/filepath" 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("rollback command", func() { 17 var ( 18 appName string 19 orgName string 20 spaceName string 21 userName string 22 ) 23 24 BeforeEach(func() { 25 appName = helpers.PrefixedRandomName("app") 26 orgName = helpers.NewOrgName() 27 spaceName = helpers.NewSpaceName() 28 userName, _ = helpers.GetCredentials() 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("rollback", "EXPERIMENTAL COMMANDS", "Rollback to the specified revision of an app")) 37 }) 38 39 It("Displays rollback command usage to output", func() { 40 session := helpers.CF("rollback", "--help") 41 42 Eventually(session).Should(Exit(0)) 43 44 Expect(session).To(Say("NAME:")) 45 Expect(session).To(Say("rollback - Rollback to the specified revision of an app")) 46 Expect(session).To(Say("USAGE:")) 47 Expect(session).To(Say(`cf rollback APP_NAME \[--revision REVISION_NUMBER\]`)) 48 Expect(session).To(Say("OPTIONS:")) 49 Expect(session).To(Say("-f Force rollback without confirmation")) 50 Expect(session).To(Say("--revision Roll back to the given app revision")) 51 Expect(session).To(Say("SEE ALSO:")) 52 Expect(session).To(Say("revisions")) 53 }) 54 }) 55 }) 56 57 When("the environment is set up correctly", func() { 58 BeforeEach(func() { 59 helpers.SetupCF(orgName, spaceName) 60 }) 61 62 AfterEach(func() { 63 helpers.QuickDeleteOrg(orgName) 64 }) 65 66 Describe("version dependent display", func() { 67 68 var domainName string 69 70 BeforeEach(func() { 71 domainName = helpers.DefaultSharedDomain() 72 }) 73 74 When("the app is started and has 2 instances", func() { 75 BeforeEach(func() { 76 helpers.WithHelloWorldApp(func(appDir string) { 77 manifestContents := []byte(fmt.Sprintf(` 78 --- 79 applications: 80 - name: %s 81 memory: 128M 82 instances: 2 83 disk_quota: 128M 84 routes: 85 - route: %s.%s 86 `, appName, appName, domainName)) 87 manifestPath := filepath.Join(appDir, "manifest.yml") 88 err := ioutil.WriteFile(manifestPath, manifestContents, 0666) 89 Expect(err).ToNot(HaveOccurred()) 90 91 Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack")).Should(Exit(0)) 92 Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack")).Should(Exit(0)) 93 }) 94 }) 95 96 When("the -f flag is provided", func() { 97 It("does not prompt the user, and just rolls back", func() { 98 session := helpers.CF("rollback", appName, "--revision", "1", "-f") 99 Eventually(session).Should(Exit(0)) 100 101 Expect(session).To(Say("Rolling back to revision 1 for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 102 Expect(session).To(Say("OK")) 103 104 Expect(session).ToNot(Say("Are you sure you want to continue?")) 105 106 session = helpers.CF("revisions", appName) 107 Eventually(session).Should(Exit(0)) 108 109 Expect(session).To(Say(`3\s+New droplet deployed.`)) 110 }) 111 }) 112 113 Describe("the -f flag is not provided", func() { 114 var buffer *Buffer 115 116 BeforeEach(func() { 117 buffer = NewBuffer() 118 }) 119 120 When("the user enters y", func() { 121 BeforeEach(func() { 122 _, err := buffer.Write([]byte("y\n")) 123 Expect(err).ToNot(HaveOccurred()) 124 }) 125 126 It("prompts the user to rollback, then successfully rolls back", func() { 127 session := helpers.CFWithStdin(buffer, "rollback", appName, "--revision", "1") 128 Eventually(session).Should(Exit(0)) 129 130 Expect(session).To(Say("Rolling '%s' back to revision '1' will create a new revision. The new revision '3' will use the settings from revision '1'.", appName)) 131 Expect(session).To(Say("Are you sure you want to continue?")) 132 Expect(session).To(Say("Rolling back to revision 1 for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 133 Expect(session).To(Say("OK")) 134 135 session = helpers.CF("revisions", appName) 136 Eventually(session).Should(Exit(0)) 137 138 Expect(session).To(Say(`3\s+New droplet deployed.`)) 139 }) 140 }) 141 142 When("the user enters n", func() { 143 BeforeEach(func() { 144 _, err := buffer.Write([]byte("n\n")) 145 Expect(err).ToNot(HaveOccurred()) 146 }) 147 148 It("prompts the user to rollback, then does not rollback", func() { 149 session := helpers.CFWithStdin(buffer, "rollback", appName, "--revision", "1") 150 Eventually(session).Should(Exit(0)) 151 152 Expect(session).To(Say("Rolling '%s' back to revision '1' will create a new revision. The new revision '3' will use the settings from revision '1'.", appName)) 153 Expect(session).To(Say("Are you sure you want to continue?")) 154 Expect(session).To(Say("App '%s' has not been rolled back to revision '1'", appName)) 155 156 session = helpers.CF("revisions", appName) 157 Eventually(session).Should(Exit(0)) 158 159 Expect(session).ToNot(Say(`3\s+[\w\-]+\s+New droplet deployed.`)) 160 }) 161 }) 162 }) 163 }) 164 }) 165 }) 166 })