github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/command/v6/disable_org_isolation_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/actor/v3action"
     8  	"code.cloudfoundry.org/cli/command/commandfakes"
     9  	. "code.cloudfoundry.org/cli/command/v6"
    10  	"code.cloudfoundry.org/cli/command/v6/v6fakes"
    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("disable-org-isolation Command", func() {
    19  	var (
    20  		cmd              DisableOrgIsolationCommand
    21  		testUI           *ui.UI
    22  		fakeConfig       *commandfakes.FakeConfig
    23  		fakeSharedActor  *commandfakes.FakeSharedActor
    24  		fakeActor        *v6fakes.FakeDisableOrgIsolationActor
    25  		binaryName       string
    26  		executeErr       error
    27  		isolationSegment string
    28  		org              string
    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(v6fakes.FakeDisableOrgIsolationActor)
    36  
    37  		cmd = DisableOrgIsolationCommand{
    38  			UI:          testUI,
    39  			Config:      fakeConfig,
    40  			SharedActor: fakeSharedActor,
    41  			Actor:       fakeActor,
    42  		}
    43  
    44  		binaryName = "faceman"
    45  		fakeConfig.BinaryNameReturns(binaryName)
    46  		org = "org1"
    47  		isolationSegment = "segment1"
    48  	})
    49  
    50  	JustBeforeEach(func() {
    51  		executeErr = cmd.Execute(nil)
    52  	})
    53  
    54  	When("checking target fails", func() {
    55  		BeforeEach(func() {
    56  			fakeSharedActor.CheckTargetReturns(actionerror.NotLoggedInError{BinaryName: binaryName})
    57  		})
    58  
    59  		It("returns an error", func() {
    60  			Expect(executeErr).To(MatchError(actionerror.NotLoggedInError{BinaryName: binaryName}))
    61  
    62  			Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1))
    63  			checkTargetedOrg, checkTargetedSpace := fakeSharedActor.CheckTargetArgsForCall(0)
    64  			Expect(checkTargetedOrg).To(BeFalse())
    65  			Expect(checkTargetedSpace).To(BeFalse())
    66  		})
    67  	})
    68  
    69  	When("user is logged in", func() {
    70  		BeforeEach(func() {
    71  			fakeConfig.CurrentUserReturns(configv3.User{Name: "admin"}, nil)
    72  			cmd.RequiredArgs.OrganizationName = org
    73  			cmd.RequiredArgs.IsolationSegmentName = isolationSegment
    74  		})
    75  
    76  		It("Outputs a mesaage", func() {
    77  			Expect(testUI.Out).To(Say("Removing entitlement to isolation segment segment1 from org org1 as admin..."))
    78  		})
    79  
    80  		When("revoking is successful", func() {
    81  			BeforeEach(func() {
    82  				fakeActor.DeleteIsolationSegmentOrganizationByNameReturns(v3action.Warnings{"warning 1", "warning 2"}, nil)
    83  			})
    84  
    85  			It("Isolation segnment is revoked from org", func() {
    86  				Expect(executeErr).ToNot(HaveOccurred())
    87  
    88  				Expect(testUI.Out).To(Say("OK"))
    89  				Expect(testUI.Err).To(Say("warning 1"))
    90  				Expect(testUI.Err).To(Say("warning 2"))
    91  
    92  				Expect(fakeActor.DeleteIsolationSegmentOrganizationByNameCallCount()).To(Equal(1))
    93  				actualIsolationSegmentName, actualOrgName := fakeActor.DeleteIsolationSegmentOrganizationByNameArgsForCall(0)
    94  				Expect(actualIsolationSegmentName).To(Equal(isolationSegment))
    95  				Expect(actualOrgName).To(Equal(org))
    96  			})
    97  		})
    98  
    99  		Context("generic error while revoking segment isolation", func() {
   100  			var expectedErr error
   101  
   102  			BeforeEach(func() {
   103  				expectedErr = errors.New("ZOMG")
   104  				fakeActor.DeleteIsolationSegmentOrganizationByNameReturns(v3action.Warnings{"warning 1", "warning 2"}, expectedErr)
   105  			})
   106  
   107  			It("returns the error", func() {
   108  				Expect(executeErr).To(MatchError(expectedErr))
   109  				Expect(testUI.Err).To(Say("warning 1"))
   110  				Expect(testUI.Err).To(Say("warning 2"))
   111  			})
   112  		})
   113  	})
   114  })