-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathconfig_test.go
More file actions
71 lines (63 loc) · 1.54 KB
/
config_test.go
File metadata and controls
71 lines (63 loc) · 1.54 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
package cloudprovider
import (
"io"
"os"
"reflect"
"testing"
"github.com/openkruise/kruise-game/cloudprovider/options"
)
func TestParse(t *testing.T) {
tests := []struct {
fileString string
kubernetes options.KubernetesOptions
alibabacloud options.AlibabaCloudOptions
}{
{
fileString: `
[kubernetes]
enable = true
[kubernetes.hostPort]
max_port = 9000
min_port = 8000
[alibabacloud]
enable = true
`,
kubernetes: options.KubernetesOptions{
Enable: true,
HostPort: options.HostPortOptions{
MaxPort: 9000,
MinPort: 8000,
},
},
alibabacloud: options.AlibabaCloudOptions{
Enable: true,
},
},
}
for _, test := range tests {
tempFile := "config"
file, err := os.Create(tempFile)
if err != nil {
t.Errorf("open file failed, because of %s", err.Error())
}
_, err = io.WriteString(file, test.fileString)
if err != nil {
t.Errorf("write file failed, because of %s", err.Error())
}
err = file.Close()
if err != nil {
t.Errorf("close file failed, because of %s", err.Error())
}
cf := ConfigFile{
Path: tempFile,
}
cloudProviderConfig := cf.Parse()
if !reflect.DeepEqual(cloudProviderConfig.AlibabaCloudOptions, test.alibabacloud) {
t.Errorf("expect AlibabaCloudOptions: %v, but got %v", test.alibabacloud, cloudProviderConfig.AlibabaCloudOptions)
}
if !reflect.DeepEqual(cloudProviderConfig.KubernetesOptions, test.kubernetes) {
t.Errorf("expect KubernetesOptions: %v, but got %v", test.kubernetes, cloudProviderConfig.KubernetesOptions)
}
os.Remove(tempFile)
}
}