Describe("Passing requirements", func() { BeforeEach(func() { requirementsFactory.LoginSuccess = true requirementsFactory.TargetedSpaceSuccess = true }) Context("refreshing the auth token", func() { It("makes a call for the app token", func() { runCommand("source-app", "target-app") Expect(authRepo.RefreshTokenCalled).To(BeTrue()) }) Context("when refreshing the auth token fails", func() { BeforeEach(func() { authRepo.RefreshTokenError = errors.New("I accidentally the UAA") }) It("it displays an error", func() { runCommand("source-app", "target-app") Expect(ui.Outputs).To(ContainSubstrings( []string{"FAILED"}, []string{"accidentally the UAA"}, )) }) }) Describe("when retrieving the app token succeeds", func() { var ( sourceApp, targetApp models.Application )
actor.FilterBrokersReturns([]models.ServiceBroker{ serviceBroker1, serviceBroker2, }, nil, ) }) It("refreshes the auth token", func() { runCommand("service") Expect(tokenRefresher.RefreshTokenCalled).To(BeTrue()) }) Context("when refreshing the auth token fails", func() { It("fails and returns the error", func() { tokenRefresher.RefreshTokenError = errors.New("Refreshing went wrong") runCommand() Expect(ui.Outputs).To(ContainSubstrings( []string{"Refreshing went wrong"}, []string{"FAILED"}, )) }) }) Context("When no flags are provided", func() { It("tells the user it is obtaining the service access", func() { runCommand() Expect(ui.Outputs).To(ContainSubstrings( []string{"Getting service access as", "my-user"}, ))
return testcmd.RunCommand(cmd, []string{}, requirementsFactory) } Describe("requirments", func() { It("fails when the user is not logged in", func() { Expect(runCommand()).ToNot(HavePassedRequirements()) }) }) Describe("When logged in", func() { BeforeEach(func() { requirementsFactory.LoginSuccess = true }) It("fails if oauth refresh fails", func() { authRepo.RefreshTokenError = errors.New("Could not refresh") runCommand() Expect(ui.Outputs).To(ContainSubstrings( []string{"FAILED"}, []string{"Could not refresh"}, )) }) It("returns to the user the oauth token after a refresh", func() { authRepo.RefreshToken = "1234567890" runCommand() Expect(ui.Outputs).To(ContainSubstrings( []string{"Getting OAuth token..."}, []string{"OK"},