. "github.com/onsi/gomega" ) var _ = Describe("GetSSHCode", func() { var fakeCredFactory *credential_fakes.FakeCredentialFactory BeforeEach(func() { fakeCredFactory = &credential_fakes.FakeCredentialFactory{} }) It("validates the command name", func() { err := cmd.GetSSHCode([]string{"bogus-name"}, fakeCredFactory, nil) Expect(err).To(MatchError("Invalid usage\n" + cmd.GetSSHCodeUsage)) }) It("does not accept any arugments", func() { err := cmd.GetSSHCode([]string{"get-ssh-code", "bogus-argument"}, fakeCredFactory, nil) Expect(err).To(MatchError("Invalid usage\n" + cmd.GetSSHCodeUsage)) }) It("gets the authorization code from the credential factory", func() { fakeCredFactory.AuthorizationCodeReturns("xyxpdq", nil) writer := &bytes.Buffer{} err := cmd.GetSSHCode([]string{"get-ssh-code"}, fakeCredFactory, writer) Expect(err).NotTo(HaveOccurred()) Expect(writer.String()).To(Equal("xyxpdq\n")) }) })
It("returns the error", func() { Expect(fakeAppFactory.GetCallCount()).To(Equal(1)) Expect(connectErr).To(Equal(errors.New("woops"))) }) }) }) Context("when the app model and endpoint info are successfully acquired", func() { BeforeEach(func() { fakeAppFactory.GetReturns(app.App{ State: "STARTED", Diego: true, }, nil) fakeInfoFactory.GetReturns(info.Info{}, nil) fakeCredFactory.AuthorizationCodeReturns("", nil) }) It("gets the current oauth token credential", func() { Expect(fakeCredFactory.AuthorizationCodeCallCount()).To(Equal(1)) }) Context("when getting the credential fails", func() { BeforeEach(func() { fakeCredFactory.AuthorizationCodeReturns("", errors.New("woops")) }) It("returns the error", func() { Expect(fakeCredFactory.AuthorizationCodeCallCount()).To(Equal(1)) Expect(connectErr).To(Equal(errors.New("woops"))) })