github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/integration/v7/isolated/service_key_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub" 5 . "github.com/onsi/gomega/gexec" 6 7 . "github.com/onsi/gomega/gbytes" 8 9 "code.cloudfoundry.org/cli/integration/helpers" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 ) 13 14 var _ = Describe("service-key command", func() { 15 const command = "service-key" 16 17 Describe("help", func() { 18 matchHelpMessage := SatisfyAll( 19 Say(`NAME:\n`), 20 Say(`\s+service-key - Show service key info\n`), 21 Say(`\n`), 22 Say(`USAGE:\n`), 23 Say(`\s+cf service-key SERVICE_INSTANCE SERVICE_KEY\n`), 24 Say(`\n`), 25 Say(`EXAMPLES:\n`), 26 Say(`\s+cf service-key mydb mykey\n`), 27 Say(`\n`), 28 Say(`OPTIONS:\n`), 29 Say(`\s+--guid\s+Retrieve and display the given service-key's guid. All other output is suppressed\.\n`), 30 ) 31 32 When("the -h flag is specified", func() { 33 It("succeeds and prints help", func() { 34 session := helpers.CF(command, "-h") 35 Eventually(session).Should(Exit(0)) 36 Expect(session.Out).To(matchHelpMessage) 37 }) 38 }) 39 40 When("the --help flag is specified", func() { 41 It("succeeds and prints help", func() { 42 session := helpers.CF(command, "--help") 43 Eventually(session).Should(Exit(0)) 44 Expect(session.Out).To(matchHelpMessage) 45 }) 46 }) 47 48 When("no arguments are provided", func() { 49 It("displays a warning, the help text, and exits 1", func() { 50 session := helpers.CF(command) 51 Eventually(session).Should(Exit(1)) 52 Expect(session.Err).To(Say("Incorrect Usage: the required arguments `SERVICE_INSTANCE` and `SERVICE_KEY` were not provided")) 53 Expect(session.Out).To(matchHelpMessage) 54 }) 55 }) 56 57 When("unknown flag is passed", func() { 58 It("displays a warning, the help text, and exits 1", func() { 59 session := helpers.CF(command, "-u") 60 Eventually(session).Should(Exit(1)) 61 Expect(session.Err).To(Say("Incorrect Usage: unknown flag `u")) 62 Expect(session.Out).To(matchHelpMessage) 63 }) 64 }) 65 }) 66 67 When("the environment is not setup correctly", func() { 68 It("fails with the appropriate errors", func() { 69 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, command, "foo", "bar") 70 }) 71 }) 72 73 When("targeting a space", func() { 74 var ( 75 org string 76 space string 77 username string 78 ) 79 80 BeforeEach(func() { 81 org = helpers.NewOrgName() 82 space = helpers.NewSpaceName() 83 helpers.SetupCF(org, space) 84 85 username, _ = helpers.GetCredentials() 86 }) 87 88 AfterEach(func() { 89 helpers.QuickDeleteOrg(org) 90 }) 91 92 When("service instance does not exit", func() { 93 It("reports a helpful error", func() { 94 session := helpers.CF(command, "no-such-instance", "no-such-key") 95 Eventually(session).Should(Exit(1)) 96 97 Expect(session.Out).To(SatisfyAll( 98 Say(`Getting key no-such-key for service instance no-such-instance as %s\.\.\.\n`, username), 99 Say(`FAILED\n`), 100 )) 101 102 Expect(session.Err).To(Say(`Service instance 'no-such-instance' not found`)) 103 }) 104 }) 105 106 When("service instance exists", func() { 107 var ( 108 broker *servicebrokerstub.ServiceBrokerStub 109 serviceInstance string 110 ) 111 112 BeforeEach(func() { 113 broker = servicebrokerstub.EnableServiceAccess() 114 serviceInstance = helpers.NewServiceInstanceName() 115 helpers.CreateManagedServiceInstance(broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), serviceInstance) 116 }) 117 118 AfterEach(func() { 119 broker.Forget() 120 }) 121 122 When("key does not exist", func() { 123 It("reports a helpful error", func() { 124 session := helpers.CF(command, serviceInstance, "no-such-key") 125 Eventually(session).Should(Exit(1)) 126 127 Expect(session.Out).To(SatisfyAll( 128 Say(`Getting key no-such-key for service instance %s as %s\.\.\.\n`, serviceInstance, username), 129 Say(`FAILED\n`), 130 )) 131 132 Expect(session.Err).To(Say(`No service key no-such-key found for service instance %s`, serviceInstance)) 133 }) 134 }) 135 136 When("keys exists", func() { 137 var keyName string 138 139 BeforeEach(func() { 140 keyName = helpers.PrefixedRandomName("key") 141 Eventually(helpers.CF("create-service-key", serviceInstance, keyName, "-c", `{"foo":"bar"}`)).Should(Exit(0)) 142 }) 143 144 It("prints the details", func() { 145 session := helpers.CF(command, serviceInstance, keyName) 146 Eventually(session).Should(Exit(0)) 147 148 Expect(session.Out).To(SatisfyAll( 149 Say(`Getting key %s for service instance %s as %s\.\.\.\n`, keyName, serviceInstance, username), 150 Say(`\n`), 151 Say(`\{\n`), 152 Say(` "password": "%s",\n`, broker.Password), 153 Say(` "username": "%s"\n`, broker.Username), 154 Say(`\}\n`), 155 )) 156 157 Expect(string(session.Err.Contents())).To(BeEmpty()) 158 }) 159 160 When("the --guid option is given", func() { 161 It("prints just the GUID", func() { 162 session := helpers.CF(command, serviceInstance, keyName, "--guid") 163 Eventually(session).Should(Exit(0)) 164 165 Expect(string(session.Err.Contents())).To(BeEmpty()) 166 Eventually(session).Should(Say(`[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\n`)) 167 }) 168 }) 169 }) 170 }) 171 }) 172 })