github.com/loafoe/cli@v7.1.0+incompatible/command/v7/space_ssh_allowed_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/actor/v7action" 8 "code.cloudfoundry.org/cli/command/commandfakes" 9 "code.cloudfoundry.org/cli/command/flag" 10 . "code.cloudfoundry.org/cli/command/v7" 11 "code.cloudfoundry.org/cli/command/v7/v7fakes" 12 "code.cloudfoundry.org/cli/util/configv3" 13 "code.cloudfoundry.org/cli/util/ui" 14 15 . "github.com/onsi/ginkgo" 16 . "github.com/onsi/gomega" 17 . "github.com/onsi/gomega/gbytes" 18 ) 19 20 var _ = Describe("space-ssh-allowed command", func() { 21 var ( 22 cmd SpaceSSHAllowedCommand 23 testUI *ui.UI 24 fakeConfig *commandfakes.FakeConfig 25 fakeSharedActor *commandfakes.FakeSharedActor 26 fakeActor *v7fakes.FakeActor 27 executeErr error 28 binaryName string 29 30 spaceName string 31 spaceSSHWarning v7action.Warnings 32 ) 33 34 BeforeEach(func() { 35 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 36 fakeConfig = new(commandfakes.FakeConfig) 37 fakeSharedActor = new(commandfakes.FakeSharedActor) 38 fakeActor = new(v7fakes.FakeActor) 39 spaceName = RandomString("space") 40 41 cmd = SpaceSSHAllowedCommand{ 42 BaseCommand: BaseCommand{ 43 UI: testUI, 44 Config: fakeConfig, 45 SharedActor: fakeSharedActor, 46 Actor: fakeActor, 47 }, 48 RequiredArgs: flag.Space{Space: spaceName}, 49 } 50 51 spaceSSHWarning = v7action.Warnings{"space-ssh-warning"} 52 53 binaryName = "faceman" 54 fakeConfig.BinaryNameReturns(binaryName) 55 fakeConfig.TargetedOrganizationReturns(configv3.Organization{GUID: "some-org-guid"}) 56 57 fakeActor.GetSpaceFeatureReturns(true, spaceSSHWarning, nil) 58 }) 59 60 JustBeforeEach(func() { 61 executeErr = cmd.Execute(nil) 62 }) 63 64 When("the environment is not set up correctly", func() { 65 BeforeEach(func() { 66 fakeSharedActor.CheckTargetReturns(actionerror.NotLoggedInError{BinaryName: binaryName}) 67 }) 68 69 It("returns an error", func() { 70 Expect(executeErr).To(MatchError(actionerror.NotLoggedInError{BinaryName: binaryName})) 71 Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) 72 checkTargetedOrg, checkTargetedSpace := fakeSharedActor.CheckTargetArgsForCall(0) 73 Expect(checkTargetedOrg).To(BeTrue()) 74 Expect(checkTargetedSpace).To(BeFalse()) 75 }) 76 }) 77 78 When("there is an error getting the SSH feature", func() { 79 BeforeEach(func() { 80 fakeActor.GetSpaceFeatureReturns(true, spaceSSHWarning, errors.New("some-feature-error")) 81 }) 82 It("returns the error", func() { 83 Expect(executeErr).To(HaveOccurred()) 84 Expect(executeErr).To(MatchError("some-feature-error")) 85 Expect(testUI.Err).To(Say("space-ssh-warning")) 86 }) 87 }) 88 89 It("prints the feature", func() { 90 Expect(executeErr).To(Not(HaveOccurred())) 91 Expect(fakeActor.GetSpaceFeatureCallCount()).To(Equal(1)) 92 inputSpaceName, inputOrgGUID, inputFeature := fakeActor.GetSpaceFeatureArgsForCall(0) 93 Expect(inputSpaceName).To(Equal(spaceName)) 94 Expect(inputOrgGUID).To(Equal("some-org-guid")) 95 Expect(inputFeature).To(Equal("ssh")) 96 97 Expect(testUI.Err).To(Say("space-ssh-warning")) 98 Expect(testUI.Out).To(Say("ssh support is enabled in space '%s'.", spaceName)) 99 }) 100 })