-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Last minute fixups from review feedback on "enable-api-fields" PR
In #3881 we added the new "enable-api-fields" feature gate and some related helpers. There were a couple of comments I missed before the PR got merged so adding them here instead. This commit adds tests for the bits of "test/path_filtering.go" that can be checked without a cluster running Tekton Pipelines.
- Loading branch information
1 parent
06ae777
commit b4943e8
Showing
3 changed files
with
121 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// +build examples | ||
|
||
/* | ||
Copyright 2021 The Tekton Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestStablePathFilter(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: false, | ||
}, { | ||
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: false, | ||
}, { | ||
path: "/v1alpha1/pipelineruns/beta/test.yaml", | ||
allowed: false, | ||
}} { | ||
name := strings.Replace(tc.path, "/", " ", -1) | ||
t.Run(name, func(t *testing.T) { | ||
if got := stablePathFilter(tc.path); got != tc.allowed { | ||
t.Errorf("path %q: want %t got %t", tc.path, tc.allowed, got) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestAlphaPathFilter(t *testing.T) { | ||
for _, tc := range []struct { | ||
path string | ||
}{{ | ||
path: "/test.yaml", | ||
}, { | ||
path: "/alpha/test.yaml", | ||
}, { | ||
path: "/foo/test.yaml", | ||
}, { | ||
path: "/v1alpha1/taskruns/test.yaml", | ||
}, { | ||
path: "/v1alpha1/taskruns/alpha/test.yaml", | ||
}, { | ||
path: "/v1beta1/taskruns/test.yaml", | ||
}, { | ||
path: "/v1beta1/taskruns/alpha/test.yaml", | ||
}, { | ||
path: "/v1beta1/taskruns/alpha/test.yaml", | ||
}, { | ||
path: "/v1alpha1/pipelineruns/beta/test.yaml", | ||
}, { | ||
path: "/v1alpha1/pipelineruns/beta/test.yaml", | ||
}} { | ||
name := strings.Replace(tc.path, "/", " ", -1) | ||
t.Run(name, func(t *testing.T) { | ||
if got := alphaPathFilter(tc.path); got != true { | ||
t.Errorf("path %q: want %t got %t", tc.path, true, got) | ||
} | ||
}) | ||
} | ||
} |