-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
65 lines (52 loc) · 1.75 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
package assets
import (
"os/exec"
"path"
"strings"
"testing"
"src.goblgobl.com/tests/assert"
)
var testConfig config
func init() {
if err := Configure(testConfigPath("minimal.json")); err != nil {
panic(err)
}
testConfig = Config
}
func Test_Config_InvalidPath(t *testing.T) {
defer func() { Config = testConfig }()
err := Configure("invalid.json")
assert.Equal(t, err.Error(), "code: 203001 - open invalid.json: no such file or directory")
}
func Test_Config_InvalidJson(t *testing.T) {
defer func() { Config = testConfig }()
err := Configure(testConfigPath("invalid.json"))
assert.Equal(t, err.Error(), "code: 203002 - expected colon after object key")
}
func Test_Config_Upstream_Base(t *testing.T) {
defer func() { Config = testConfig }()
err := Configure(testConfigPath("upstream_base.json"))
assert.Equal(t, err.Error(), "code: 203004 - upstream must have a base_url")
}
func Test_Config_Minimal(t *testing.T) {
defer func() { Config = testConfig }()
err := Configure(testConfigPath("minimal.json"))
assert.Nil(t, err)
expectedPath, _ := exec.LookPath("vipsthumbnail")
assert.True(t, expectedPath != "") // sanity
assert.Equal(t, Config.VipsThumbnail, expectedPath)
assert.True(t, strings.HasPrefix(Config.VipsVersion, "libvips "))
assert.Equal(t, len(Config.Upstreams), 1)
up1 := Config.Upstreams["test"]
assert.Equal(t, up1.BaseURL, "http://localhost:5400/x1")
assert.Equal(t, len(up1.Caching), 3)
assert.Equal(t, up1.Caching[0].Status, 0)
assert.Equal(t, up1.Caching[0].TTL, 300)
assert.Equal(t, up1.Caching[1].Status, 404)
assert.Equal(t, up1.Caching[1].TTL, -60)
assert.Equal(t, up1.Caching[2].Status, 200)
assert.Equal(t, up1.Caching[2].TTL, 3600)
}
func testConfigPath(file string) string {
return path.Join("tests/configs/", file)
}