-
Notifications
You must be signed in to change notification settings - Fork 34
/
response_test.go
69 lines (64 loc) · 2.15 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
package ipp
import (
"bytes"
"github.com/stretchr/testify/assert"
"testing"
)
var responseTestCases = []struct {
Response Response
Bytes []byte
// some test cases are only for encoding, skip them in decoding tests
SkipDecoding bool
}{
{
Response: Response{
ProtocolVersionMajor: ProtocolVersionMajor,
ProtocolVersionMinor: ProtocolVersionMinor,
StatusCode: StatusOk,
RequestId: 12345,
},
Bytes: []byte{2, 0, 0, 0, 0, 0, 48, 57, 1, 71, 0, 18, 97, 116, 116, 114, 105, 98, 117, 116, 101, 115, 45, 99, 104, 97, 114, 115, 101, 116, 0, 5, 117, 116, 102, 45, 56, 72, 0, 27, 97, 116, 116, 114, 105, 98, 117, 116, 101, 115, 45, 110, 97, 116, 117, 114, 97, 108, 45, 108, 97, 110, 103, 117, 97, 103, 101, 0, 5, 101, 110, 45, 85, 83, 3},
SkipDecoding: true,
},
{
Response: Response{
ProtocolVersionMajor: ProtocolVersionMajor,
ProtocolVersionMinor: ProtocolVersionMinor,
StatusCode: StatusOk,
RequestId: 12345,
OperationAttributes: Attributes{
AttributeCharset: []Attribute{
{
Value: Charset,
Tag: AttributeTagMapping[Charset],
},
},
AttributeNaturalLanguage: []Attribute{
{
Value: CharsetLanguage,
Tag: AttributeTagMapping[CharsetLanguage],
},
},
},
},
Bytes: []byte{2, 0, 0, 0, 0, 0, 48, 57, 1, 71, 0, 18, 97, 116, 116, 114, 105, 98, 117, 116, 101, 115, 45, 99, 104, 97, 114, 115, 101, 116, 0, 5, 117, 116, 102, 45, 56, 72, 0, 27, 97, 116, 116, 114, 105, 98, 117, 116, 101, 115, 45, 110, 97, 116, 117, 114, 97, 108, 45, 108, 97, 110, 103, 117, 97, 103, 101, 0, 5, 101, 110, 45, 85, 83, 3},
SkipDecoding: true,
},
}
func TestResponse_Encode(t *testing.T) {
for _, c := range responseTestCases {
data, err := c.Response.Encode()
assert.Nil(t, err)
assert.Equal(t, c.Bytes, data, "encoded response is not correct")
}
}
func TestResponseDecoder_Decode(t *testing.T) {
for _, c := range responseTestCases {
if c.SkipDecoding {
continue
}
response, err := NewResponseDecoder(bytes.NewReader(c.Bytes)).Decode(nil)
assert.Nil(t, err)
assert.Equal(t, &c.Response, response, "decoded response is not correct")
}
}