Skip to content

Commit

Permalink
modify existing test, check multiple types of reference in import cycle
Browse files Browse the repository at this point in the history
Signed-off-by: Stephanie <yangcao@redhat.com>
  • Loading branch information
yangcao77 committed Apr 9, 2021
1 parent aa85a4a commit 981f87d
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions pkg/devfile/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2188,7 +2188,7 @@ func Test_parseParentAndPluginFromURI(t *testing.T) {
}
}

func Test_parseParentAndPlugin_RecursivelyReference_withMultipleURI(t *testing.T) {
func Test_parseParentAndPlugin_RecursivelyReference(t *testing.T) {
const uri1 = "127.0.0.1:8080"
const uri2 = "127.0.0.1:9090"
const uri3 = "127.0.0.1:8090"
Expand Down Expand Up @@ -2266,26 +2266,20 @@ func Test_parseParentAndPlugin_RecursivelyReference_withMultipleURI(t *testing.T
SchemaVersion: schemaV200,
},
DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{
DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{
Components: []v1.Component{
{
Name: "plugin",
ComponentUnion: v1.ComponentUnion{
Plugin: &v1.PluginComponent{
ImportReference: v1.ImportReference{
ImportReferenceUnion: v1.ImportReferenceUnion{
Uri: httpPrefix + uri3,
},
},
},
},
Parent: &v1.Parent{
ImportReference: v1.ImportReference{
ImportReferenceUnion: v1.ImportReferenceUnion{
Id: "nodejs",
},
RegistryUrl: httpPrefix + uri3,
},
},
DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{},
},
},
},
}

parentDevfile3 := DevfileObj{
Ctx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath),
Data: &v2.DevfileV2{
Expand Down Expand Up @@ -2369,7 +2363,13 @@ func Test_parseParentAndPlugin_RecursivelyReference_withMultipleURI(t *testing.T
defer testServer2.Close()

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

testServer3.Start()
defer testServer3.Close()
t.Run("it should error out if URI is recursively referenced with multiple references", func(t *testing.T) {

t.Run("it should error out if import reference has a cycle", func(t *testing.T) {
err := parseParentAndPlugin(devFileObj, &resolutionContextTree{}, resolverTools{})
// 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
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,
// 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
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,
httpPrefix, uri2, httpPrefix, uri3, httpPrefix, uri1)
// Unexpected error
if err == nil || !reflect.DeepEqual(expectedErr, err.Error()) {
t.Errorf("Test_parseParentAndPlugin_RecursivelyReference_withMultipleURI() unexpected error = %v", err)
t.Errorf("Test_parseParentAndPlugin_RecursivelyReference unexpected error = %v", err)
return
}

Expand Down

0 comments on commit 981f87d

Please sign in to comment.