github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+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 When("there too many arguments", func() { 84 It("ignores the extra arguments", func() { 85 session := helpers.CF("stack", stackName, "extra") 86 87 Eventually(session).Should(Say(`Getting stack %s as %s\.\.\.`, stackName, username)) 88 Eventually(session.Err).Should(Say("Stack %s not found", stackName)) 89 Eventually(session).Should(Say("FAILED")) 90 Eventually(session).Should(Exit(1)) 91 }) 92 }) 93 }) 94 95 When("the stack does not exist", func() { 96 It("Fails", func() { 97 session := helpers.CF("stack", stackName) 98 99 Eventually(session).Should(Say(`Getting stack %s as %s\.\.\.`, stackName, username)) 100 Eventually(session.Err).Should(Say("Stack %s not found", stackName)) 101 Eventually(session).Should(Say("FAILED")) 102 Eventually(session).Should(Exit(1)) 103 }) 104 }) 105 106 When("the stack exists", func() { 107 var stackGUID string 108 109 BeforeEach(func() { 110 jsonBody := fmt.Sprintf(`{"name": "%s", "description": "%s"}`, stackName, stackDescription) 111 session := helpers.CF("curl", "-d", jsonBody, "-X", "POST", "/v3/stacks") 112 Eventually(session).Should(Exit(0)) 113 114 r, _ := regexp.Compile(`[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}`) 115 stackGUID = string(r.Find(session.Out.Contents())) 116 }) 117 118 AfterEach(func() { 119 session := helpers.CF("curl", "-X", "DELETE", fmt.Sprintf("/v3/stacks/%s", stackGUID)) 120 Eventually(session).Should(Exit(0)) 121 }) 122 123 It("Shows the details for the stack", func() { 124 session := helpers.CF("stack", stackName) 125 126 Eventually(session).Should(Say(`Getting stack %s as %s\.\.\.`, stackName, username)) 127 Eventually(session).Should(Say(`name:\s+%s`, stackName)) 128 Eventually(session).Should(Say(`description:\s+%s`, stackDescription)) 129 Eventually(session).Should(Exit(0)) 130 }) 131 132 When("the stack exists and the --guid flag is passed", func() { 133 It("prints nothing but the guid", func() { 134 session := helpers.CF("stack", stackName, "--guid") 135 136 Consistently(session).ShouldNot(Say(`Getting stack %s as %s\.\.\.`, stackName, username)) 137 Consistently(session).ShouldNot(Say(`name:\s+%s`, stackName)) 138 Consistently(session).ShouldNot(Say(`description:\s+%s`, stackDescription)) 139 Eventually(session).Should(Say(`^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}`)) 140 Eventually(session).Should(Exit(0)) 141 }) 142 }) 143 }) 144 }) 145 })