-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathconfig_test.go
155 lines (127 loc) · 3.9 KB
/
config_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
146
147
148
149
150
151
152
153
154
155
/*
* Copyright 2021 The Gort Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package config
import (
"os"
"testing"
"time"
"github.com/getgort/gort/data"
"github.com/stretchr/testify/assert"
)
func TestLoad(t *testing.T) {
config, err := load("../testing/config/complete.yml")
if err != nil {
t.Error(err.Error())
t.FailNow()
}
cglobal := config.GlobalConfigs
assert.NotNil(t, cglobal)
assert.Equal(t, time.Minute, cglobal.CommandTimeout)
cgort := config.GortServerConfigs
assert.NotNil(t, cgort)
assert.Equal(t, true, cgort.AllowSelfRegistration)
assert.Equal(t, ":4000", cgort.APIAddress)
assert.Equal(t, "localhost", cgort.APIURLBase)
assert.Equal(t, true, cgort.DevelopmentMode)
assert.Equal(t, true, cgort.EnableSpokenCommands)
cdb := config.DatabaseConfigs
assert.NotNil(t, cdb)
assert.Equal(t, "localhost", cdb.Host)
assert.Equal(t, 5432, cdb.Port)
assert.Equal(t, "gort", cdb.User)
assert.Equal(t, "veryKleverPassw0rd!", cdb.Password)
assert.Equal(t, true, cdb.SSLEnabled)
assert.Equal(t, 30*time.Second, cdb.ConnectionMaxIdleTime)
assert.Equal(t, 5*time.Minute, cdb.ConnectionMaxLifetime)
assert.Equal(t, 2, cdb.MaxIdleConnections)
assert.Equal(t, 4, cdb.MaxOpenConnections)
cd := config.DockerConfigs
assert.NotNil(t, cd)
assert.Equal(t, "unix:///var/run/docker.sock", cd.DockerHost)
cs := config.SlackProviders
assert.NotNil(t, cs)
assert.NotEmpty(t, cs)
assert.Equal(t, "MyWorkspace", cs[0].Name)
assert.Equal(t, "xoxb-210987654321-123456789012-nyWJ3U4JoWuUtaUkRPKn0dJR", cs[0].APIToken)
assert.Equal(t, "https://emoji.slack-edge.com/T023V8ZFQEQ/gort/78a0c1607eeb1f29.png", cs[0].IconURL)
assert.Equal(t, "Gort", cs[0].BotName)
cj := config.JaegerConfigs
assert.NotNil(t, cj)
assert.NotEmpty(t, cj)
assert.Equal(t, cj.Endpoint, "http://localhost:14268/api/traces")
assert.Equal(t, cj.Username, "gort")
assert.Equal(t, cj.Password, "veryKleverPassw0rd!")
}
func TestUndefinedNil(t *testing.T) {
id := Undefined(nil)
assert.True(t, id)
}
func TestUndefinedFalse(t *testing.T) {
c, err := load("../testing/config/complete.yml")
if err != nil {
t.Error(err.Error())
t.FailNow()
}
id := Undefined(c)
assert.False(t, id)
}
func TestUndefinedTrue(t *testing.T) {
c := data.GortConfig{}
id := Undefined(c)
assert.True(t, id)
}
func TestUndefinedTrue2(t *testing.T) {
c, err := load("../testing/config/no-database.yml")
if err != nil {
t.Error(err.Error())
t.FailNow()
}
id := Undefined(c.DatabaseConfigs)
assert.True(t, id)
}
func TestStandardizeDatabaseConfigNone(t *testing.T) {
// Clear the password environment variable for repeated runs
err := os.Setenv(EnvDatabasePassword, "")
if err != nil {
t.Error(err.Error())
t.FailNow()
}
config, err := load("../testing/config/no-database-password.yml")
if err != nil {
t.Error(err.Error())
t.FailNow()
}
standardizeDatabaseConfig(&config.DatabaseConfigs)
dbp := config.DatabaseConfigs.Password
assert.Empty(t, dbp)
}
func TestStandardizeDatabaseConfigDefined(t *testing.T) {
const expected = "someRandomPassword"
err := os.Setenv(EnvDatabasePassword, expected)
if err != nil {
t.Error(err.Error())
t.FailNow()
}
config, err := load("../testing/config/no-database-password.yml")
if err != nil {
t.Error(err.Error())
t.FailNow()
}
standardizeDatabaseConfig(&config.DatabaseConfigs)
dbp := config.DatabaseConfigs.Password
assert.NotEmpty(t, dbp)
assert.Equal(t, dbp, expected)
}