Context("when retrieving /v2/info is successful", func() { BeforeEach(func() { expectedJson = `{ "app_ssh_endpoint": "ssh.example.com:1234", "app_ssh_host_key_fingerprint": "00:11:22:33:44:55:66:77:88" }` fakeCliConnection.CliCommandWithoutTerminalOutputReturns([]string{expectedJson}, nil) }) It("returns a populated Info model", func() { model, err := infoFactory.Get() Expect(err).NotTo(HaveOccurred()) Expect(fakeCliConnection.CliCommandWithoutTerminalOutputCallCount()).To(Equal(1)) Expect(fakeCliConnection.CliCommandWithoutTerminalOutputArgsForCall(0)).To(ConsistOf("curl", "/v2/info")) Expect(model.SSHEndpoint).To(Equal("ssh.example.com:1234")) Expect(model.SSHEndpointFingerprint).To(Equal("00:11:22:33:44:55:66:77:88")) }) }) Context("when retrieving /v2/info fails", func() { JustBeforeEach(func() { fakeCliConnection.CliCommandWithoutTerminalOutputReturns(nil, errors.New("woops")) }) It("fails with an error", func() { _, err := infoFactory.Get() Expect(err).To(MatchError("Failed to acquire SSH endpoint info"))
Context("when no app name is supplied", func() { It("returns an error message", func() { _, err := appenv.GetEnvs(fakeCliConnection, []string{}) Expect(err).To(MatchError("You must specify an app name")) }) }) Context("when getting vcap_services", func() { appname := "APP_NAME" BeforeEach(func() { fakeCliConnection.CliCommandWithoutTerminalOutputReturns([]string{"hi"}, nil) appenv.GetEnvs(fakeCliConnection, []string{"something", appname}) }) It("calls cli", func() { Expect(fakeCliConnection.CliCommandWithoutTerminalOutputCallCount()). To(Not(BeZero())) }) It("requests the correct app envs", func() { Expect(fakeCliConnection.CliCommandWithoutTerminalOutputArgsForCall(0)). To(Equal([]string{"env", appname})) }) }) Context("parsing json app environment data", func() { It("error handles invalid json", func() { _, err := appenv.GetJson("TEST", []string{ "foo", "TEST: stuff", })
}) It("Extract Application Name From Command Line Args", func() { name, err := callCopyEnvCommandPlugin.ExtractAppName([]string{"copyenv"}) Ω(err).Should(MatchError("missing application name")) name, err = callCopyEnvCommandPlugin.ExtractAppName([]string{"copyenv", "APP_NAME"}) Ω(err).ShouldNot(HaveOccurred()) Ω(name).Should(Equal("APP_NAME")) }) It("Retrieve Application Environment Variables From Name", func() { fakeCliConnection.CliCommandWithoutTerminalOutputReturns([]string{"SOME", "OUTPUT", "COMMAND"}, nil) output, err := callCopyEnvCommandPlugin.RetrieveAppNameEnv(fakeCliConnection, "APP_NAME") Ω(err).ShouldNot(HaveOccurred()) Ω(fakeCliConnection.CliCommandWithoutTerminalOutputCallCount()).Should(Equal(1)) Ω(fakeCliConnection.CliCommandWithoutTerminalOutputArgsForCall(0)).Should(Equal([]string{"env", "APP_NAME"})) Ω(output).Should(Equal([]string{"SOME", "OUTPUT", "COMMAND"})) }) It("Return Service Credentials From Appplication Environment", func() { _, err := callCopyEnvCommandPlugin.ExtractCredentialsJSON("VCAP_SERVICES", []string{""}) Ω(err).Should(MatchError("missing service credentials for application")) service_creds := []string{"{\"VCAP_SERVICES\":{\"service\": [ { \"credentials\": {} } ]}}"} b, err := callCopyEnvCommandPlugin.ExtractCredentialsJSON("VCAP_SERVICES", service_creds) Ω(err).ShouldNot(HaveOccurred()) Ω(string(b[:])).Should(Equal("{\"service\":[{\"credentials\":{}}]}")) }) It("Print Service Credentials As Shell Variable", func() {