github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/command/v6/v3_apply_manifest_command_test.go (about) 1 package v6_test 2 3 import ( 4 "errors" 5 "regexp" 6 7 "code.cloudfoundry.org/cli/actor/actionerror" 8 "code.cloudfoundry.org/cli/actor/v3action" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 10 "code.cloudfoundry.org/cli/command/commandfakes" 11 "code.cloudfoundry.org/cli/command/flag" 12 "code.cloudfoundry.org/cli/command/translatableerror" 13 . "code.cloudfoundry.org/cli/command/v6" 14 "code.cloudfoundry.org/cli/command/v6/v6fakes" 15 "code.cloudfoundry.org/cli/util/configv3" 16 "code.cloudfoundry.org/cli/util/ui" 17 . "github.com/onsi/ginkgo" 18 . "github.com/onsi/gomega" 19 . "github.com/onsi/gomega/gbytes" 20 ) 21 22 var _ = Describe("v3-apply-manifest Command", func() { 23 var ( 24 cmd V3ApplyManifestCommand 25 testUI *ui.UI 26 fakeConfig *commandfakes.FakeConfig 27 fakeSharedActor *commandfakes.FakeSharedActor 28 fakeActor *v6fakes.FakeV3ApplyManifestActor 29 fakeParser *v6fakes.FakeManifestParser 30 binaryName string 31 executeErr error 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(v6fakes.FakeV3ApplyManifestActor) 39 fakeParser = new(v6fakes.FakeManifestParser) 40 41 binaryName = "faceman" 42 fakeConfig.BinaryNameReturns(binaryName) 43 44 cmd = V3ApplyManifestCommand{ 45 UI: testUI, 46 Config: fakeConfig, 47 SharedActor: fakeSharedActor, 48 Actor: fakeActor, 49 Parser: fakeParser, 50 } 51 }) 52 53 JustBeforeEach(func() { 54 executeErr = cmd.Execute(nil) 55 }) 56 57 When("the API version is below the minimum", func() { 58 BeforeEach(func() { 59 fakeActor.CloudControllerAPIVersionReturns(ccversion.MinV3ClientVersion) 60 }) 61 62 It("returns a MinimumAPIVersionNotMetError", func() { 63 Expect(executeErr).To(MatchError(translatableerror.MinimumCFAPIVersionNotMetError{ 64 CurrentVersion: ccversion.MinV3ClientVersion, 65 MinimumVersion: ccversion.MinVersionApplicationFlowV3, 66 })) 67 }) 68 69 It("displays the experimental warning", func() { 70 Expect(testUI.Err).To(Say("This command is in EXPERIMENTAL stage and may change without notice")) 71 }) 72 }) 73 74 When("checking target fails", func() { 75 BeforeEach(func() { 76 fakeActor.CloudControllerAPIVersionReturns(ccversion.MinVersionApplicationFlowV3) 77 fakeSharedActor.CheckTargetReturns(actionerror.NoOrganizationTargetedError{BinaryName: binaryName}) 78 }) 79 80 It("returns an error", func() { 81 Expect(executeErr).To(MatchError(actionerror.NoOrganizationTargetedError{BinaryName: binaryName})) 82 83 Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) 84 checkTargetedOrg, checkTargetedSpace := fakeSharedActor.CheckTargetArgsForCall(0) 85 Expect(checkTargetedOrg).To(BeTrue()) 86 Expect(checkTargetedSpace).To(BeTrue()) 87 }) 88 }) 89 90 When("the user is not logged in", func() { 91 var expectedErr error 92 93 BeforeEach(func() { 94 fakeActor.CloudControllerAPIVersionReturns(ccversion.MinVersionApplicationFlowV3) 95 expectedErr = errors.New("some current user error") 96 fakeConfig.CurrentUserReturns(configv3.User{}, expectedErr) 97 }) 98 99 It("return an error", func() { 100 Expect(executeErr).To(Equal(expectedErr)) 101 }) 102 }) 103 104 When("the user is logged in", func() { 105 var ( 106 providedPath string 107 ) 108 109 BeforeEach(func() { 110 fakeActor.CloudControllerAPIVersionReturns(ccversion.MinVersionApplicationFlowV3) 111 fakeConfig.TargetedOrganizationReturns(configv3.Organization{ 112 Name: "some-org", 113 }) 114 fakeConfig.TargetedSpaceReturns(configv3.Space{ 115 Name: "some-space", 116 GUID: "some-space-guid", 117 }) 118 fakeConfig.CurrentUserReturns(configv3.User{Name: "steve"}, nil) 119 120 providedPath = "some-manifest-path" 121 cmd.PathToManifest = flag.PathWithExistenceCheck(providedPath) 122 }) 123 124 When("the parse is successful", func() { 125 BeforeEach(func() { 126 fakeActor.ApplyApplicationManifestReturns( 127 v3action.Warnings{"some-manifest-warning"}, 128 nil, 129 ) 130 }) 131 132 It("displays the success text", func() { 133 Expect(executeErr).ToNot(HaveOccurred()) 134 Expect(testUI.Out).To(Say("Applying manifest %s in org some-org / space some-space as steve...", regexp.QuoteMeta(providedPath))) 135 Expect(testUI.Err).To(Say("some-manifest-warning")) 136 Expect(testUI.Out).To(Say("OK")) 137 138 Expect(fakeParser.ParseCallCount()).To(Equal(1)) 139 Expect(fakeParser.ParseArgsForCall(0)).To(Equal(providedPath)) 140 141 Expect(fakeActor.ApplyApplicationManifestCallCount()).To(Equal(1)) 142 parserArg, spaceGUIDArg := fakeActor.ApplyApplicationManifestArgsForCall(0) 143 Expect(parserArg).To(Equal(fakeParser)) 144 Expect(spaceGUIDArg).To(Equal("some-space-guid")) 145 }) 146 }) 147 148 When("the parse errors", func() { 149 var expectedErr error 150 151 BeforeEach(func() { 152 expectedErr = errors.New("oooooh nooooos") 153 fakeParser.ParseReturns(expectedErr) 154 }) 155 156 It("returns back the parse error", func() { 157 Expect(executeErr).To(MatchError(expectedErr)) 158 159 Expect(fakeActor.ApplyApplicationManifestCallCount()).To(Equal(0)) 160 }) 161 }) 162 }) 163 })