-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathconfig_test.go
85 lines (81 loc) · 1.68 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
package main_test
import (
"bytes"
"flag"
"fmt"
"testing"
"github.com/codegangsta/cli"
"github.com/corvus-ch/rabbitmq-cli-consumer"
"github.com/stretchr/testify/assert"
)
var loadConfigurationTest = []struct {
name string
flags func(set *flag.FlagSet)
err error
url string
queue string
}{
{
"default",
func(set *flag.FlagSet) {
set.String("configuration", "fixtures/default.conf", "")
},
nil,
"",
"test",
},
{
"missingFlags",
func(set *flag.FlagSet) {},
cli.NewExitError("", 1),
"",
"",
},
{
"missingFile",
func(set *flag.FlagSet) {
set.String("configuration", "/does/not/exits.conf", "")
},
fmt.Errorf("failed parsing configuration: open /does/not/exits.conf: no such file or directory"),
"",
"",
},
{
"url",
func(set *flag.FlagSet) {
set.String("configuration", "fixtures/default.conf", "")
set.String("url", "amqp://amqp.example.com:1234", "")
},
nil,
"amqp://amqp.example.com:1234",
"test",
},
{
"queue",
func(set *flag.FlagSet) {
set.String("configuration", "fixtures/default.conf", "")
set.String("queue-name", "someOtherQueue", "")
},
nil,
"",
"someOtherQueue",
},
}
func TestLoadConfiguration(t *testing.T) {
app := main.NewApp()
app.Writer = &bytes.Buffer{}
for _, test := range loadConfigurationTest {
t.Run(test.name, func(t *testing.T) {
set := flag.NewFlagSet(t.Name(), flag.ContinueOnError)
test.flags(set)
c := cli.NewContext(app, set, nil)
cfg, err := main.LoadConfiguration(c)
assert.Equal(t, err, test.err)
if test.err == nil {
assert.NotNil(t, cfg)
assert.Equal(t, cfg.RabbitMq.AmqpUrl, test.url)
assert.Equal(t, cfg.RabbitMq.Queue, test.queue)
}
})
}
}