-
Notifications
You must be signed in to change notification settings - Fork 1
/
server_test.go
86 lines (68 loc) · 1.97 KB
/
server_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
package goserv
import (
"fmt"
"github.com/Sirupsen/logrus"
flag "github.com/ogier/pflag"
"os"
"testing"
"time"
)
// Configuration for testing
var TestConfig = BaseConfiguration{
"127.0.0.1",
8080,
10 * time.Second,
10 * time.Second,
1 << 20,
"debug",
"out.log",
0,
"",
"",
}
// Required for testing
func init() {
flag.StringP("test", "t", "", "")
flag.Parse()
}
// tearDown removes the log file created by tests
func tearDown() {
os.Remove(TestConfig.LogFile)
}
// Test_makeLogger tests makeLogger to ensure it sets the proper values
func Test_makeLogger(t *testing.T) {
makeLogger(&TestConfig)
if Logger.Level != logrus.DebugLevel {
t.Fatalf("makeLogger did not set the correct level. Expected %s, got %s", logrus.DebugLevel, Logger.Level)
}
if _, err := os.OpenFile(TestConfig.LogFile, os.O_RDONLY, os.ModePerm); err != nil {
t.Fatalf("makeLogger did not create the log file at %s", TestConfig.LogFile)
}
tearDown()
}
// TestNewServer tests NewServer and verifies it sets proper values
func TestNewServer(t *testing.T) {
server := NewServer(&TestConfig)
if server.MaxHeaderBytes != TestConfig.MaxHeaderBytes {
t.Fatalf("NewServer set incorrect MaxHeaderBytes. Expected %s, got %s", TestConfig.MaxHeaderBytes, server.MaxHeaderBytes)
}
if server.Addr != fmt.Sprintf("%s:%d", TestConfig.BindAddress, TestConfig.BindPort) {
t.Fatalf("NewServer set incorrect BindAddress. Expected %s, got %s", TestConfig.BindAddress, server.Addr)
}
if server.ReadTimeout != TestConfig.ReadTimeout {
t.Fatalf("NewServer set incorrect ReadTimeout. Expected %s, got %s", TestConfig.ReadTimeout, server.ReadTimeout)
}
if server.WriteTimeout != TestConfig.WriteTimeout {
t.Fatalf("NewServer set incorrect WriteTimeout. Expected %s, got %s", TestConfig.WriteTimeout, server.WriteTimeout)
}
tearDown()
}
// TODO(ashcrow): Finish testing
/*
func TestRunHttpAndHttps(t *testingT) {
}
func TestBackgroundRunHttps(t *testingT) {
}
func TestBackgroundRunHttp(t *testingT) {
}
*/