-
Notifications
You must be signed in to change notification settings - Fork 59
/
readconfig_test.go
126 lines (98 loc) · 3.08 KB
/
readconfig_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
package main
import (
"os"
"testing"
"time"
)
func Test_ReadConfig_IncorrectPortValue(t *testing.T) {
readConfig := ReadConfig{}
os.Setenv("faas_gateway_port", "8080a")
_, err := readConfig.Read()
want := "converting faas_gateway_port 8080a to int error: strconv.Atoi: parsing \"8080a\": invalid syntax"
if err.Error() != want {
t.Errorf("basicfaas_gateway_port want %q, got %q", want, err.Error())
}
}
func Test_ReadConfig(t *testing.T) {
readConfig := ReadConfig{}
os.Setenv("faas_nats_address", "test_nats")
os.Setenv("faas_nats_port", "1234")
os.Setenv("faas_nats_cluster_name", "example-nats-cluster")
os.Setenv("faas_nats_channel", "foo")
os.Setenv("faas_nats_queue_group", "bar")
os.Setenv("faas_gateway_address", "test_gatewayaddr")
os.Setenv("faas_gateway_port", "8080")
os.Setenv("faas_print_body", "true")
os.Setenv("write_debug", "true")
os.Setenv("max_inflight", "10")
os.Setenv("ack_wait", "10ms")
config, _ := readConfig.Read()
want := "test_nats"
if config.NatsAddress != want {
t.Logf("NatsAddress want `%s`, got `%s`\n", want, config.NatsAddress)
t.Fail()
}
wantNatsPort := 1234
if config.NatsPort != wantNatsPort {
t.Logf("NatsPort want `%d`, got `%d`\n", wantNatsPort, config.NatsPort)
t.Fail()
}
wantNatsClusterName := "example-nats-cluster"
if config.NatsClusterName != wantNatsClusterName {
t.Logf("NatsClusterName want `%s`, got `%s`\n", wantNatsClusterName, config.NatsClusterName)
t.Fail()
}
want = "test_gatewayaddr"
if config.GatewayAddress != want {
t.Logf("GatewayAddress want `%s`, got `%s`\n", want, config.GatewayAddress)
t.Fail()
}
wantGatewayPort := 8080
if config.GatewayPort != wantGatewayPort {
t.Logf("GatewayPort want `%d`, got `%d`\n", wantGatewayPort, config.GatewayPort)
t.Fail()
}
want = "test_gatewayaddr:8080"
if config.GatewayAddressURL() != want {
t.Logf("GatewayAddressURL want `%s`, got `%s`\n", want, config.GatewayAddressURL())
t.Fail()
}
if config.DebugPrintBody != true {
t.Logf("DebugPrintBody want `%v`, got `%v`\n", true, config.DebugPrintBody)
t.Fail()
}
if config.WriteDebug != true {
t.Logf("WriteDebug want `%v`, got `%v`\n", true, config.WriteDebug)
t.Fail()
}
wantAckWait := time.Millisecond * 10
if config.AckWait != wantAckWait {
t.Logf("maxInflight want `%v`, got `%v`\n", wantAckWait, config.AckWait)
t.Fail()
}
os.Unsetenv("max_inflight")
os.Unsetenv("ack_wait")
config, _ = readConfig.Read()
wantAckWait = time.Second * 30
if config.AckWait != wantAckWait {
t.Logf("maxInflight want `%v`, got `%v`\n", wantAckWait, config.AckWait)
t.Fail()
}
os.Setenv("max_inflight", "10.00")
os.Setenv("ack_wait", "10")
config, _ = readConfig.Read()
wantAckWait = time.Second * 30
if config.AckWait != wantAckWait {
t.Logf("ackWait want `%v`, got `%v`\n", wantAckWait, config.AckWait)
t.Fail()
}
}
func Test_ReadConfig_NatsQueueGroup(t *testing.T) {
readConfig := ReadConfig{}
os.Setenv("faas_nats_queue_group", "")
cfg, _ := readConfig.Read()
want := "faas"
if cfg.NatsQueueGroup != want {
t.Errorf("NatsQueueGroup want %v, got %v", want, cfg.NatsQueueGroup)
}
}