github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/actor/v2action/ssh_test.go (about)

     1  package v2action_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	. "code.cloudfoundry.org/cli/actor/v2action"
     7  	"code.cloudfoundry.org/cli/actor/v2action/v2actionfakes"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("SSH Actions", func() {
    13  	var (
    14  		actor         *Actor
    15  		fakeConfig    *v2actionfakes.FakeConfig
    16  		fakeUAAClient *v2actionfakes.FakeUAAClient
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		fakeConfig = new(v2actionfakes.FakeConfig)
    21  		fakeUAAClient = new(v2actionfakes.FakeUAAClient)
    22  		actor = NewActor(nil, fakeUAAClient, fakeConfig)
    23  	})
    24  
    25  	Describe("GetSSHPasscode", func() {
    26  		var uaaAccessToken string
    27  
    28  		BeforeEach(func() {
    29  			uaaAccessToken = "4cc3sst0k3n"
    30  			fakeConfig.AccessTokenReturns(uaaAccessToken)
    31  			fakeConfig.SSHOAuthClientReturns("some-id")
    32  		})
    33  
    34  		Context("when no errors are encountered getting the ssh passcode", func() {
    35  			var expectedCode string
    36  
    37  			BeforeEach(func() {
    38  				expectedCode = "s3curep4ss"
    39  				fakeUAAClient.GetSSHPasscodeReturns(expectedCode, nil)
    40  			})
    41  
    42  			It("returns the ssh passcode", func() {
    43  				code, err := actor.GetSSHPasscode()
    44  				Expect(err).ToNot(HaveOccurred())
    45  				Expect(code).To(Equal(expectedCode))
    46  				Expect(fakeUAAClient.GetSSHPasscodeCallCount()).To(Equal(1))
    47  				accessTokenArg, sshOAuthClientArg := fakeUAAClient.GetSSHPasscodeArgsForCall(0)
    48  				Expect(accessTokenArg).To(Equal(uaaAccessToken))
    49  				Expect(sshOAuthClientArg).To(Equal("some-id"))
    50  			})
    51  		})
    52  
    53  		Context("when an error is encountered getting the ssh passcode", func() {
    54  			var expectedErr error
    55  
    56  			BeforeEach(func() {
    57  				expectedErr = errors.New("failed fetching code")
    58  				fakeUAAClient.GetSSHPasscodeReturns("", expectedErr)
    59  			})
    60  
    61  			It("returns the error", func() {
    62  				_, err := actor.GetSSHPasscode()
    63  				Expect(err).To(MatchError(expectedErr))
    64  				Expect(fakeUAAClient.GetSSHPasscodeCallCount()).To(Equal(1))
    65  				accessTokenArg, sshOAuthClientArg := fakeUAAClient.GetSSHPasscodeArgsForCall(0)
    66  				Expect(accessTokenArg).To(Equal(uaaAccessToken))
    67  				Expect(sshOAuthClientArg).To(Equal("some-id"))
    68  			})
    69  		})
    70  	})
    71  })