@@ -2,6 +2,7 @@ package commands_test
22
33import (
44 "encoding/base64"
5+ "errors"
56 "fmt"
67 "io"
78 "io/fs"
@@ -12,6 +13,7 @@ import (
1213 "time"
1314
1415 cli_fakes "github.com/cloudfoundry-incubator/multiapps-cli-plugin/cli/fakes"
16+ cf_client_fakes "github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/cfrestclient/fakes"
1517 "github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/models"
1618 "github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/mtaclient"
1719 mtafake "github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/mtaclient/fakes"
@@ -112,41 +114,62 @@ var _ = Describe("DeployCommand", func() {
112114 if fromUrl {
113115 mtaNameToPrint = "from url"
114116 }
117+
115118 lines = append (lines ,
116- "Deploying multi-target app archive " + mtaNameToPrint + " in org " + org + " / space " + space + " as " + user + "..." )
117- lines = append (lines , "" )
119+ "Deploying multi-target app archive " + mtaNameToPrint + " in org " + org + " / space " + space + " as " + user + "..." ,
120+ "" ,
121+ )
122+
118123 if processAborted {
119124 lines = append (lines ,
120125 "Executing action \" abort\" on operation test-process-id..." ,
121126 "OK" ,
122127 )
123128 }
124- if fromUrl {
125- lines = append (lines , "OK" )
126- } else {
129+
130+ if ! fromUrl {
131+ if existentUserProvidedServiceSecurity {
132+ lines = append (lines ,
133+ "Using existing user-provided service " + userProvidedServiceSecurityRelated + " for secure parameters." )
134+ }
135+
136+ if createdUserProvidedServiceSecurity {
137+ lines = append (lines ,
138+ "Created user-provided service " + userProvidedServiceSecurityRelated + " for secure parameters." )
139+ }
140+
127141 lines = append (lines ,
128142 "Uploading 1 files..." ,
129143 " " + fullMtaArchivePath ,
130- "OK" )
144+ "OK" ,
145+ )
146+ } else {
147+ if existentUserProvidedServiceSecurity {
148+ lines = append (lines ,
149+ "Using existing user-provided service " + userProvidedServiceSecurityRelated + " for secure parameters." )
150+ }
151+
152+ if createdUserProvidedServiceSecurity {
153+ lines = append (lines ,
154+ "Created user-provided service " + userProvidedServiceSecurityRelated + " for secure parameters." )
155+ }
156+ lines = append (lines , "OK" )
131157 }
158+
132159 if extDescriptor {
133160 lines = append (lines ,
134161 "Uploading 1 files..." ,
135162 " " + fullExtDescriptorPath ,
136- "OK" )
137- }
138- if existentUserProvidedServiceSecurity {
139- lines = append (lines ,
140- "Using existing user-provided service " + userProvidedServiceSecurityRelated + " for secure parameters." )
141- }
142- if createdUserProvidedServiceSecurity {
143- lines = append (lines ,
144- "Created user-provided service " + userProvidedServiceSecurityRelated + " for secure parameters." )
163+ "OK" ,
164+ )
145165 }
166+
146167 lines = append (lines ,
147168 "Test message" ,
148169 "Process finished." ,
149- "Use \" cf dmol -i 1000\" to download the logs of the process." )
170+ "Use \" cf dmol -i 1000\" to download the logs of the process." ,
171+ )
172+
150173 return lines
151174 }
152175
@@ -180,6 +203,7 @@ var _ = Describe("DeployCommand", func() {
180203
181204 BeforeEach (func () {
182205 ui .DisableTerminalOutput (true )
206+ command = commands .NewDeployCommand ()
183207 name = command .GetPluginCommand ().Name
184208 cliConnection = cli_fakes .NewFakeCliConnectionBuilder ().
185209 CurrentOrg ("test-org-guid" , org , nil ).
@@ -194,8 +218,9 @@ var _ = Describe("DeployCommand", func() {
194218 jobId := "one"
195219 fileUploadJobId .Add ("Location" , jobId )
196220 jobResult := mtaclient.AsyncUploadJobResult {
197- File : mtaArchive ,
198- MtaId : "anatz" ,
221+ File : mtaArchive ,
222+ MtaId : "anatz" ,
223+ SchemaVersion : "3.1.0" ,
199224 }
200225 mtaClient = mtafake .NewFakeMtaClientBuilder ().
201226 GetMtaFiles ([]* models.FileMetadata {& testutil .SimpleFile }, nil ).
@@ -209,7 +234,6 @@ var _ = Describe("DeployCommand", func() {
209234 GetMtaOperationLogContent ("1000" , testutil .LogID , testutil .LogContent , nil ).
210235 GetMtaOperations (nil , nil , nil , []* models.Operation {& testutil .OperationResult }, nil ).Build ()
211236 testClientFactory = commands .NewTestClientFactory (mtaClient , nil , nil )
212- command = commands .NewDeployCommand ()
213237 testTokenFactory := commands .NewTestTokenFactory (cliConnection )
214238 deployServiceURLCalculator := util_fakes .NewDeployServiceURLFakeCalculator ("deploy-service.test.ondemand.com" )
215239 command .InitializeAll (name , cliConnection , testutil .NewCustomTransport (200 ), testClientFactory , testTokenFactory , deployServiceURLCalculator )
@@ -511,12 +535,12 @@ var _ = Describe("DeployCommand", func() {
511535 command .FileUrlReader = newMockFileReader (correctMtaUrl )
512536
513537 upsName := "__mta-secure-anatz"
514- cliConnection . CliCommandWithoutTerminalOutputStub = func ( args ... string ) ([] string , error ) {
515- if len ( args ) > 0 && args [ 0 ] == "services" {
516- table := fmt . Sprintf ( "%s user-provided fake-plan \n another-service-instance managed fake-plan \n " , upsName )
517- return [] string { table }, nil
518- }
519- return [] string {}, nil
538+ command . CfClient = & cf_client_fakes. FakeCloudFoundryClient {
539+ Services : []models. CloudFoundryServiceInstance { {
540+ Guid : "ups-guid" ,
541+ Name : upsName },
542+ },
543+ ServiceBindingsErr : nil ,
520544 }
521545
522546 output , status := oc .CaptureOutputAndStatus (func () int {
@@ -540,18 +564,14 @@ var _ = Describe("DeployCommand", func() {
540564 defer os .Unsetenv ("__MTA___fake-variable" )
541565 command .FileUrlReader = newMockFileReader (correctMtaUrl )
542566
543- cliConnection .CliCommandWithoutTerminalOutputStub = func (args ... string ) ([]string , error ) {
544- if len (args ) > 0 && args [0 ] == "services" {
545- return []string {"another-service-instance managed fake-plan\n " }, nil
546- }
547- return []string {}, nil
548- }
549-
550- cliConnection .CliCommandStub = func (args ... string ) ([]string , error ) {
551- if len (args ) > 0 && args [0 ] == "create-user-provided-service" {
552- return []string {}, nil
553- }
554- return []string {}, nil
567+ upsName := "__mta-secure-anatz"
568+ command .CfClient = & cf_client_fakes.FakeCloudFoundryClient {
569+ Services : []models.CloudFoundryServiceInstance {{
570+ Guid : "ups-guid" ,
571+ Name : upsName },
572+ },
573+ ServiceBindingsErr : errors .New ("service instance not found" ),
574+ ServicesErr : nil ,
555575 }
556576
557577 output , status := oc .CaptureOutputAndStatus (func () int {
@@ -575,18 +595,10 @@ var _ = Describe("DeployCommand", func() {
575595 defer os .Unsetenv ("__MTA___fake-variable" )
576596 command .FileUrlReader = newMockFileReader (correctMtaUrl )
577597
578- cliConnection .CliCommandWithoutTerminalOutputStub = func (args ... string ) ([]string , error ) {
579- if len (args ) > 0 && args [0 ] == "services" {
580- return []string {"another-service-instance managed fake-plan\n " }, nil
581- }
582- return []string {}, nil
583- }
584-
585- cliConnection .CliCommandStub = func (args ... string ) ([]string , error ) {
586- if len (args ) > 0 && args [0 ] == "create-user-provided-service" {
587- return nil , fmt .Errorf ("error - could not be created" )
588- }
589- return []string {}, nil
598+ command .CfClient = & cf_client_fakes.FakeCloudFoundryClient {
599+ Services : []models.CloudFoundryServiceInstance {{Name : "fakeName" }},
600+ ServiceBindingsErr : errors .New ("error with cf api" ),
601+ ServicesErr : nil ,
590602 }
591603
592604 output , status := oc .CaptureOutputAndStatus (func () int {
0 commit comments