Skip to content

Commit d135abf

Browse files
committed
update comment
Signed-off-by: Stephanie <yangcao@redhat.com>
1 parent 7a3917b commit d135abf

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

pkg/devfile/parser/parse_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2395,7 +2395,7 @@ func Test_parseParentAndPlugin_RecursivelyReference(t *testing.T) {
23952395
}
23962396

23972397
err := parseParentAndPlugin(devFileObj, &resolutionContextTree{}, tool)
2398-
// 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+
// devfile has a cycle in references: main devfile -> uri: http://127.0.0.1:8080 -> name: testcrd, namespace: defaultnamespace -> id: nodejs, registryURL: http://127.0.0.1:8090 -> uri: http://127.0.0.1:8080
23992399
expectedErr := fmt.Sprintf("devfile has an cycle in references: main devfile -> uri: %s%s -> name: %s, namespace: %s -> id: nodejs, registryURL: %s%s -> uri: %s%s", httpPrefix, uri1, name, namespace,
24002400
httpPrefix, uri2, httpPrefix, uri1)
24012401
// Unexpected error

pkg/devfile/parser/resolutionContext.go

+8-11
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,24 @@ func (t *resolutionContextTree) appendNode(importReference v1.ImportReference) *
2727
func (t *resolutionContextTree) hasCycle() error {
2828
var seenRefs []v1.ImportReference
2929
currNode := t
30+
hasCycle := false
31+
cycle := resolveImportReference(t.importReference)
32+
3033
for currNode.parentNode != nil {
3134
for _, seenRef := range seenRefs {
3235
if reflect.DeepEqual(seenRef, currNode.importReference) {
33-
return fmt.Errorf("devfile has an cycle in references: %v", formatImportCycle(t))
36+
hasCycle = true
3437
}
3538
}
3639
seenRefs = append(seenRefs, currNode.importReference)
3740
currNode = currNode.parentNode
41+
cycle = fmt.Sprintf("%s -> %s", resolveImportReference(currNode.importReference), cycle)
3842
}
39-
return nil
40-
}
4143

42-
// formatImportCycle is a utility method for formatting a cycle that has been detected. Output is formatted as
43-
// {importReference1} -> {importReference2} -> {importReference3} -> {importReference1}, where {importReference1} are importReference detailed info
44-
func formatImportCycle(end *resolutionContextTree) string {
45-
cycle := resolveImportReference(end.importReference)
46-
for end.parentNode != nil {
47-
end = end.parentNode
48-
cycle = fmt.Sprintf("%s -> %s", resolveImportReference(end.importReference), cycle)
44+
if hasCycle {
45+
return fmt.Errorf("devfile has an cycle in references: %v", cycle)
4946
}
50-
return cycle
47+
return nil
5148
}
5249

5350
func resolveImportReference(importReference v1.ImportReference) string {

0 commit comments

Comments
 (0)