-
Notifications
You must be signed in to change notification settings - Fork 362
/
openshift-copies_test.go
106 lines (92 loc) · 2.96 KB
/
openshift-copies_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
package openshift
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const fixtureKubeConfigPath = "testdata/admin.kubeconfig"
// These are only smoke tests based on the skopeo integration test cluster. Error handling, non-trivial configuration merging,
// and any other situations are not currently covered.
// Set up KUBECONFIG to point at the fixture.
// Callers MUST NOT call testing.T.Parallel().
func setupKubeConfigForSerialTest(t *testing.T) {
t.Setenv("KUBECONFIG", fixtureKubeConfigPath)
}
func TestClientConfigLoadingRules(t *testing.T) {
setupKubeConfigForSerialTest(t)
rules := newOpenShiftClientConfigLoadingRules()
res, err := rules.Load()
require.NoError(t, err)
expected := clientcmdConfig{
Clusters: clustersMap{
"172-17-0-2:8443": &clientcmdCluster{
LocationOfOrigin: fixtureKubeConfigPath,
Server: "https://172.17.0.2:8443",
CertificateAuthorityData: []byte("Cluster CA"),
},
},
AuthInfos: authInfosMap{
"system:admin/172-17-0-2:8443": &clientcmdAuthInfo{
LocationOfOrigin: fixtureKubeConfigPath,
ClientCertificateData: []byte("Client cert"),
ClientKeyData: []byte("Client key"),
},
},
Contexts: contextsMap{
"default/172-17-0-2:8443/system:admin": &clientcmdContext{
LocationOfOrigin: fixtureKubeConfigPath,
Cluster: "172-17-0-2:8443",
AuthInfo: "system:admin/172-17-0-2:8443",
Namespace: "default",
},
},
CurrentContext: "default/172-17-0-2:8443/system:admin",
}
assert.Equal(t, &expected, res)
}
func TestDirectClientConfig(t *testing.T) {
setupKubeConfigForSerialTest(t)
rules := newOpenShiftClientConfigLoadingRules()
config, err := rules.Load()
require.NoError(t, err)
direct := newNonInteractiveClientConfig(*config)
res, err := direct.ClientConfig()
require.NoError(t, err)
assert.Equal(t, &restConfig{
Host: "https://172.17.0.2:8443",
TLSClientConfig: restTLSClientConfig{
CertData: []byte("Client cert"),
KeyData: []byte("Client key"),
CAData: []byte("Cluster CA"),
},
}, res)
}
func TestDeferredLoadingClientConfig(t *testing.T) {
setupKubeConfigForSerialTest(t)
rules := newOpenShiftClientConfigLoadingRules()
deferred := newNonInteractiveDeferredLoadingClientConfig(rules)
res, err := deferred.ClientConfig()
require.NoError(t, err)
assert.Equal(t, &restConfig{
Host: "https://172.17.0.2:8443",
TLSClientConfig: restTLSClientConfig{
CertData: []byte("Client cert"),
KeyData: []byte("Client key"),
CAData: []byte("Cluster CA"),
},
}, res)
}
func TestDefaultClientConfig(t *testing.T) {
setupKubeConfigForSerialTest(t)
config := defaultClientConfig()
res, err := config.ClientConfig()
require.NoError(t, err)
assert.Equal(t, &restConfig{
Host: "https://172.17.0.2:8443",
TLSClientConfig: restTLSClientConfig{
CertData: []byte("Client cert"),
KeyData: []byte("Client key"),
CAData: []byte("Cluster CA"),
},
}, res)
}