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