forked from openshift/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudproviderconfig_test.go
More file actions
138 lines (125 loc) · 3.77 KB
/
cloudproviderconfig_test.go
File metadata and controls
138 lines (125 loc) · 3.77 KB
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
package openstack
import (
"context"
"testing"
"github.com/gophercloud/utils/v2/openstack/clientconfig"
"github.com/stretchr/testify/assert"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/openstack"
)
func TestCloudProviderConfigSecret(t *testing.T) {
cloud := clientconfig.Cloud{
AuthInfo: &clientconfig.AuthInfo{
Username: "my_user",
Password: "my_secret_password",
AuthURL: "https://my_auth_url.com/v3/",
ProjectID: "f12f928576ae4d21bdb984da5dd1d3bf",
DomainID: "default",
DomainName: "Default",
},
RegionName: "my_region",
}
expectedConfig := `[Global]
auth-url = "https://my_auth_url.com/v3/"
username = "my_user"
password = "my_secret_password"
tenant-id = "f12f928576ae4d21bdb984da5dd1d3bf"
domain-id = "default"
domain-name = "Default"
region = "my_region"
`
actualConfig, err := CloudProviderConfigSecret(&cloud)
assert.NoError(t, err, "failed to create cloud provider config")
assert.Equal(t, expectedConfig, string(actualConfig), "unexpected cloud provider config")
}
func TestCloudProviderConfigSecretUserDomain(t *testing.T) {
cloud := clientconfig.Cloud{
AuthInfo: &clientconfig.AuthInfo{
Username: "my_user",
Password: "my_secret_password",
AuthURL: "https://my_auth_url.com/v3/",
ProjectID: "f12f928576ae4d21bdb984da5dd1d3bf",
UserDomainID: "default",
UserDomainName: "Default",
},
RegionName: "my_region",
}
expectedConfig := `[Global]
auth-url = "https://my_auth_url.com/v3/"
username = "my_user"
password = "my_secret_password"
tenant-id = "f12f928576ae4d21bdb984da5dd1d3bf"
domain-id = "default"
domain-name = "Default"
region = "my_region"
`
actualConfig, err := CloudProviderConfigSecret(&cloud)
assert.NoError(t, err, "failed to create cloud provider config")
assert.Equal(t, expectedConfig, string(actualConfig), "unexpected cloud provider config")
}
func TestCloudProviderConfigSecretQuoting(t *testing.T) {
passwords := map[string]string{
"regular": "regular",
"with\\n": "with\\\\n",
"with#": "with#",
"with$": "with$",
"with;": "with;",
"with \n \" \\ ": "with \\n \\\" \\\\ ",
"with!": "with!",
"with?": "with?",
"with`": "with`",
}
for k, v := range passwords {
cloud := clientconfig.Cloud{
AuthInfo: &clientconfig.AuthInfo{
Password: k,
},
}
expectedConfig := `[Global]
password = "` + v + `"
`
actualConfig, err := CloudProviderConfigSecret(&cloud)
assert.NoError(t, err, "failed to create cloud provider config")
assert.Equal(t, expectedConfig, string(actualConfig), "unexpected cloud provider config")
}
}
func TestCloudProviderConfig(t *testing.T) {
cases := []struct {
name string
installConfig *types.InstallConfig
expectedConfig string
}{
{
name: "default install config",
installConfig: &types.InstallConfig{
Networking: &types.Networking{},
Platform: types.Platform{
OpenStack: &openstack.Platform{},
},
},
expectedConfig: `[Global]
secret-name = openstack-credentials
secret-namespace = kube-system
region = my_region
`,
},
}
cloud := clientconfig.Cloud{
AuthInfo: &clientconfig.AuthInfo{
Username: "my_user",
Password: "my_secret_password",
AuthURL: "https://my_auth_url.com/v3/",
ProjectID: "f12f928576ae4d21bdb984da5dd1d3bf",
DomainID: "default",
DomainName: "Default",
},
RegionName: "my_region",
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
actualConfig, _, err := generateCloudProviderConfig(context.Background(), nil, &cloud, nil, *tc.installConfig)
assert.NoError(t, err, "unexpected error when generating cloud provider config")
assert.Equal(t, tc.expectedConfig, actualConfig, "unexpected cloud provider config")
})
}
}