@@ -19,14 +19,18 @@ func TestCreateAppCommand_Run_Flags(t *testing.T) {
1919 ctrl := gomock .NewController (t )
2020 defer ctrl .Finish ()
2121
22+ description := "Test application"
23+ businessCriticality := "high"
24+ maturityLevel := "production"
25+
2226 ctx := & components.Context {
2327 Arguments : []string {"app-key" },
2428 }
2529 ctx .AddStringFlag ("application-name" , "test-app" )
2630 ctx .AddStringFlag ("project" , "test-project" )
27- ctx .AddStringFlag ("desc" , "Test application" )
31+ ctx .AddStringFlag ("desc" , description )
2832 ctx .AddStringFlag ("business-criticality" , "high" )
29- ctx .AddStringFlag ("maturity-level" , "production" )
33+ ctx .AddStringFlag ("maturity-level" , maturityLevel )
3034 ctx .AddStringFlag ("labels" , "env=prod;region=us-east" )
3135 ctx .AddStringFlag ("user-owners" , "john.doe;jane.smith" )
3236 ctx .AddStringFlag ("group-owners" , "devops;security" )
@@ -36,15 +40,15 @@ func TestCreateAppCommand_Run_Flags(t *testing.T) {
3640 ApplicationKey : "app-key" ,
3741 ApplicationName : "test-app" ,
3842 ProjectKey : "test-project" ,
39- Description : "Test application" ,
40- BusinessCriticality : "high" ,
41- MaturityLevel : "production" ,
42- Labels : map [string ]string {
43+ Description : & description ,
44+ BusinessCriticality : & businessCriticality ,
45+ MaturityLevel : & maturityLevel ,
46+ Labels : & map [string ]string {
4347 "env" : "prod" ,
4448 "region" : "us-east" ,
4549 },
46- UserOwners : []string {"john.doe" , "jane.smith" },
47- GroupOwners : []string {"devops" , "security" },
50+ UserOwners : & []string {"john.doe" , "jane.smith" },
51+ GroupOwners : & []string {"devops" , "security" },
4852 }
4953
5054 mockAppService := mockapps .NewMockApplicationService (ctrl )
@@ -125,6 +129,52 @@ func TestCreateAppCommand_MissingProjectFlag(t *testing.T) {
125129 assert .Contains (t , err .Error (), "--project is mandatory" )
126130}
127131
132+ func TestCreateAppCommand_Run_FullSpecFile (t * testing.T ) {
133+ ctrl := gomock .NewController (t )
134+ defer ctrl .Finish ()
135+
136+ ctx := & components.Context {
137+ Arguments : []string {"app-full" },
138+ }
139+ ctx .AddStringFlag ("url" , "https://example.com" )
140+ ctx .AddStringFlag ("spec" , "./testfiles/full-spec.json" )
141+
142+ expectedDescription := "A comprehensive test application"
143+ expectedMaturityLevel := "production"
144+ expectedBusinessCriticality := "high"
145+ expectedPayload := & model.AppDescriptor {
146+ ApplicationKey : "app-full" ,
147+ ApplicationName : "test-app-full" ,
148+ ProjectKey : "test-project" ,
149+ Description : & expectedDescription ,
150+ MaturityLevel : & expectedMaturityLevel ,
151+ BusinessCriticality : & expectedBusinessCriticality ,
152+ Labels : & map [string ]string {
153+ "environment" : "production" ,
154+ "region" : "us-east-1" ,
155+ "team" : "devops" ,
156+ },
157+ UserOwners : & []string {"john.doe" , "jane.smith" },
158+ GroupOwners : & []string {"devops-team" , "security-team" },
159+ }
160+
161+ var actualPayload * model.AppDescriptor
162+ mockAppService := mockapps .NewMockApplicationService (ctrl )
163+ mockAppService .EXPECT ().CreateApplication (gomock .Any (), gomock .Any ()).
164+ DoAndReturn (func (_ interface {}, req * model.AppDescriptor ) error {
165+ actualPayload = req
166+ return nil
167+ }).Times (1 )
168+
169+ cmd := & createAppCommand {
170+ applicationService : mockAppService ,
171+ }
172+
173+ err := cmd .prepareAndRunCommand (ctx )
174+ assert .NoError (t , err )
175+ assert .Equal (t , expectedPayload , actualPayload )
176+ }
177+
128178func TestCreateAppCommand_Run_SpecFile (t * testing.T ) {
129179 tests := []struct {
130180 name string
@@ -144,26 +194,6 @@ func TestCreateAppCommand_Run_SpecFile(t *testing.T) {
144194 ProjectKey : "test-project" ,
145195 },
146196 },
147- {
148- name : "full spec file" ,
149- specPath : "./testfiles/full-spec.json" ,
150- args : []string {"app-full" },
151- expectsPayload : & model.AppDescriptor {
152- ApplicationKey : "app-full" ,
153- ApplicationName : "test-app-full" ,
154- ProjectKey : "test-project" ,
155- Description : "A comprehensive test application" ,
156- MaturityLevel : "production" ,
157- BusinessCriticality : "high" ,
158- Labels : map [string ]string {
159- "environment" : "production" ,
160- "region" : "us-east-1" ,
161- "team" : "devops" ,
162- },
163- UserOwners : []string {"john.doe" , "jane.smith" },
164- GroupOwners : []string {"devops-team" , "security-team" },
165- },
166- },
167197 {
168198 name : "invalid spec file" ,
169199 specPath : "./testfiles/invalid-spec.json" ,
@@ -193,7 +223,6 @@ func TestCreateAppCommand_Run_SpecFile(t *testing.T) {
193223 ApplicationKey : "command-line-app-key" ,
194224 ApplicationName : "test-app" ,
195225 ProjectKey : "test-project" ,
196- Description : "A test application with application_key that should be ignored" ,
197226 },
198227 },
199228 }
@@ -241,14 +270,18 @@ func TestCreateAppCommand_Run_SpecVars(t *testing.T) {
241270 ctrl := gomock .NewController (t )
242271 defer ctrl .Finish ()
243272
273+ expectedDescription := "A test application for production"
274+ expectedMaturityLevel := "production"
275+ expectedBusinessCriticality := "high"
276+
244277 expectedPayload := & model.AppDescriptor {
245278 ApplicationKey : "app-with-vars" ,
246279 ApplicationName : "test-app" ,
247280 ProjectKey : "test-project" ,
248- Description : "A test application for production" ,
249- MaturityLevel : "production" ,
250- BusinessCriticality : "high" ,
251- Labels : map [string ]string {
281+ Description : & expectedDescription ,
282+ MaturityLevel : & expectedMaturityLevel ,
283+ BusinessCriticality : & expectedBusinessCriticality ,
284+ Labels : & map [string ]string {
252285 "environment" : "production" ,
253286 "region" : "us-east-1" ,
254287 },
0 commit comments