Skip to content

Commit

Permalink
Beta Example Tests
Browse files Browse the repository at this point in the history
This PR runs example tests of beta and stable features under the feature flag
`enable-api-fields: beta`. This is an extension to PR
#5737.
  • Loading branch information
chitrangpatel authored and tekton-robot committed Feb 27, 2023
1 parent efb7b12 commit 99d0746
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
12 changes: 10 additions & 2 deletions test/path_filtering.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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/")
}
47 changes: 47 additions & 0 deletions test/path_filtering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}

0 comments on commit 99d0746

Please sign in to comment.