mirror of
https://github.com/kubevela/kubevela.git
synced 2026-05-07 09:57:17 +00:00
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
/*
|
|
Copyright 2021 The KubeVela 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 utils
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestFilterComponents(t *testing.T) {
|
|
testCases := map[string]struct {
|
|
Components []string
|
|
Selector []string
|
|
Output []string
|
|
}{
|
|
"normal": {
|
|
Components: []string{"comp1", "comp2", "comp3"},
|
|
Selector: []string{"comp1", "comp2"},
|
|
Output: []string{"comp1", "comp2"},
|
|
},
|
|
"selector-empty": {
|
|
Components: []string{"comp1", "comp2", "comp3"},
|
|
Selector: []string{},
|
|
Output: nil,
|
|
},
|
|
"selector-nil": {
|
|
Components: []string{"comp1", "comp2", "comp3"},
|
|
Selector: nil,
|
|
Output: []string{"comp1", "comp2", "comp3"},
|
|
},
|
|
}
|
|
for name, tt := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
r := require.New(t)
|
|
output := FilterComponents(tt.Components, tt.Selector)
|
|
r.Equal(tt.Output, output)
|
|
})
|
|
}
|
|
|
|
}
|