forked from singularperturbation/sphinx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
response_test.go
76 lines (65 loc) · 1.45 KB
/
response_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
package sphinx
import (
"bytes"
"testing"
)
// Test get expected errors with a buffer that's too short
func TestGetErrorWithBadBuffer(t *testing.T) {
// t.Fail()
}
// Do some basic sanity checking on round-tripping of responses
func TestRoundTripInt(t *testing.T) {
defer func() {
if r := recover(); r != nil {
t.Fatal(r)
}
}()
const testInteger = 124
var b bytes.Buffer
var w = &SafeWriter{
internalBuf: &b,
err: nil,
}
w.AddIntToBuffer(testInteger)
if w.err != nil {
t.Errorf("Unexpected error writing integer: %v\n ", w.err)
}
var r = &ResponseReader{
Buffer: &b,
internalErr: nil,
}
if recoveredInteger := r.ReadInt(); recoveredInteger != testInteger {
t.Errorf(
"Expected to get integer %v from buffer, got %v\n",
testInteger, recoveredInteger,
)
}
}
// Basic sanity checking on round-tripping of string
func TestRoundTripString(t *testing.T) {
defer func() {
if r := recover(); r != nil {
t.Fatal(r)
}
}()
const testString = "At least it was here"
var b bytes.Buffer
var w = &SafeWriter{
internalBuf: &b,
err: nil,
}
w.AddStringToBuffer(testString)
if w.err != nil {
t.Errorf("Unexpected error writing string to buffer: %v\n", w.err)
}
var r = &ResponseReader{
Buffer: &b,
internalErr: nil,
}
if recoveredString := r.ReadString(); recoveredString != testString {
t.Errorf(
"Expected to get string `%v` from buffer, got `%v`\n",
testString, recoveredString,
)
}
}