forked from kyma-project/cp-mod-migrator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cp_mod_migration_utilz_test.go
145 lines (125 loc) · 2.95 KB
/
cp_mod_migration_utilz_test.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package main_test
import (
"errors"
"io"
"os"
"testing"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/mock"
v211 "github.tools.sap/framefrog/cp-mod-migrator/pkg/cproxy/api/v211"
"github.tools.sap/framefrog/cp-mod-migrator/pkg/extract"
"github.tools.sap/framefrog/cp-mod-migrator/pkg/mocks"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/yaml"
)
func readYaml[T any](name string, out T) {
file, err := os.Open(name)
if err != nil {
Expect(err).ShouldNot(HaveOccurred())
}
decoder := yaml.NewYAMLOrJSONDecoder(file, 2048)
Expect(decoder.Decode(&out)).ShouldNot(HaveOccurred())
}
func namespace(name string) corev1.Namespace {
return corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
}
}
func cp(name, namespace string, migrated bool) v211.ConnectivityProxy {
annotations := map[string]string{}
if migrated {
annotations[v211.CProxyMigratedAnnotation] = "true"
}
return v211.ConnectivityProxy{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Annotations: annotations,
},
Spec: v211.Spec{
Config: v211.Config{
HighAvailabilityMode: v211.HighAvailabilityModeOff,
Integration: v211.Integration{
AuditLog: v211.AuditLog{
Mode: v211.AuditLogModeConsole,
},
ConnectivityService: &v211.ConnectivityService{
ServiceCredentialsKey: "test",
},
},
Servers: v211.Servers{
BusinessDataTunnel: v211.BusinessDataTunnel{
ExternalHost: "test",
ExternalPort: 20,
},
Proxy: v211.Proxy{
HTTP: v211.ProxyCfg{
Port: 123,
},
RfcAndLdap: v211.ProxyCfg{
Port: 123,
},
Socks5: v211.ProxyCfg{
Port: 123,
},
},
},
ConnectivityService: v211.ConnectivityService{
ServiceCredentialsKey: "test",
},
SubaccountID: "test-me-plz",
TenantMode: v211.TenantModeDedicated,
},
Ingress: v211.Ingress{
ClassName: v211.ClassTypeIstio,
},
SecretConfig: v211.SecretConfig{
Integration: v211.SecretConfigIntegration{
ConnectivityService: v211.ServiceSecretConfig{
SecretName: "test",
},
},
},
},
}
}
func loadCMs(data *[]corev1.ConfigMap) error {
file, err := os.Open("./hack/testdata/configmaps.yaml")
if err != nil {
return err
}
decoder := yaml.NewYAMLOrJSONDecoder(file, 2048)
var cm corev1.ConfigMap
for {
err := decoder.Decode(&cm)
if errors.Is(err, io.EOF) {
break
}
if err != nil {
return err
}
*data = append(*data, cm)
}
return nil
}
func newClient(t *testing.T, cms []corev1.ConfigMap) extract.Client {
var index int
runFn := func(args mock.Arguments) {
cm := args.Get(2).(*corev1.ConfigMap)
*cm = cms[index]
if index == len(cms)-1 {
index = 0
return
}
index++
}
client := mocks.NewClient(t)
client.On("Get", mock.Anything, mock.Anything, mock.Anything).
Run(runFn).
Return(nil).
Times(len(cms))
return client
}