forked from open-networks/go-msgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResponseStatus_test.go
92 lines (88 loc) · 2.44 KB
/
ResponseStatus_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
package msgraph
import (
"fmt"
"testing"
"time"
)
func TestResponseStatus_Equal(t *testing.T) {
testTime := time.Now()
type args struct {
other ResponseStatus
}
tests := []struct {
name string
s ResponseStatus
args args
want bool
}{
{
name: "Equal",
s: ResponseStatus{Response: "accepted", Time: testTime},
args: args{other: ResponseStatus{Response: "accepted", Time: testTime}},
want: true,
}, {
name: "non-equal response",
s: ResponseStatus{Response: "declined", Time: testTime},
args: args{other: ResponseStatus{Response: "accepted", Time: testTime}},
want: false,
}, {
name: "non-equal time",
s: ResponseStatus{Response: "accepted", Time: testTime.Add(time.Minute)},
args: args{other: ResponseStatus{Response: "accepted", Time: testTime}},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.s.Equal(tt.args.other); got != tt.want {
t.Errorf("ResponseStatus.Equal() = %v, want %v", got, tt.want)
}
})
}
}
func TestResponseStatus_UnmarshalJSON(t *testing.T) {
fmt.Println(time.Now().Format(time.RFC3339Nano))
type args struct {
data []byte
}
tests := []struct {
name string
s *ResponseStatus
args args
wantErr bool
}{
{
name: "all good",
s: &ResponseStatus{},
args: args{data: []byte("{\"response\" : \"accepted\", \"time\" : \"" + time.Now().Format(time.RFC3339Nano) + "\"}")},
wantErr: false,
}, {
name: "invalid time format",
s: &ResponseStatus{},
args: args{data: []byte("{\"response\" : \"accepted\", \"time\" : \"" + time.Now().Format(time.RFC1123) + "\"}")},
wantErr: true,
}, {
name: "response-field empty",
s: &ResponseStatus{},
args: args{data: []byte("{\"time\" : \"" + time.Now().Format(time.RFC1123) + "\"}")},
wantErr: true,
}, {
name: "time-field empty",
s: &ResponseStatus{},
args: args{data: []byte("{\"response\" : \"accepted\"}")},
wantErr: true,
}, {
name: "invalid json",
s: &ResponseStatus{},
args: args{data: []byte("{\"response\" \"accepted\", \"time\" : \"" + time.Now().Format(time.RFC3339Nano) + "\"}")},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.s.UnmarshalJSON(tt.args.data); (err != nil) != tt.wantErr {
t.Errorf("ResponseStatus.UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}