Skip to content

Commit 61b2b7f

Browse files
committed
use []string for multiple error cases
Signed-off-by: Stephanie <yangcao@redhat.com>
1 parent 5526b14 commit 61b2b7f

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

pkg/devfile/parser/parse_test.go

+27-18
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
102102
pluginProjectAlreadyDefinedErr := "Some Projects are already defined in plugin.* If you want to override them, you should do it in the plugin scope."
103103
newCmdErr := "Some Commands do not override any existing element.* They should be defined in the main body, as new elements, not in the overriding section"
104104
newCmpErr := "Some Components do not override any existing element.* They should be defined in the main body, as new elements, not in the overriding section"
105+
newProjectErr := "Some Projects do not override any existing element.* They should be defined in the main body, as new elements, not in the overriding section"
105106
importCycleErr := "devfile has an cycle in references: main devfile -> .*"
106-
overrideInvalidErr := fmt.Sprintf(".*\n.*%s\n.*%s", newCmdErr, newCmpErr)
107107

108108
type args struct {
109109
devFileObj DevfileObj
@@ -115,7 +115,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
115115
pluginDevfile DevfileObj
116116
pluginOverride v1.PluginOverrides
117117
wantDevFile DevfileObj
118-
wantErr *string
118+
wantErr []string
119119
testRecursiveReference bool
120120
}{
121121
{
@@ -444,6 +444,12 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
444444
},
445445
},
446446
},
447+
Projects: []v1.ProjectParentOverride{
448+
{
449+
ClonePath: "/projects",
450+
Name: "nodejs-starter",
451+
},
452+
},
447453
},
448454
},
449455
},
@@ -461,6 +467,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
461467
DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{
462468
Commands: []v1.Command{},
463469
Components: []v1.Component{},
470+
Projects: []v1.Project{},
464471
},
465472
},
466473
},
@@ -469,7 +476,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
469476
wantDevFile: DevfileObj{
470477
Data: &v2.DevfileV2{},
471478
},
472-
wantErr: &overrideInvalidErr,
479+
wantErr: []string{newCmpErr, newCmdErr, newProjectErr},
473480
},
474481
{
475482
name: "error out if the same parent command is defined again in the local devfile",
@@ -522,7 +529,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
522529
wantDevFile: DevfileObj{
523530
Data: &v2.DevfileV2{},
524531
},
525-
wantErr: &parentCmdAlreadyDefinedErr,
532+
wantErr: []string{parentCmdAlreadyDefinedErr},
526533
},
527534
{
528535
name: "error out if the same parent component is defined again in the local devfile",
@@ -579,7 +586,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
579586
wantDevFile: DevfileObj{
580587
Data: &v2.DevfileV2{},
581588
},
582-
wantErr: &parentCmpAlreadyDefinedErr,
589+
wantErr: []string{parentCmpAlreadyDefinedErr},
583590
},
584591
{
585592
name: "should not have error if the same event is defined again in the local devfile",
@@ -699,7 +706,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
699706
wantDevFile: DevfileObj{
700707
Data: &v2.DevfileV2{},
701708
},
702-
wantErr: &parentProjectAlreadyDefinedErr,
709+
wantErr: []string{parentProjectAlreadyDefinedErr},
703710
},
704711
{
705712
name: "it should merge the plugin's uri data and add the local devfile's data",
@@ -1143,7 +1150,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
11431150
wantDevFile: DevfileObj{
11441151
Data: &v2.DevfileV2{},
11451152
},
1146-
wantErr: &newCmdErr,
1153+
wantErr: []string{newCmdErr},
11471154
},
11481155
{
11491156
name: "error out if the same plugin command is defined again in the local devfile",
@@ -1196,7 +1203,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
11961203
wantDevFile: DevfileObj{
11971204
Data: &v2.DevfileV2{},
11981205
},
1199-
wantErr: &pluginCmdAlreadyDefinedErr,
1206+
wantErr: []string{pluginCmdAlreadyDefinedErr},
12001207
},
12011208
{
12021209
name: "error out if the same plugin component is defined again in the local devfile",
@@ -1253,7 +1260,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
12531260
wantDevFile: DevfileObj{
12541261
Data: &v2.DevfileV2{},
12551262
},
1256-
wantErr: &pluginCmpAlreadyDefinedErr,
1263+
wantErr: []string{pluginCmpAlreadyDefinedErr},
12571264
},
12581265
{
12591266
name: "error out if the plugin project is defined again in the local devfile",
@@ -1316,7 +1323,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
13161323
wantDevFile: DevfileObj{
13171324
Data: &v2.DevfileV2{},
13181325
},
1319-
wantErr: &pluginProjectAlreadyDefinedErr,
1326+
wantErr: []string{pluginProjectAlreadyDefinedErr},
13201327
},
13211328
{
13221329
name: "error out if the same project is defined in the both plugin devfile and parent",
@@ -1407,7 +1414,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
14071414
wantDevFile: DevfileObj{
14081415
Data: &v2.DevfileV2{},
14091416
},
1410-
wantErr: &pluginProjectAlreadyDefinedErr,
1417+
wantErr: []string{pluginProjectAlreadyDefinedErr},
14111418
},
14121419
{
14131420
name: "error out if the same command is defined in both plugin devfile and parent devfile",
@@ -1483,7 +1490,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
14831490
wantDevFile: DevfileObj{
14841491
Data: &v2.DevfileV2{},
14851492
},
1486-
wantErr: &pluginCmdAlreadyDefinedErr,
1493+
wantErr: []string{pluginCmdAlreadyDefinedErr},
14871494
},
14881495
{
14891496
name: "error out if the same component is defined in both plugin devfile and parent devfile",
@@ -1565,7 +1572,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
15651572
wantDevFile: DevfileObj{
15661573
Data: &v2.DevfileV2{},
15671574
},
1568-
wantErr: &pluginCmpAlreadyDefinedErr,
1575+
wantErr: []string{pluginCmpAlreadyDefinedErr},
15691576
},
15701577
{
15711578
name: "it should override the requested parent's data and plugin's data, and add the local devfile's data",
@@ -1881,7 +1888,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
18811888
wantDevFile: DevfileObj{
18821889
Data: &v2.DevfileV2{},
18831890
},
1884-
wantErr: &pluginCmpAlreadyDefinedErr,
1891+
wantErr: []string{pluginCmpAlreadyDefinedErr},
18851892
},
18861893
{
18871894
name: "it should override with no errors if the plugin component is defined with a different component type in the plugin override",
@@ -2011,7 +2018,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
20112018
wantDevFile: DevfileObj{
20122019
Data: &v2.DevfileV2{},
20132020
},
2014-
wantErr: &parentCmpAlreadyDefinedErr,
2021+
wantErr: []string{parentCmpAlreadyDefinedErr},
20152022
},
20162023
{
20172024
name: "it should override with no errors if the parent component is defined with a different component type in the parent override",
@@ -2136,7 +2143,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
21362143
wantDevFile: DevfileObj{
21372144
Data: &v2.DevfileV2{},
21382145
},
2139-
wantErr: &importCycleErr,
2146+
wantErr: []string{importCycleErr},
21402147
testRecursiveReference: true,
21412148
},
21422149
}
@@ -2228,7 +2235,9 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
22282235
} else if err == nil && !reflect.DeepEqual(tt.args.devFileObj.Data, tt.wantDevFile.Data) {
22292236
t.Errorf("Test_parseParentAndPluginFromURI() error: wanted: %v, got: %v, difference at %v", tt.wantDevFile.Data, tt.args.devFileObj.Data, pretty.Compare(tt.args.devFileObj.Data, tt.wantDevFile.Data))
22302237
} else if err != nil {
2231-
assert.Regexp(t, *tt.wantErr, err.Error(), "Test_parseParentAndPluginFromURI(): Error message should match")
2238+
for _, wantErr := range tt.wantErr {
2239+
assert.Regexp(t, wantErr, err.Error(), "Test_parseParentAndPluginFromURI(): Error message should match")
2240+
}
22322241
}
22332242
})
22342243
}
@@ -3399,7 +3408,7 @@ func Test_parseFromRegistry(t *testing.T) {
33993408
invalidURLErr := "the provided registryURL: .* is not a valid URL"
34003409
URLNotFoundErr := "failed to retrieve .*, 404: Not Found"
34013410
missingRegistryURLErr := "failed to fetch from registry, registry URL is not provided"
3402-
invalidRegistryURLErr := "Get .* dial tcp: lookup http: no such host"
3411+
invalidRegistryURLErr := "Get .* dial tcp: lookup http: .*"
34033412

34043413
testServer := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
34053414
var data []byte

0 commit comments

Comments
 (0)