diff --git a/test/path_filtering.go b/test/path_filtering.go index 75d1384f0dd..ae0d28e1644 100644 --- a/test/path_filtering.go +++ b/test/path_filtering.go @@ -56,6 +56,8 @@ func getPathFilter(t *testing.T) (pathFilter, error) { f = stablePathFilter case "alpha": f = alphaPathFilter + case "beta": + f = betaPathFilter } if f == nil { return nil, fmt.Errorf("unable to create path filter from feature gate %q", enabledFeatureGate) @@ -90,11 +92,17 @@ func getFeatureGate(namespace string) (string, error) { // stablePathFilter returns true for any example that should be allowed to run // when "enable-api-fields" is "stable". func stablePathFilter(p string) bool { - return !(strings.Contains(p, "/alpha/") || strings.Contains(p, "/beta/")) + return !strings.Contains(p, "/alpha/") && !strings.Contains(p, "/beta/") } // alphaPathFilter returns true for any example that should be allowed to run // when "enable-api-fields" is "alpha". func alphaPathFilter(p string) bool { - return strings.Contains(p, "/alpha/") || strings.Contains(p, "/beta/") || stablePathFilter(p) + return true +} + +// betaPathFilter returns true for any example that should be allowed to run +// when "enable-api-fields" is "beta". +func betaPathFilter(p string) bool { + return !strings.Contains(p, "/alpha/") } diff --git a/test/path_filtering_test.go b/test/path_filtering_test.go index 000022272aa..abc7b51f0f7 100644 --- a/test/path_filtering_test.go +++ b/test/path_filtering_test.go @@ -103,3 +103,50 @@ func TestAlphaPathFilter(t *testing.T) { }) } } + +func TestBetaPathFilter(t *testing.T) { + for _, tc := range []struct { + path string + allowed bool + }{{ + path: "/test.yaml", + allowed: true, + }, { + path: "/alpha/test.yaml", + allowed: false, + }, { + path: "/beta/test.yaml", + allowed: true, + }, { + path: "/foo/test.yaml", + allowed: true, + }, { + path: "/v1alpha1/taskruns/test.yaml", + allowed: true, + }, { + path: "/v1alpha1/taskruns/alpha/test.yaml", + allowed: false, + }, { + path: "/v1beta1/taskruns/test.yaml", + allowed: true, + }, { + path: "/v1beta1/taskruns/alpha/test.yaml", + allowed: false, + }, { + path: "/v1beta1/taskruns/alpha/test.yaml", + allowed: false, + }, { + path: "/v1alpha1/pipelineruns/beta/test.yaml", + allowed: true, + }, { + path: "/v1alpha1/pipelineruns/beta/test.yaml", + allowed: true, + }} { + name := strings.Replace(tc.path, "/", " ", -1) + t.Run(name, func(t *testing.T) { + if got := betaPathFilter(tc.path); got != tc.allowed { + t.Errorf("path %q: want %t got %t", tc.path, tc.allowed, got) + } + }) + } +}