github.com/sleungcy-sap/cli@v7.1.0+incompatible/command/v7/unbind_running_group_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/v7" 10 "code.cloudfoundry.org/cli/command/v7/v7fakes" 11 "code.cloudfoundry.org/cli/util/configv3" 12 "code.cloudfoundry.org/cli/util/ui" 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 . "github.com/onsi/gomega/gbytes" 16 ) 17 18 var _ = Describe("unbind-running-security-group Command", func() { 19 var ( 20 cmd UnbindRunningSecurityGroupCommand 21 testUI *ui.UI 22 fakeConfig *commandfakes.FakeConfig 23 fakeSharedActor *commandfakes.FakeSharedActor 24 fakeActor *v7fakes.FakeActor 25 binaryName string 26 executeErr error 27 ) 28 29 BeforeEach(func() { 30 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 31 fakeConfig = new(commandfakes.FakeConfig) 32 fakeSharedActor = new(commandfakes.FakeSharedActor) 33 fakeActor = new(v7fakes.FakeActor) 34 35 cmd = UnbindRunningSecurityGroupCommand{ 36 BaseCommand: BaseCommand{ 37 UI: testUI, 38 Config: fakeConfig, 39 SharedActor: fakeSharedActor, 40 Actor: fakeActor, 41 }, 42 } 43 44 binaryName = "faceman" 45 fakeConfig.BinaryNameReturns(binaryName) 46 47 cmd.RequiredArgs.SecurityGroup = "some-security-group" 48 49 fakeConfig.CurrentUserReturns( 50 configv3.User{Name: "some-user"}, 51 nil) 52 }) 53 54 JustBeforeEach(func() { 55 executeErr = cmd.Execute(nil) 56 }) 57 58 When("the command executes successfully", func() { 59 BeforeEach(func() { 60 fakeActor.UpdateSecurityGroupGloballyEnabledReturns( 61 v7action.Warnings{"get security group warning"}, 62 nil) 63 }) 64 65 It("unbinds the security group from being available globally for running", func() { 66 Expect(executeErr).NotTo(HaveOccurred()) 67 Expect(testUI.Out).To(Say("Unbinding security group %s from defaults for running as some-user...", cmd.RequiredArgs.SecurityGroup)) 68 Expect(testUI.Out).To(Say("OK")) 69 Expect(testUI.Out).To(Say(`TIP: Changes require an app restart \(for running\) or restage \(for staging\) to apply to existing applications\.`)) 70 71 Expect(testUI.Err).To(Say("get security group warning")) 72 }) 73 }) 74 75 When("the security group does not exist", func() { 76 BeforeEach(func() { 77 fakeActor.UpdateSecurityGroupGloballyEnabledReturns( 78 v7action.Warnings{"update security group warning"}, 79 actionerror.SecurityGroupNotFoundError{Name: cmd.RequiredArgs.SecurityGroup}) 80 }) 81 82 It("displays OK, warning and exits without error", func() { 83 Expect(testUI.Err).To(Say("update security group warning")) 84 Expect(testUI.Err).To(Say("Security group '%s' not found.", cmd.RequiredArgs.SecurityGroup)) 85 Expect(testUI.Out).To(Say("OK")) 86 Expect(executeErr).NotTo(HaveOccurred()) 87 }) 88 }) 89 90 When("updating the security group fails", func() { 91 BeforeEach(func() { 92 fakeActor.UpdateSecurityGroupGloballyEnabledReturns( 93 v7action.Warnings{"update security group warning"}, 94 errors.New("update security group error")) 95 }) 96 97 It("returns the error", func() { 98 Expect(testUI.Err).To(Say("update security group warning")) 99 Expect(executeErr).To(MatchError("update security group error")) 100 }) 101 }) 102 })