-
Notifications
You must be signed in to change notification settings - Fork 9
/
config_test.go
104 lines (87 loc) · 2.35 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
package main
import (
"io/ioutil"
"os"
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
func TestConfig(t *testing.T) {
suite.Run(t, new(ConfigTestSuite))
}
type ConfigTestSuite struct {
suite.Suite
tempfile *os.File
assert *require.Assertions
}
func (c *ConfigTestSuite) SetupTest() {
c.assert = require.New(c.T())
var err error
c.tempfile, err = ioutil.TempFile("", "config")
c.assert.NoError(err)
}
func (c *ConfigTestSuite) TearDownTest() {
os.Remove(c.tempfile.Name())
}
func (c *ConfigTestSuite) WriteTemp(content string) {
_, err := c.tempfile.Write([]byte(content))
c.assert.NoError(err)
ReadConfig(c.tempfile.Name())
err = c.tempfile.Close()
c.assert.NoError(err)
}
var validConfig = `
redis:
host: "localhost:9000"
namespace: "test"
queue: "background"
aws:
access_key: "super"
secret_key: "secret"
region: "us_best"
queue:
name: "myapp_queue"
topics:
foo_topic: "FooWorker"
bar_topic: "BazWorker"`
func (c *ConfigTestSuite) TestConfig_Valid() {
c.WriteTemp(validConfig)
config, err := ReadConfig(c.tempfile.Name())
c.assert.NoError(err)
// More to convince myself that the yaml package works than anything
c.assert.Equal(config.Redis.Host, "localhost:9000")
c.assert.Equal(config.Redis.Queue, "background")
c.assert.Equal(config.Redis.Password, "")
c.assert.Equal(config.AWS.Region, "us_best")
c.assert.Equal(config.Queue.Name, "myapp_queue")
c.assert.Equal(config.Queue.Topics["foo_topic"], "FooWorker")
}
var sparseConfig = `
redis:
host: "localhost:9000"
aws:
access_key: "super"
secret_key: "secret"
region: "us_best"`
// It's ok for stuff to be missing, we'll check that elsewhere
func (c *ConfigTestSuite) TestConfig_Sparse() {
c.WriteTemp(sparseConfig)
config, err := ReadConfig(c.tempfile.Name())
c.assert.NoError(err)
c.assert.Equal(config.Redis.Namespace, "")
c.assert.Equal(config.AWS.Region, "us_best")
c.assert.Equal(len(config.Queue.Topics), 0)
}
var redisAuthConfig = `
redis:
host: localhost:9000
password: jsdf3-402341234
`
// It's ok for stuff to be missing, we'll check that elsewhere
func (c *ConfigTestSuite) TestConfig_RedisPass() {
c.WriteTemp(redisAuthConfig)
config, err := ReadConfig(c.tempfile.Name())
c.assert.NoError(err)
c.assert.Equal(config.Redis.Password, "jsdf3-402341234")
c.assert.Equal(config.Redis.Host, "localhost:9000")
}