forked from infobloxopen/atlas-app-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware_test.go
51 lines (43 loc) · 1.45 KB
/
middleware_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
package gateway
import (
"testing"
"github.com/infobloxopen/atlas-app-toolkit/query"
)
func TestUnsetOp(t *testing.T) {
page := new(query.PageInfo)
res := &testResponse{PageInfo: &query.PageInfo{Offset: 30, Size: 10}}
if err := unsetOp(res, page); err != nil {
t.Fatalf("unexpected error: %s", err)
}
if page.GetOffset() != 30 {
t.Errorf("invalid repsponse offset: %d - expected: 30", page.GetOffset())
}
if page.GetSize() != 10 {
t.Errorf("invalid repsponse size: %d - expected: 10", page.GetSize())
}
// nil operator
err := unsetOp(res, nil)
if err == nil {
t.Fatalf("unexpected non error result - expected: %s", "operator is not a pointer - invalid")
}
if err.Error() != "operator is not a pointer - invalid" {
t.Errorf("invalid error: %s - expected: %s", err, "operator is not a pointer - invalid")
}
// nil response
err = unsetOp(nil, nil)
if err == nil {
t.Fatalf("unexpected non error result - expected: %s", "response is not a pointer - invalid")
}
if err.Error() != "response is not a pointer - invalid" {
t.Errorf("invalid error: %s - expected: %s", err, "response is not a pointer - invalid")
}
// non struct response
var i int
err = unsetOp(&i, nil)
if err == nil {
t.Fatalf("unexpected non error result - expected: %s", "response value is not a struct - int")
}
if err.Error() != "response value is not a struct - int" {
t.Errorf("invalid error: %s - expected: %s", err, "response value is not a struct - int")
}
}