github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+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/integration/helpers" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gbytes" 11 . "github.com/onsi/gomega/gexec" 12 ) 13 14 var _ = Describe("stack command", func() { 15 var ( 16 orgName string 17 spaceName string 18 stackName string 19 stackDescription string 20 ) 21 22 BeforeEach(func() { 23 orgName = helpers.NewOrgName() 24 spaceName = helpers.NewSpaceName() 25 stackName = helpers.PrefixedRandomName("stack") 26 stackDescription = "this is a test stack" 27 }) 28 29 Describe("help", func() { 30 When("--help flag is set", func() { 31 It("Displays command usage to output", func() { 32 session := helpers.CF("stack", "--help") 33 34 Eventually(session).Should(Say(`NAME:`)) 35 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\)`)) 36 Eventually(session).Should(Say("USAGE:")) 37 Eventually(session).Should(Say("cf stack STACK_NAME")) 38 39 Eventually(session).Should(Exit(0)) 40 }) 41 }) 42 }) 43 44 When("the stack name is not provided", func() { 45 It("tells the user that the stack name is required, prints help text, and exits 1", func() { 46 session := helpers.CF("stack") 47 48 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `STACK_NAME` was not provided")) 49 Eventually(session).Should(Say("NAME:")) 50 Eventually(session).Should(Exit(1)) 51 }) 52 }) 53 54 When("the environment is not setup correctly", func() { 55 It("fails with the appropriate errors", func() { 56 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "stack", stackName) 57 }) 58 }) 59 60 When("the environment is set up correctly", func() { 61 var username string 62 63 BeforeEach(func() { 64 helpers.SetupCF(orgName, spaceName) 65 username, _ = helpers.GetCredentials() 66 }) 67 68 AfterEach(func() { 69 helpers.QuickDeleteOrg(orgName) 70 }) 71 72 When("the input is invalid", func() { 73 When("there are not enough arguments", func() { 74 It("outputs the usage and exits 1", func() { 75 session := helpers.CF("stack") 76 77 Eventually(session.Err).Should(Say("Incorrect Usage:")) 78 Eventually(session).Should(Say("NAME:")) 79 Eventually(session).Should(Exit(1)) 80 }) 81 }) 82 }) 83 84 When("the stack does not exist", func() { 85 It("Fails", func() { 86 session := helpers.CF("stack", stackName) 87 88 Eventually(session).Should(Say(`Getting info for stack %s as %s\.\.\.`, stackName, username)) 89 Eventually(session.Err).Should(Say("Stack '%s' not found", stackName)) 90 Eventually(session).Should(Say("FAILED")) 91 Eventually(session).Should(Exit(1)) 92 }) 93 }) 94 95 When("the stack exists", func() { 96 var stackGUID string 97 98 BeforeEach(func() { 99 jsonBody := fmt.Sprintf(`{"name": "%s", "description": "%s"}`, stackName, stackDescription) 100 session := helpers.CF("curl", "-d", jsonBody, "-X", "POST", "/v3/stacks") 101 Eventually(session).Should(Exit(0)) 102 103 r, _ := regexp.Compile(`[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}`) 104 stackGUID = string(r.Find(session.Out.Contents())) 105 }) 106 107 AfterEach(func() { 108 session := helpers.CF("curl", "-X", "DELETE", fmt.Sprintf("/v3/stacks/%s", stackGUID)) 109 Eventually(session).Should(Exit(0)) 110 }) 111 112 It("Shows the details for the stack", func() { 113 session := helpers.CF("stack", stackName) 114 115 Eventually(session).Should(Say(`Getting info for stack %s as %s\.\.\.`, stackName, username)) 116 Eventually(session).Should(Say(`name:\s+%s`, stackName)) 117 Eventually(session).Should(Say(`description:\s+%s`, stackDescription)) 118 Eventually(session).Should(Exit(0)) 119 }) 120 121 When("the stack exists and the --guid flag is passed", func() { 122 It("prints nothing but the guid", func() { 123 session := helpers.CF("stack", stackName, "--guid") 124 125 Consistently(session).ShouldNot(Say(`Getting info for stack %s as %s\.\.\.`, stackName, username)) 126 Consistently(session).ShouldNot(Say(`name:\s+%s`, stackName)) 127 Consistently(session).ShouldNot(Say(`description:\s+%s`, stackDescription)) 128 Eventually(session).Should(Say(`^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}`)) 129 Eventually(session).Should(Exit(0)) 130 }) 131 }) 132 }) 133 }) 134 })