-
Notifications
You must be signed in to change notification settings - Fork 175
/
start_test.go
175 lines (143 loc) · 3.46 KB
/
start_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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package main
import (
"os"
"testing"
)
func TestParseConcurrencyFlagEmpty(t *testing.T) {
c, err := parseConcurrency("")
if err != nil {
t.Fatal(err)
}
if len(c) > 0 {
t.Fatal("expected no concurrency settings with ''")
}
}
func TestParseConcurrencyFlagSimle(t *testing.T) {
c, err := parseConcurrency("foo=2")
if err != nil {
t.Fatal(err)
}
if len(c) != 1 {
t.Fatal("expected 1 concurrency settings with 'foo=2'")
}
if c["foo"] != 2 {
t.Fatal("expected concurrency settings of 2 with 'foo=2'")
}
}
func TestParseConcurrencyFlagMultiple(t *testing.T) {
c, err := parseConcurrency("foo=2,bar=3")
if err != nil {
t.Fatal(err)
}
if len(c) != 2 {
t.Fatal("expected 1 concurrency settings with 'foo=2'")
}
if c["foo"] != 2 {
t.Fatal("expected concurrency settings of 2 with 'foo=2'")
}
if c["bar"] != 3 {
t.Fatal("expected concurrency settings of 3 with 'bar=3'")
}
}
func TestParseConcurrencyFlagNonInt(t *testing.T) {
_, err := parseConcurrency("foo=x")
if err == nil {
t.Fatal("foo=x should fail")
}
}
func TestParseConcurrencyFlagWhitespace(t *testing.T) {
c, err := parseConcurrency("foo = 2, bar = 3")
if err != nil {
t.Fatalf("foo = 2, bar = 4 should not fail:%s", err)
}
if len(c) != 2 {
t.Fatal("expected 1 concurrency settings with 'foo=2'")
}
if c["foo"] != 2 {
t.Fatal("expected concurrency settings of 2 with 'foo=2'")
}
if c["bar"] != 3 {
t.Fatal("expected concurrency settings of 3 with 'bar=3'")
}
}
func TestParseConcurrencyFlagMultipleEquals(t *testing.T) {
_, err := parseConcurrency("foo===2")
if err == nil {
t.Fatalf("foo===2 should fail: %s", err)
}
}
func TestParseConcurrencyFlagNoValue(t *testing.T) {
_, err := parseConcurrency("foo=")
if err == nil {
t.Fatalf("foo= should fail: %s", err)
}
_, err = parseConcurrency("=")
if err == nil {
t.Fatalf("= should fail: %s", err)
}
_, err = parseConcurrency("=1")
if err == nil {
t.Fatalf("= should fail: %s", err)
}
_, err = parseConcurrency(",")
if err == nil {
t.Fatalf(", should fail: %s", err)
}
_, err = parseConcurrency(",,,")
if err == nil {
t.Fatalf(",,, should fail: %s", err)
}
}
func TestPortFromEnv(t *testing.T) {
env := make(Env)
port, err := basePort(env)
if err != nil {
t.Fatalf("Can not get base port: %s", err)
}
if port != 5000 {
t.Fatal("Base port should be 5000")
}
os.Setenv("PORT", "4000")
port, err = basePort(env)
if err != nil {
t.Fatal("Can not get port: %s", err)
}
if port != 4000 {
t.Fatal("Base port should be 4000")
}
env["PORT"] = "6000"
port, err = basePort(env)
if err != nil {
t.Fatalf("Can not get base port: %s", err)
}
if port != 6000 {
t.Fatal("Base port should be 6000")
}
env["PORT"] = "forego"
port, err = basePort(env)
if err == nil {
t.Fatalf("Port 'forego' should fail: %s", err)
}
}
func TestConfigBeOverrideByForegoFile(t *testing.T) {
var procfile = "Profile"
var port = 5000
var concurrency string = "web=2"
var gracetime int = 3
err := readConfigFile("./fixtures/configs/.forego", &procfile, &port, &concurrency, &gracetime)
if err != nil {
t.Fatalf("Cannot set default values from forego config file")
}
if procfile != "Procfile.dev" {
t.Fatal("Procfile should be Procfile.dev")
}
if port != 15000 {
t.Fatal("port should be 15000, got %d", port)
}
if concurrency != "foo=2,bar=3" {
t.Fatal("concurrency should be 'foo=2,bar=3', got %s", concurrency)
}
if gracetime != 30 {
t.Fatal("gracetime should be 3, got %d", gracetime)
}
}