Skip to content

Commit 13984d0

Browse files
Merge pull request #18494 from SSshahan/negativeCheck_new-app
Automatic merge from submit-queue. add negative checking for new-app Add negative checking for new-app unit-test, please have a review, thanks! @mfojtik @coreydaley could you have a look?
2 parents abe4e06 + 0c2eca8 commit 13984d0

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

pkg/oc/cli/cmd/newapp_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,19 @@ func TestNewAppRunFailure(t *testing.T) {
205205
},
206206
expectedErr: "--search can't be used with --param",
207207
},
208+
"search_without_argument": {
209+
config: &newcmd.AppConfig{
210+
AsSearch: true,
211+
ComponentInputs: newcmd.ComponentInputs{
212+
DockerImages: []string{""},
213+
},
214+
},
215+
expectedErr: "no matches found",
216+
},
217+
"without_args": {
218+
config: &newcmd.AppConfig{},
219+
expectedErr: "You must specify one or more images, image streams, templates, or source code locations to create an application.",
220+
},
208221
}
209222

210223
opts := &NewAppOptions{
@@ -318,6 +331,42 @@ func TestNewAppRunQueryActions(t *testing.T) {
318331
expectedDockerVisited: true,
319332
expectedTemplateFilesVisited: true,
320333
},
334+
{
335+
name: "search template failure",
336+
config: &newcmd.AppConfig{
337+
AsSearch: true,
338+
ComponentInputs: newcmd.ComponentInputs{
339+
Templates: []string{"non-exist-template"},
340+
},
341+
},
342+
expectedActions: []testAction{
343+
{namespace: "openshift", verb: "list", resource: "templates"},
344+
},
345+
346+
expectedErr: "no matches found",
347+
},
348+
{
349+
name: "search imagestream failure",
350+
config: &newcmd.AppConfig{
351+
AsSearch: true,
352+
ComponentInputs: newcmd.ComponentInputs{
353+
ImageStreams: []string{"#@@#%*"},
354+
},
355+
},
356+
expectedErr: "no matches found",
357+
},
358+
{
359+
name: "search dockerimage failure",
360+
config: &newcmd.AppConfig{
361+
AsSearch: true,
362+
ComponentInputs: newcmd.ComponentInputs{
363+
DockerImages: []string{"fakerepo/non-exist-image"},
364+
},
365+
},
366+
expectedDockerVisited: true,
367+
expectedActions: []testAction{},
368+
expectedErr: "no matches found",
369+
},
321370
}
322371

323372
o := &NewAppOptions{
@@ -351,6 +400,13 @@ func TestNewAppRunQueryActions(t *testing.T) {
351400
return app.ComponentMatches{match}, []error{}
352401
},
353402
}
403+
o.Config.DockerSearcher = MockSearcher{
404+
OnSearch: func(precise bool, terms ...string) (app.ComponentMatches, []error) {
405+
dockerVisited = true
406+
return app.ComponentMatches{}, []error{}
407+
},
408+
}
409+
354410
o.Config.TemplateFileSearcher = MockSearcher{
355411
OnSearch: func(precise bool, terms ...string) (app.ComponentMatches, []error) {
356412
tfVisited = true

0 commit comments

Comments
 (0)