github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/command/v7/ssh_code_command_test.go (about) 1 package v7_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/actor/actionerror" 7 "code.cloudfoundry.org/cli/command/commandfakes" 8 . "code.cloudfoundry.org/cli/command/v7" 9 v7 "code.cloudfoundry.org/cli/command/v7" 10 "code.cloudfoundry.org/cli/command/v7/v7fakes" 11 "code.cloudfoundry.org/cli/util/ui" 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 . "github.com/onsi/gomega/gbytes" 15 ) 16 17 var _ = Describe("ssh-code Command", func() { 18 var ( 19 cmd SSHCodeCommand 20 testUI *ui.UI 21 fakeConfig *commandfakes.FakeConfig 22 fakeSharedActor *commandfakes.FakeSharedActor 23 fakeActor *v7fakes.FakeActor 24 binaryName string 25 executeErr error 26 ) 27 28 BeforeEach(func() { 29 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 30 fakeConfig = new(commandfakes.FakeConfig) 31 fakeSharedActor = new(commandfakes.FakeSharedActor) 32 fakeActor = new(v7fakes.FakeActor) 33 34 cmd = v7.SSHCodeCommand{ 35 BaseCommand: v7.BaseCommand{ 36 UI: testUI, 37 Config: fakeConfig, 38 SharedActor: fakeSharedActor, 39 Actor: fakeActor, 40 }, 41 } 42 binaryName = "faceman" 43 fakeConfig.BinaryNameReturns(binaryName) 44 }) 45 46 JustBeforeEach(func() { 47 executeErr = cmd.Execute(nil) 48 }) 49 50 When("checking the target fails", func() { 51 BeforeEach(func() { 52 fakeSharedActor.CheckTargetReturns( 53 actionerror.NotLoggedInError{BinaryName: binaryName}) 54 }) 55 56 It("returns an error", func() { 57 Expect(executeErr).To(MatchError(actionerror.NotLoggedInError{BinaryName: binaryName})) 58 59 Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) 60 targetedOrganizationRequired, targetedSpaceRequired := fakeSharedActor.CheckTargetArgsForCall(0) 61 Expect(targetedOrganizationRequired).To(Equal(false)) 62 Expect(targetedSpaceRequired).To(Equal(false)) 63 }) 64 }) 65 66 When("the user is logged in", func() { 67 var code string 68 69 BeforeEach(func() { 70 code = "s3curep4ss" 71 fakeActor.GetSSHPasscodeReturns(code, nil) 72 }) 73 74 It("displays the ssh code", func() { 75 Expect(executeErr).NotTo(HaveOccurred()) 76 Expect(testUI.Out).To(Say(code)) 77 Expect(fakeActor.GetSSHPasscodeCallCount()).To(Equal(1)) 78 }) 79 80 When("an error is encountered getting the ssh code", func() { 81 var expectedErr error 82 83 BeforeEach(func() { 84 expectedErr = errors.New("get ssh code error") 85 fakeActor.GetSSHPasscodeReturns("", expectedErr) 86 }) 87 88 It("returns the error", func() { 89 Expect(executeErr).To(MatchError(expectedErr)) 90 91 Expect(fakeActor.GetSSHPasscodeCallCount()).To(Equal(1)) 92 }) 93 }) 94 }) 95 })