86 lines
2.1 KiB
Go
86 lines
2.1 KiB
Go
/*
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|