github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/stack_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 "regexp" 6 7 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 8 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("stack command", func() { 17 var ( 18 orgName string 19 spaceName string 20 stackName string 21 stackDescription string 22 ) 23 24 BeforeEach(func() { 25 orgName = helpers.NewOrgName() 26 spaceName = helpers.NewSpaceName() 27 stackName = helpers.PrefixedRandomName("stack") 28 stackDescription = "this is a test stack" 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("stack", "APPS", "Show information for a stack (a stack is a pre-built file system, including an operating system, that can run apps)")) 37 }) 38 39 It("Displays command usage to output", func() { 40 session := helpers.CF("stack", "--help") 41 42 Eventually(session).Should(Say(`NAME:`)) 43 Eventually(session).Should(Say(`stack - Show information for a stack \(a stack is a pre-built file system, including an operating system, that can run apps\)`)) 44 Eventually(session).Should(Say("USAGE:")) 45 Eventually(session).Should(Say("cf stack STACK_NAME")) 46 47 Eventually(session).Should(Exit(0)) 48 }) 49 }) 50 }) 51 52 When("the stack name is not provided", func() { 53 It("tells the user that the stack name is required, prints help text, and exits 1", func() { 54 session := helpers.CF("stack") 55 56 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `STACK_NAME` was not provided")) 57 Eventually(session).Should(Say("NAME:")) 58 Eventually(session).Should(Exit(1)) 59 }) 60 }) 61 62 When("the environment is not setup correctly", func() { 63 It("fails with the appropriate errors", func() { 64 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "stack", stackName) 65 }) 66 }) 67 68 When("the environment is set up correctly", func() { 69 var username string 70 71 BeforeEach(func() { 72 helpers.SetupCF(orgName, spaceName) 73 username, _ = helpers.GetCredentials() 74 }) 75 76 AfterEach(func() { 77 helpers.QuickDeleteOrg(orgName) 78 }) 79 80 When("the input is invalid", func() { 81 When("there are not enough arguments", func() { 82 It("outputs the usage and exits 1", func() { 83 session := helpers.CF("stack") 84 85 Eventually(session.Err).Should(Say("Incorrect Usage:")) 86 Eventually(session).Should(Say("NAME:")) 87 Eventually(session).Should(Exit(1)) 88 }) 89 }) 90 }) 91 92 When("the stack does not exist", func() { 93 It("Fails", func() { 94 session := helpers.CF("stack", stackName) 95 96 Eventually(session).Should(Say(`Getting info for stack %s as %s\.\.\.`, stackName, username)) 97 Eventually(session.Err).Should(Say("Stack '%s' not found", stackName)) 98 Eventually(session).Should(Say("FAILED")) 99 Eventually(session).Should(Exit(1)) 100 }) 101 }) 102 103 When("the stack exists", func() { 104 var stackGUID string 105 106 BeforeEach(func() { 107 jsonBody := fmt.Sprintf(`{"name": "%s", "description": "%s"}`, stackName, stackDescription) 108 session := helpers.CF("curl", "-d", jsonBody, "-X", "POST", "/v3/stacks") 109 Eventually(session).Should(Exit(0)) 110 111 r := regexp.MustCompile(`[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}`) 112 stackGUID = string(r.Find(session.Out.Contents())) 113 }) 114 115 AfterEach(func() { 116 session := helpers.CF("curl", "-X", "DELETE", fmt.Sprintf("/v3/stacks/%s", stackGUID)) 117 Eventually(session).Should(Exit(0)) 118 }) 119 120 It("Shows the details for the stack", func() { 121 session := helpers.CF("stack", stackName) 122 123 Eventually(session).Should(Say(`Getting info for stack %s as %s\.\.\.`, stackName, username)) 124 Eventually(session).Should(Say(`name:\s+%s`, stackName)) 125 Eventually(session).Should(Say(`description:\s+%s`, stackDescription)) 126 Eventually(session).Should(Exit(0)) 127 }) 128 129 When("the stack exists and the --guid flag is passed", func() { 130 It("prints nothing but the guid", func() { 131 session := helpers.CF("stack", stackName, "--guid") 132 133 Consistently(session).ShouldNot(Say(`Getting info for stack %s as %s\.\.\.`, stackName, username)) 134 Consistently(session).ShouldNot(Say(`name:\s+%s`, stackName)) 135 Consistently(session).ShouldNot(Say(`description:\s+%s`, stackDescription)) 136 Eventually(session).Should(Say(`^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}`)) 137 Eventually(session).Should(Exit(0)) 138 }) 139 }) 140 }) 141 }) 142 })