Skip to content

Commit 981f87d

Browse files
committed
modify existing test, check multiple types of reference in import cycle
Signed-off-by: Stephanie <[email protected]>
1 parent aa85a4a commit 981f87d

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

pkg/devfile/parser/parse_test.go

+20-19
Original file line numberDiff line numberDiff line change
@@ -2188,7 +2188,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
21882188
}
21892189
}
21902190

2191-
func Test_parseParentAndPlugin_RecursivelyReference_withMultipleURI(t *testing.T) {
2191+
func Test_parseParentAndPlugin_RecursivelyReference(t *testing.T) {
21922192
const uri1 = "127.0.0.1:8080"
21932193
const uri2 = "127.0.0.1:9090"
21942194
const uri3 = "127.0.0.1:8090"
@@ -2266,26 +2266,20 @@ func Test_parseParentAndPlugin_RecursivelyReference_withMultipleURI(t *testing.T
22662266
SchemaVersion: schemaV200,
22672267
},
22682268
DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{
2269-
DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{
2270-
Components: []v1.Component{
2271-
{
2272-
Name: "plugin",
2273-
ComponentUnion: v1.ComponentUnion{
2274-
Plugin: &v1.PluginComponent{
2275-
ImportReference: v1.ImportReference{
2276-
ImportReferenceUnion: v1.ImportReferenceUnion{
2277-
Uri: httpPrefix + uri3,
2278-
},
2279-
},
2280-
},
2281-
},
2269+
Parent: &v1.Parent{
2270+
ImportReference: v1.ImportReference{
2271+
ImportReferenceUnion: v1.ImportReferenceUnion{
2272+
Id: "nodejs",
22822273
},
2274+
RegistryUrl: httpPrefix + uri3,
22832275
},
22842276
},
2277+
DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{},
22852278
},
22862279
},
22872280
},
22882281
}
2282+
22892283
parentDevfile3 := DevfileObj{
22902284
Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath),
22912285
Data: &v2.DevfileV2{
@@ -2369,7 +2363,13 @@ func Test_parseParentAndPlugin_RecursivelyReference_withMultipleURI(t *testing.T
23692363
defer testServer2.Close()
23702364

23712365
testServer3 := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2372-
data, err := yaml.Marshal(parentDevfile3.Data)
2366+
var data []byte
2367+
if strings.Contains(r.URL.Path, "/devfiles/nodejs") {
2368+
data, err = yaml.Marshal(parentDevfile3.Data)
2369+
} else {
2370+
w.WriteHeader(http.StatusNotFound)
2371+
return
2372+
}
23732373
if err != nil {
23742374
t.Errorf("unexpected error: %v", err)
23752375
}
@@ -2391,14 +2391,15 @@ func Test_parseParentAndPlugin_RecursivelyReference_withMultipleURI(t *testing.T
23912391

23922392
testServer3.Start()
23932393
defer testServer3.Close()
2394-
t.Run("it should error out if URI is recursively referenced with multiple references", func(t *testing.T) {
2394+
2395+
t.Run("it should error out if import reference has a cycle", func(t *testing.T) {
23952396
err := parseParentAndPlugin(devFileObj, &resolutionContextTree{}, resolverTools{})
2396-
// devfile has an cycle in references: main devfile -> uri: http://127.0.0.1:8080 -> uri: http://127.0.0.1:9090 -> uri: http://127.0.0.1:8090 -> uri: http://127.0.0.1:8080
2397-
expectedErr := fmt.Sprintf("devfile has an cycle in references: main devfile -> uri: %s%s -> uri: %s%s -> uri: %s%s -> uri: %s%s", httpPrefix, uri1,
2397+
// devfile has a cycle in references: main devfile -> uri: http://127.0.0.1:8080 -> uri: http://127.0.0.1:9090 -> id: nodejs, registryURL: http://127.0.0.1:8090 -> uri: http://127.0.0.1:8080
2398+
expectedErr := fmt.Sprintf("devfile has an cycle in references: main devfile -> uri: %s%s -> uri: %s%s -> id: nodejs, registryURL: %s%s -> uri: %s%s", httpPrefix, uri1,
23982399
httpPrefix, uri2, httpPrefix, uri3, httpPrefix, uri1)
23992400
// Unexpected error
24002401
if err == nil || !reflect.DeepEqual(expectedErr, err.Error()) {
2401-
t.Errorf("Test_parseParentAndPlugin_RecursivelyReference_withMultipleURI() unexpected error = %v", err)
2402+
t.Errorf("Test_parseParentAndPlugin_RecursivelyReference unexpected error = %v", err)
24022403
return
24032404
}
24042405

0 commit comments

Comments
 (0)