-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathconfig_test.go
75 lines (67 loc) · 1.85 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
package config
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func defaultConfig() *config {
return &config{
AwsRegion: "",
AwsAPIEndpoint: "",
S3Bucket: "",
S3KeyPrefix: "",
IndexDocument: "index.html",
DirectoryListing: false,
DirListingCheckIndex: false,
DirListingFormat: "",
HTTPCacheControl: "",
HTTPExpires: "",
BasicAuthUser: "",
BasicAuthPass: "",
Port: "80",
Host: "",
AccessLog: false,
SslCert: "",
SslKey: "",
StripPath: "",
ContentEncoding: true,
CorsAllowOrigin: "",
CorsAllowMethods: "",
CorsAllowHeaders: "",
CorsMaxAge: int64(600),
HealthCheckPath: "",
AllPagesInDir: false,
MaxIdleConns: 150,
IdleConnTimeout: time.Duration(10) * time.Second,
DisableCompression: true,
InsecureTLS: false,
}
}
func TestConfigDefaults(t *testing.T) {
expected := defaultConfig()
assert.Equal(t, expected, Config)
}
func TestChangeDefaults(t *testing.T) {
os.Setenv("DIRECTORY_LISTINGS", "1")
os.Setenv("ACCESS_LOG", "True")
os.Setenv("CONTENT_ENCODING", "f")
os.Setenv("CORS_MAX_AGE", "0")
os.Setenv("GET_ALL_PAGES_IN_DIR", "TRUE")
os.Setenv("MAX_IDLE_CONNECTIONS", "0")
os.Setenv("IDLE_CONNECTION_TIMEOUT", "60")
os.Setenv("DISABLE_COMPRESSION", "FALSE")
os.Setenv("INSECURE_TLS", "t")
Setup()
expected := defaultConfig()
expected.DirectoryListing = true
expected.AccessLog = true
expected.ContentEncoding = false
expected.CorsMaxAge = 0
expected.AllPagesInDir = true
expected.MaxIdleConns = 0
expected.IdleConnTimeout = time.Duration(60) * time.Second
expected.DisableCompression = false
expected.InsecureTLS = true
assert.Equal(t, expected, Config)
}