forked from mmatczuk/go-http-tunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrolmsg_test.go
70 lines (64 loc) · 1.33 KB
/
controlmsg_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
// Copyright (C) 2017 Michał Matczuk
// Use of this source code is governed by an AGPL-style
// license that can be found in the LICENSE file.
package proto
import (
"errors"
"net/http"
"reflect"
"testing"
)
func TestControlMessageWriteRead(t *testing.T) {
t.Parallel()
data := []struct {
msg *ControlMessage
err error
}{
{
&ControlMessage{
Action: "action",
ForwardedHost: "forwarded_host",
ForwardedProto: "forwarded_proto",
},
nil,
},
{
&ControlMessage{
ForwardedHost: "forwarded_host",
ForwardedProto: "forwarded_proto",
},
errors.New("missing headers: [X-Action]"),
},
{
&ControlMessage{
Action: "action",
ForwardedHost: "forwarded_host",
},
errors.New("missing headers: [X-Forwarded-Proto]"),
},
{
&ControlMessage{
Action: "action",
ForwardedProto: "forwarded_proto",
},
errors.New("missing headers: [X-Forwarded-Host]"),
},
}
for i, tt := range data {
r := http.Request{}
r.Header = http.Header{}
tt.msg.WriteToHeader(r.Header)
actual, err := ReadControlMessage(&r)
if tt.err != nil {
if err == nil {
t.Error(i, "expected error")
} else if tt.err.Error() != err.Error() {
t.Error(i, tt.err, err)
}
} else {
if !reflect.DeepEqual(tt.msg, actual) {
t.Error(i, tt.msg, actual)
}
}
}
}