forked from jsternberg/ansible-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
47 lines (38 loc) · 1.07 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
package main
import (
"testing"
"github.com/BurntSushi/toml"
"github.com/stretchr/testify/assert"
)
const TestConfig = `
[ssl]
enabled = true
certificate = "/etc/ansible/server.cert"
private_key = "/etc/ansible/server.key"
[ldap]
enabled = true
host = "ldaps://example.com"
port = 636
base_dn = "dc=example,dc=com"
user_filter = "(uid=%s)"
`
func TestDefaultConfig(t *testing.T) {
assert := assert.New(t)
config := DefaultConfig()
assert.False(config.SSL.Enabled)
assert.False(config.Ldap.Enabled)
}
func TestConfigLoad(t *testing.T) {
assert := assert.New(t)
config := DefaultConfig()
if err := toml.Unmarshal([]byte(TestConfig), config); assert.NoError(err) {
assert.True(config.SSL.Enabled)
assert.Equal("/etc/ansible/server.cert", config.SSL.Certificate)
assert.Equal("/etc/ansible/server.key", config.SSL.PrivateKey)
assert.True(config.Ldap.Enabled)
assert.Equal("ldaps://example.com", config.Ldap.Host)
assert.Equal(uint16(636), config.Ldap.Port)
assert.Equal("dc=example,dc=com", config.Ldap.BaseDN)
assert.Equal("(uid=%s)", config.Ldap.UserFilter)
}
}