-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathquestion_test.go
More file actions
172 lines (151 loc) · 3.81 KB
/
question_test.go
File metadata and controls
172 lines (151 loc) · 3.81 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package activitypub
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestQuestionNew(t *testing.T) {
testValue := ID("test")
a := QuestionNew(testValue)
if a.ID != testValue {
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
}
if !a.Match(QuestionType) {
t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), QuestionType)
}
}
func TestQuestion_GetID(t *testing.T) {
a := QuestionNew("test")
if a.GetID() != "test" {
t.Errorf("%T should return an empty %T object. Received %#v", a, a.GetID(), a.GetID())
}
}
func TestQuestion_IsObject(t *testing.T) {
a := QuestionNew("test")
if !a.IsObject() {
t.Errorf("%T should respond true to IsObject", a)
}
}
func TestQuestion_IsLink(t *testing.T) {
a := QuestionNew("test")
if a.IsLink() {
t.Errorf("%T should respond false to IsLink", a)
}
}
func TestQuestion_GetLink(t *testing.T) {
a := QuestionNew("test")
if a.GetLink() != "test" {
t.Errorf("GetLink should return \"test\" for %T, received %q", a, a.GetLink())
}
}
func TestQuestion_GetType(t *testing.T) {
a := QuestionNew("test")
if !QuestionType.Match(a.GetType()) {
t.Errorf("GetType should return %q for %T, received %q", QuestionType, a, a.GetType())
}
}
func TestToQuestion(t *testing.T) {
tests := []struct {
name string
it LinkOrIRI
want *Question
wantErr error
}{
{
name: "empty",
},
{
name: "Valid Question",
it: Question{ID: "test", Type: TravelType},
want: &Question{ID: "test", Type: TravelType},
},
{
name: "Valid *Question",
it: &Question{ID: "test", Type: ArriveType},
want: &Question{ID: "test", Type: ArriveType},
},
{
name: "Valid Question",
it: Question{ID: "test", Type: QuestionType},
want: &Question{ID: "test", Type: QuestionType},
},
{
name: "Valid *Question",
it: &Question{ID: "test", Type: QuestionType},
want: &Question{ID: "test", Type: QuestionType},
},
{
name: "IRI",
it: IRI("https://example.com"),
wantErr: ErrorInvalidType[Question](IRI("")),
},
{
name: "IntransitiveActivity",
it: &IntransitiveActivity{ID: "test", Type: ArriveType},
wantErr: ErrorInvalidType[Question](new(IntransitiveActivity)),
},
{
name: "Activity",
it: &Activity{ID: "test", Type: UpdateType},
wantErr: ErrorInvalidType[Question](new(Activity)),
},
{
name: "IRIs",
it: IRIs{IRI("https://example.com")},
wantErr: ErrorInvalidType[Question](IRIs{}),
},
{
name: "ItemCollection",
it: ItemCollection{},
wantErr: ErrorInvalidType[Question](ItemCollection{}),
},
{
name: "Object",
it: &Object{ID: "test", Type: ArticleType},
wantErr: ErrorInvalidType[Question](&Object{}),
},
{
name: "Actor",
it: &Actor{ID: "test", Type: PersonType},
wantErr: ErrorInvalidType[Question](&Person{}),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ToQuestion(tt.it)
if !cmp.Equal(err, tt.wantErr, EquateWeakErrors) {
t.Errorf("ToQuestion() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !cmp.Equal(got, tt.want) {
t.Errorf("ToQuestion() got = %s", cmp.Diff(tt.want, got))
}
})
}
}
func TestToQuestion1(t *testing.T) {
var it Item
act := QuestionNew("test")
it = act
a, err := ToQuestion(it)
if err != nil {
t.Error(err)
}
if a != act {
t.Errorf("Invalid activity returned by ToActivity #%v", a)
}
ob := ObjectNew(ArticleType)
it = ob
o, err := ToQuestion(it)
if err == nil {
t.Errorf("Error returned when calling ToActivity with object should not be nil")
}
if o != nil {
t.Errorf("Invalid return by ToActivity #%v, should have been nil", o)
}
}
func TestQuestion_IsCollection(t *testing.T) {
t.Skipf("TODO")
}
func TestQuestion_UnmarshalJSON(t *testing.T) {
t.Skipf("TODO")
}