diff --git a/engine/resource/lookup.go b/engine/resource/lookup.go index 75ad4b8..d4e1f8c 100644 --- a/engine/resource/lookup.go +++ b/engine/resource/lookup.go @@ -13,7 +13,7 @@ import ( // Lookup returns the named pipeline from the Manifest. func Lookup(name string, manifest *manifest.Manifest) (*Pipeline, error) { for _, resource := range manifest.Resources { - if resource.GetName() != name { + if !isNameMatch(resource.GetName(), name) { continue } if pipeline, ok := resource.(*Pipeline); ok { @@ -22,3 +22,8 @@ func Lookup(name string, manifest *manifest.Manifest) (*Pipeline, error) { } return nil, errors.New("resource not found") } + +// helper function returns true if the name matches. +func isNameMatch(a, b string) bool { + return a == b || (a == "" && b == "default") +} diff --git a/engine/resource/lookup_test.go b/engine/resource/lookup_test.go index 894278a..861d373 100644 --- a/engine/resource/lookup_test.go +++ b/engine/resource/lookup_test.go @@ -43,3 +43,20 @@ func TestLookupNotFound(t *testing.T) { t.Errorf("Expect resource not found error") } } + +func TestNameMatch(t *testing.T) { + tests := []struct { + a, b string + match bool + }{ + {"a", "b", false}, + {"a", "a", true}, + {"", "default", true}, + } + for _, test := range tests { + got, want := isNameMatch(test.a, test.b), test.match + if got != want { + t.Errorf("Expect %q and %q match is %v", test.a, test.b, want) + } + } +}