-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest_writeto_test.go
108 lines (83 loc) · 2.19 KB
/
request_writeto_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package finger_test
import (
"github.com/reiver/go-finger"
"strings"
"testing"
)
func TestRequest_WriteTo(t *testing.T) {
tests := []struct{
FingerRequest finger.Request
Expected string
}{
{
FingerRequest: finger.EmptyRequest(),
Expected: "\r\n",
},
{
FingerRequest: finger.CreateRequestSwitch("/W"),
Expected: "/W\r\n",
},
{
FingerRequest: finger.CreateRequestSwitch("/PULL"),
Expected: "/PULL\r\n",
},
{
FingerRequest: finger.CreateRequestTarget("joeblow"),
Expected: "joeblow\r\n",
},
{
FingerRequest: finger.CreateRequestTarget("dariush"),
Expected: "dariush\r\n",
},
{
FingerRequest: finger.CreateRequest("/W", "joeblow"),
Expected: "/W joeblow\r\n",
},
{
FingerRequest: finger.CreateRequest("/W", "dariush"),
Expected: "/W dariush\r\n",
},
{
FingerRequest: finger.CreateRequest("/PULL", "joeblow"),
Expected: "/PULL joeblow\r\n",
},
{
FingerRequest: finger.CreateRequest("/PULL", "dariush"),
Expected: "/PULL dariush\r\n",
},
{
FingerRequest: finger.CreateRequest("/once/twice/thrice/fource", "malekeh"),
Expected: "/once/twice/thrice/fource malekeh\r\n",
},
}
for testNumber, test := range tests {
var storage strings.Builder
{
n, err := test.FingerRequest.WriteTo(&storage)
if nil != err {
t.Errorf("For test #%d, did not expect an error but actually got one.", testNumber)
t.Logf("ERROR: (%T) %q", err, err)
t.Logf("EXPECTED-REQUEST: %q", test.Expected)
continue
}
if expected, actual := int64(len(test.Expected)), n; expected != actual {
t.Errorf("For test #%d, the actual number of bytes written is not what was expected.", testNumber)
t.Logf("EXPECTED: %d", expected)
t.Logf("ACTUAL: %d", actual)
t.Logf("EXPECTED-REQUEST: %q", test.Expected)
t.Logf("ACTUAL-REQUEST: %q", storage.String())
continue
}
}
{
var expected string = test.Expected
var actual string = storage.String()
if expected != actual {
t.Errorf("For test #%d, the actual finger-protocol request (string) is not what was expected.", testNumber)
t.Logf("EXPECTED: %q", expected)
t.Logf("ACTUAL: %q", actual)
continue
}
}
}
}