github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/command/v7/bind_running_security_group_command_test.go (about) 1 package v7_test 2 3 import ( 4 "errors" 5 6 "github.com/LukasHeimann/cloudfoundrycli/v8/actor/v7action" 7 "github.com/LukasHeimann/cloudfoundrycli/v8/api/cloudcontroller/ccv3/constant" 8 "github.com/LukasHeimann/cloudfoundrycli/v8/command/commandfakes" 9 "github.com/LukasHeimann/cloudfoundrycli/v8/command/flag" 10 . "github.com/LukasHeimann/cloudfoundrycli/v8/command/v7" 11 "github.com/LukasHeimann/cloudfoundrycli/v8/command/v7/v7fakes" 12 "github.com/LukasHeimann/cloudfoundrycli/v8/util/configv3" 13 "github.com/LukasHeimann/cloudfoundrycli/v8/util/ui" 14 . "github.com/onsi/ginkgo" 15 . "github.com/onsi/gomega" 16 . "github.com/onsi/gomega/gbytes" 17 ) 18 19 var _ = Describe("bind-running-security-group Command", func() { 20 var ( 21 cmd BindRunningSecurityGroupCommand 22 testUI *ui.UI 23 fakeConfig *commandfakes.FakeConfig 24 fakeSharedActor *commandfakes.FakeSharedActor 25 fakeActor *v7fakes.FakeActor 26 binaryName string 27 executeErr error 28 securityGroupName = "sec-group-name" 29 ) 30 31 BeforeEach(func() { 32 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 33 fakeConfig = new(commandfakes.FakeConfig) 34 fakeSharedActor = new(commandfakes.FakeSharedActor) 35 fakeActor = new(v7fakes.FakeActor) 36 37 cmd = BindRunningSecurityGroupCommand{ 38 BaseCommand: BaseCommand{ 39 UI: testUI, 40 Config: fakeConfig, 41 SharedActor: fakeSharedActor, 42 Actor: fakeActor, 43 }, 44 SecurityGroup: flag.SecurityGroup{SecurityGroup: securityGroupName}, 45 } 46 47 binaryName = "faceman" 48 fakeConfig.BinaryNameReturns(binaryName) 49 50 fakeActor.GetCurrentUserReturns( 51 configv3.User{Name: "some-user"}, 52 nil) 53 }) 54 55 JustBeforeEach(func() { 56 executeErr = cmd.Execute(nil) 57 }) 58 BeforeEach(func() { 59 fakeActor.UpdateSecurityGroupGloballyEnabledReturns( 60 v7action.Warnings{"globally bind security group warning"}, 61 nil) 62 }) 63 64 When("the current user is invalid", func() { 65 BeforeEach(func() { 66 fakeActor.GetCurrentUserReturns( 67 configv3.User{}, 68 errors.New("some-error")) 69 }) 70 It("returns the error", func() { 71 Expect(executeErr).To(HaveOccurred()) 72 Expect(executeErr).To(MatchError("some-error")) 73 }) 74 }) 75 76 It("globally binds the security group displays all warnings", func() { 77 Expect(testUI.Out).To(Say(`Binding security group sec-group-name to running as some-user\.\.\.`)) 78 79 Expect(fakeActor.UpdateSecurityGroupGloballyEnabledCallCount()).To(Equal(1)) 80 securityGroupName, lifecycle, enabled := fakeActor.UpdateSecurityGroupGloballyEnabledArgsForCall(0) 81 Expect(securityGroupName).To(Equal("sec-group-name")) 82 Expect(lifecycle).To(Equal(constant.SecurityGroupLifecycleRunning)) 83 Expect(enabled).To(Equal(true)) 84 }) 85 86 When("an error is encountered globally binding the security group", func() { 87 var expectedErr error 88 89 BeforeEach(func() { 90 expectedErr = errors.New("bind security group error") 91 fakeActor.UpdateSecurityGroupGloballyEnabledReturns( 92 v7action.Warnings{"globally bind security group warning"}, 93 expectedErr) 94 }) 95 96 It("returns the error and displays all warnings", func() { 97 Expect(executeErr).To(MatchError(expectedErr)) 98 99 Expect(testUI.Out).NotTo(Say("OK")) 100 101 Expect(testUI.Err).To(Say("globally bind security group warning")) 102 }) 103 }) 104 105 It("signals that the security group is bound and provides a helpful tip", func() { 106 Expect(testUI.Out).To(Say("OK")) 107 Expect(testUI.Out).To(Say(`TIP: If Dynamic ASG's are enabled, changes will automatically apply for running and staging applications. Otherwise, changes will require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 108 Expect(testUI.Err).To(Say("globally bind security group warning")) 109 Expect(executeErr).NotTo(HaveOccurred()) 110 }) 111 })