-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
118 lines (107 loc) · 3.23 KB
/
main_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
package main
import (
"testing"
"./types"
"github.com/stretchr/testify/assert"
)
func TestLoadConfigUnmarshallError(t *testing.T) {
err, yamlConf, azureConf := loadAndValidateYamlConfig([]byte(`
bad
`))
assert.Nil(t, yamlConf)
assert.Nil(t, azureConf)
assert.EqualError(t, err, "yaml: unmarshal errors:\n line 2: cannot unmarshal !!str `bad` into types.YamlConfig")
}
func TestLoadConfigOneWorkspaceError(t *testing.T) {
err, _, azureConf := loadAndValidateYamlConfig([]byte(`
hello: world
`))
assert.Nil(t, azureConf)
assert.EqualError(t, err, "must have at least one workspace, aborting")
}
func TestLoadConfigInvalidIdError(t *testing.T) {
err, _, azureConf := loadAndValidateYamlConfig([]byte(`
workspaces:
- id: two
`))
assert.Nil(t, azureConf)
assert.EqualError(t, err, "two is not a valid workspace ID")
}
func TestLoadConfigMissingIdError(t *testing.T) {
err, _, azureConf := loadAndValidateYamlConfig([]byte(`
workspaces:
- name: one
`))
assert.Nil(t, azureConf)
assert.EqualError(t, err, "missing id for workspace {Id: Name:one Secret:}")
}
func TestLoadConfigMissingSecretError(t *testing.T) {
err, _, azureConf := loadAndValidateYamlConfig([]byte(`
workspaces:
- id: 01234567-3ca5-4b65-8383-c12a5cda28b3
`))
assert.Nil(t, azureConf)
assert.EqualError(t, err, "missing secret for workspace 01234567-3ca5-4b65-8383-c12a5cda28b3")
}
func TestLoadConfigDupeIdError(t *testing.T) {
err, _, azureConf := loadAndValidateYamlConfig([]byte(`
workspaces:
- id: 01234567-3ca5-4b65-8383-c12a5cda28b3
name: one
secret: sssss
- id: 01234567-3ca5-4b65-8383-c12a5cda28b3
name: two
secret: sssss
`))
assert.Nil(t, azureConf)
assert.EqualError(t, err, "found duplicate workspace id (01234567-3ca5-4b65-8383-c12a5cda28b3)")
}
func TestLoadConfigDupeNameError(t *testing.T) {
err, _, azureConf := loadAndValidateYamlConfig([]byte(`
workspaces:
- id: 01234567-3ca5-4b65-8383-c12a5cda28b3
name: one
secret: sssss
- id: 51234567-3ca5-4b65-8383-c12a5cda28b4
name: one
secret: sssss
`))
assert.Nil(t, azureConf)
assert.EqualError(t, err, "found duplicate workspace name (one)")
}
func TestLoadConfigSuccess(t *testing.T) {
err, yamlConf, azureConf := loadAndValidateYamlConfig([]byte(`
listen_ip: 192.168.100.100 # defaults to 127.0.0.1 if not specified
listen_port: 50000 # defaults to 4000 if not specified
workspaces:
- id: 01234567-3ca5-4b65-8383-c12a5cda28b3
name: one
secret: "secret one"
# comments are ok in the config file
- id: 51234567-3ca5-4b65-8383-c12a5cda28b4
secret: "secret two"
`))
assert.Nil(t, err)
assert.NotNil(t, azureConf)
wks1 := &types.YamlWorkspace{
Id: "01234567-3ca5-4b65-8383-c12a5cda28b3",
Name: "one",
Secret: "secret one",
}
wks2 := &types.YamlWorkspace{
Id: "51234567-3ca5-4b65-8383-c12a5cda28b4",
Secret: "secret two",
}
expectedIdMap := make(map[string]*types.YamlWorkspace, 2)
expectedIdMap[wks1.Id] = wks1
expectedIdMap[wks2.Id] = wks2
expectedNameMap := make(map[string]*types.YamlWorkspace, 2)
expectedNameMap[wks1.Name] = wks1
expectedAzureConfig := &types.AzureMaps{
WksIdMap: expectedIdMap,
WksNameMap: expectedNameMap,
}
assert.Equal(t, expectedAzureConfig, azureConf)
assert.Equal(t, "192.168.100.100", yamlConf.ListenIP)
assert.Equal(t, uint16(50000), yamlConf.ListenPort)
}