forked from esurdam/go-sophos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_test.go
65 lines (55 loc) · 1.31 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
package sophos_test
import (
"encoding/json"
"net/http/httptest"
"testing"
"github.com/esurdam/go-sophos"
)
func TestResponse_MarshalTo(t *testing.T) {
td := setupTestCase(t)
defer td(t)
r := httptest.NewRecorder()
byt, _ := json.Marshal(dnsMock{
Email: "[email protected]",
})
r.Body.Write(byt)
var res sophos.Response
var dns dnsMock
res.Response = r.Result()
err := res.MarshalTo(&dns)
if err != nil {
t.Error(err)
}
if dns.Email != "[email protected]" {
t.Errorf("wanted [email protected], got %s", dns.Email)
}
}
func TestResponse_Errors(t *testing.T) {
td := setupTestCase(t)
defer td(t)
res, err := client.Get("/api/errorjson")
if err == nil {
t.Error("TestResponse_Errors should have error for /api/errorjson")
}
if res.Errors == nil {
t.Error("TestResponse_Errors should have error for /api/errorjson")
}
errs := *res.Errors
if len(errs) != 1 {
t.Error("TestResponse_Errors should have returned Error")
return
}
if !errs.IsFatal() {
t.Error("TestResponse_Errors should be fatal")
}
if !errs[0].IsFatal() {
t.Error("TestResponse_Errors should be fatal")
}
if errs[0].Msgtype != "DATATYPE_OBJECT_ATTRIBUTE" {
t.Error("TestResponse_Errors should have MsgType DATATYPE_OBJECT_ATTRIBUTE")
}
errs[0].Fatal = 0
if errs.IsFatal() {
t.Error("TestResponse_Errors should not be fatal")
}
}