feat: Serving CRD in ks apiserver

Signed-off-by: Roland.Ma <rolandma@kubesphere.io>
This commit is contained in:
Roland.Ma
2022-01-13 06:27:16 +00:00
parent 365924e76b
commit 0ec32f29fb
7 changed files with 948 additions and 14 deletions

View File

@@ -0,0 +1,85 @@
/*
Copyright 2022 The KubeSphere 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 crds
import "testing"
func TestLabelMatch(t *testing.T) {
tests := []struct {
labels map[string]string
filter string
expectResult bool
}{
{
labels: map[string]string{
"kubesphere.io/workspace": "kubesphere-system",
},
filter: "kubesphere.io/workspace",
expectResult: true,
},
{
labels: map[string]string{
"kubesphere.io/creator": "system",
},
filter: "kubesphere.io/workspace",
expectResult: false,
},
{
labels: map[string]string{
"kubesphere.io/workspace": "kubesphere-system",
},
filter: "kubesphere.io/workspace=",
expectResult: false,
},
{
labels: map[string]string{
"kubesphere.io/workspace": "kubesphere-system",
},
filter: "kubesphere.io/workspace!=",
expectResult: true,
},
{
labels: map[string]string{
"kubesphere.io/workspace": "kubesphere-system",
},
filter: "kubesphere.io/workspace!=kubesphere-system",
expectResult: false,
},
{
labels: map[string]string{
"kubesphere.io/workspace": "kubesphere-system",
},
filter: "kubesphere.io/workspace=kubesphere-system",
expectResult: true,
},
{
labels: map[string]string{
"kubesphere.io/workspace": "kubesphere-system",
},
filter: "kubesphere.io/workspace=system",
expectResult: false,
},
}
for i, test := range tests {
result := labelMatch(test.labels, test.filter)
if result != test.expectResult {
t.Errorf("case %d, got %#v, expected %#v", i, result, test.expectResult)
}
}
}