-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_test.go
92 lines (88 loc) · 1.58 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
87
88
89
90
91
92
package gmock
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewServer(t *testing.T) {
// default port
want := &Server{
port: defaultPort,
}
got := NewServer()
assert.Equal(t, want.port, got.port)
}
func TestNewServerWithConfig(t *testing.T) {
type args struct {
config Config
}
tests := []struct {
name string
args args
want *Server
}{
{
name: "default port",
args: args{
config: Config{},
},
want: &Server{
port: defaultPort,
stubs: make(stubHashMap),
},
},
{
name: "custom port",
args: args{
config: Config{
Port: 9999,
},
},
want: &Server{
port: 9999,
stubs: make(stubHashMap),
},
},
{
name: "custom port and stubs",
args: args{
config: Config{
Port: 9999,
Stubs: []*Stub{
{
Request: StubRequest{
Method: "GET",
Path: "/test",
},
Response: StubResponse{
StatusCode: 200,
Body: "{}",
},
},
},
},
},
want: &Server{
port: 9999,
stubs: stubHashMap{
hash("cf31ce76c1b07cfaecef83c3feb6c04dd2c98f4f2aa33375c7b7a7d2a90424da"): &Stub{
Request: StubRequest{
Method: "GET",
Path: "/test",
},
Response: StubResponse{
StatusCode: 200,
Body: "{}",
},
},
},
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want.port, NewServerWithConfig(tt.args.config).port)
assert.Equal(t, tt.want.stubs, NewServerWithConfig(tt.args.config).stubs)
})
}
}