/
helper.go
49 lines (44 loc) · 1.26 KB
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0
package envtestutils
import (
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
controllerruntime "sigs.k8s.io/controller-runtime"
)
var log = controllerruntime.Log.WithName("test-env")
// mergePaths merges two string slices containing paths.
// This function makes no guarantees about order of the merged slice.
func mergePaths(s1, s2 []string) []string {
m := make(map[string]struct{})
for _, s := range s1 {
m[s] = struct{}{}
}
for _, s := range s2 {
m[s] = struct{}{}
}
merged := make([]string, len(m))
i := 0
for key := range m {
merged[i] = key
i++
}
return merged
}
// mergeAPIServices merges two APIService slices using their names.
// This function makes no guarantees about order of the merged slice.
func mergeAPIServices(s1, s2 []*apiregistrationv1.APIService) []*apiregistrationv1.APIService {
m := make(map[string]*apiregistrationv1.APIService)
for _, obj := range s1 {
m[obj.GetName()] = obj
}
for _, obj := range s2 {
m[obj.GetName()] = obj
}
merged := make([]*apiregistrationv1.APIService, len(m))
i := 0
for _, obj := range m {
merged[i] = obj.DeepCopy()
i++
}
return merged
}