Debian Codegraph @

question_test.go

raw symbols SCIP
1 package activitypub
2
3 import (
4 "testing"
5
6 "github.com/google/go-cmp/cmp"
7 )
8
9 func TestQuestionNew(t *testing.T) {
10 testValue := ID("test")
11
12 a := QuestionNew(testValue)
13
14 if a.ID != testValue {
15 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
16 }
17 if !a.Match(QuestionType) {
18 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), QuestionType)
19 }
20 }
21
22 func TestQuestion_GetID(t *testing.T) {
23 a := QuestionNew("test")
24
25 if a.GetID() != "test" {
26 t.Errorf("%T should return an empty %T object. Received %#v", a, a.GetID(), a.GetID())
27 }
28 }
29
30 func TestQuestion_IsObject(t *testing.T) {
31 a := QuestionNew("test")
32
33 if !a.IsObject() {
34 t.Errorf("%T should respond true to IsObject", a)
35 }
36 }
37
38 func TestQuestion_IsLink(t *testing.T) {
39 a := QuestionNew("test")
40
41 if a.IsLink() {
42 t.Errorf("%T should respond false to IsLink", a)
43 }
44 }
45
46 func TestQuestion_GetLink(t *testing.T) {
47 a := QuestionNew("test")
48
49 if a.GetLink() != "test" {
50 t.Errorf("GetLink should return \"test\" for %T, received %q", a, a.GetLink())
51 }
52 }
53
54 func TestQuestion_GetType(t *testing.T) {
55 a := QuestionNew("test")
56
57 if !QuestionType.Match(a.GetType()) {
58 t.Errorf("GetType should return %q for %T, received %q", QuestionType, a, a.GetType())
59 }
60 }
61
62 func TestToQuestion(t *testing.T) {
63 tests := []struct {
64 name string
65 it LinkOrIRI
66 want *Question
67 wantErr error
68 }{
69 {
70 name: "empty",
71 },
72 {
73 name: "Valid Question",
74 it: Question{ID: "test", Type: TravelType},
75 want: &Question{ID: "test", Type: TravelType},
76 },
77 {
78 name: "Valid *Question",
79 it: &Question{ID: "test", Type: ArriveType},
80 want: &Question{ID: "test", Type: ArriveType},
81 },
82 {
83 name: "Valid Question",
84 it: Question{ID: "test", Type: QuestionType},
85 want: &Question{ID: "test", Type: QuestionType},
86 },
87 {
88 name: "Valid *Question",
89 it: &Question{ID: "test", Type: QuestionType},
90 want: &Question{ID: "test", Type: QuestionType},
91 },
92 {
93 name: "IRI",
94 it: IRI("https://example.com"),
95 wantErr: ErrorInvalidType[Question](IRI("")),
96 },
97 {
98 name: "IntransitiveActivity",
99 it: &IntransitiveActivity{ID: "test", Type: ArriveType},
100 wantErr: ErrorInvalidType[Question](new(IntransitiveActivity)),
101 },
102 {
103 name: "Activity",
104 it: &Activity{ID: "test", Type: UpdateType},
105 wantErr: ErrorInvalidType[Question](new(Activity)),
106 },
107 {
108 name: "IRIs",
109 it: IRIs{IRI("https://example.com")},
110 wantErr: ErrorInvalidType[Question](IRIs{}),
111 },
112 {
113 name: "ItemCollection",
114 it: ItemCollection{},
115 wantErr: ErrorInvalidType[Question](ItemCollection{}),
116 },
117 {
118 name: "Object",
119 it: &Object{ID: "test", Type: ArticleType},
120 wantErr: ErrorInvalidType[Question](&Object{}),
121 },
122 {
123 name: "Actor",
124 it: &Actor{ID: "test", Type: PersonType},
125 wantErr: ErrorInvalidType[Question](&Person{}),
126 },
127 }
128 for _, tt := range tests {
129 t.Run(tt.name, func(t *testing.T) {
130 got, err := ToQuestion(tt.it)
131 if !cmp.Equal(err, tt.wantErr, EquateWeakErrors) {
132 t.Errorf("ToQuestion() error = %v, wantErr %v", err, tt.wantErr)
133 return
134 }
135 if !cmp.Equal(got, tt.want) {
136 t.Errorf("ToQuestion() got = %s", cmp.Diff(tt.want, got))
137 }
138 })
139 }
140 }
141 func TestToQuestion1(t *testing.T) {
142 var it Item
143 act := QuestionNew("test")
144 it = act
145
146 a, err := ToQuestion(it)
147 if err != nil {
148 t.Error(err)
149 }
150 if a != act {
151 t.Errorf("Invalid activity returned by ToActivity #%v", a)
152 }
153
154 ob := ObjectNew(ArticleType)
155 it = ob
156
157 o, err := ToQuestion(it)
158 if err == nil {
159 t.Errorf("Error returned when calling ToActivity with object should not be nil")
160 }
161 if o != nil {
162 t.Errorf("Invalid return by ToActivity #%v, should have been nil", o)
163 }
164 }
165
166 func TestQuestion_IsCollection(t *testing.T) {
167 t.Skipf("TODO")
168 }
169
170 func TestQuestion_UnmarshalJSON(t *testing.T) {
171 t.Skipf("TODO")
172 }