Debian Codegraph @

item_test.go

raw symbols SCIP
1 package activitypub
2
3 import "testing"
4
5 func TestFlatten(t *testing.T) {
6 t.Skipf("TODO")
7 }
8
9 func TestItemsEqual(t *testing.T) {
10 type args struct {
11 it Item
12 with Item
13 }
14 tests := []struct {
15 name string
16 args args
17 want bool
18 }{
19 {
20 name: "nil_items_equal",
21 args: args{nil, nil},
22 want: true,
23 },
24 {
25 name: "nil_item_with_object",
26 args: args{nil, &Object{}},
27 want: false,
28 },
29 {
30 name: "nil_item_with_object#1",
31 args: args{&Object{}, nil},
32 want: false,
33 },
34 {
35 name: "empty_objects",
36 args: args{&Object{}, &Object{}},
37 want: true,
38 },
39 {
40 name: "empty_objects_different_alias_type",
41 args: args{&Activity{}, &Object{}},
42 want: true,
43 },
44 {
45 name: "empty_objects_different_alias_type#1",
46 args: args{&Actor{}, &Object{}},
47 want: true,
48 },
49 {
50 name: "same_id_object",
51 args: args{&Object{ID: "test"}, &Object{ID: "test"}},
52 want: true,
53 },
54 {
55 name: "same_id_object_different_alias",
56 args: args{&Activity{ID: "test"}, &Object{ID: "test"}},
57 want: true,
58 },
59 {
60 name: "same_id_object_different_alias#1",
61 args: args{&Activity{ID: "test"}, &Actor{ID: "test"}},
62 want: true,
63 },
64 {
65 name: "different_id_objects",
66 args: args{&Object{ID: "test1"}, &Object{ID: "test"}},
67 want: false,
68 },
69 {
70 name: "different_id_types",
71 args: args{&Object{ID: "test", Type: NoteType}, &Object{ID: "test", Type: ArticleType}},
72 want: false,
73 },
74 {
75 name: "Link different than Object",
76 args: args{&Object{ID: "test", Type: NoteType}, &Link{ID: "test", Type: MentionType}},
77 want: false,
78 },
79 {
80 name: "matching Link",
81 args: args{&Link{ID: "test", Type: MentionType}, &Link{ID: "test", Type: MentionType}},
82 want: true,
83 },
84 {
85 name: "different id Links",
86 args: args{&Link{ID: "test1", Type: MentionType}, &Link{ID: "test", Type: MentionType}},
87 want: false,
88 },
89 }
90 for _, tt := range tests {
91 t.Run(tt.name, func(t *testing.T) {
92 if got := ItemsEqual(tt.args.it, tt.args.with); got != tt.want {
93 t.Errorf("ItemsEqual() = %v, want %v", got, tt.want)
94 }
95 })
96 }
97 }
98
99 func TestIsNil(t *testing.T) {
100 type args struct {
101 it Item
102 }
103 var (
104 o *Object
105 col *ItemCollection
106 iris *IRIs
107 obNil Item = o
108 colNil Item = col
109 itIRIs Item = iris
110 )
111 tests := []struct {
112 name string
113 args args
114 want bool
115 }{
116 {
117 name: "nil is nil",
118 args: args{
119 it: nil,
120 },
121 want: true,
122 },
123 {
124 name: "Item is nil",
125 args: args{
126 it: Item(nil),
127 },
128 want: true,
129 },
130 {
131 name: "Object nil",
132 args: args{
133 it: obNil,
134 },
135 want: true,
136 },
137 {
138 name: "IRIs nil",
139 args: args{
140 it: iris,
141 },
142 want: true,
143 },
144 {
145 name: "IRIs as Item nil",
146 args: args{
147 it: itIRIs,
148 },
149 want: true,
150 },
151 {
152 name: "IRIs not nil",
153 args: args{
154 it: IRIs{},
155 },
156 want: false,
157 },
158 {
159 name: "IRIs as Item not nil",
160 args: args{
161 it: Item(IRIs{}),
162 },
163 want: false,
164 },
165 {
166 name: "ItemCollection nil",
167 args: args{
168 it: col,
169 },
170 want: true,
171 },
172 {
173 name: "ItemCollection as Item nil",
174 args: args{
175 it: colNil,
176 },
177 want: true,
178 },
179 {
180 name: "ItemCollection not nil",
181 args: args{
182 it: ItemCollection{},
183 },
184 want: false,
185 },
186 {
187 name: "object-not-nil",
188 args: args{
189 it: &Object{},
190 },
191 want: false,
192 },
193 {
194 name: "place-not-nil",
195 args: args{
196 it: &Place{},
197 },
198 want: false,
199 },
200 {
201 name: "tombstone-not-nil",
202 args: args{
203 it: &Tombstone{},
204 },
205 want: false,
206 },
207 {
208 name: "collection-not-nil",
209 args: args{
210 it: &Collection{},
211 },
212 want: false,
213 },
214 {
215 name: "activity-not-nil",
216 args: args{
217 it: &Activity{},
218 },
219 want: false,
220 },
221 {
222 name: "intransitive-activity-not-nil",
223 args: args{
224 it: &IntransitiveActivity{},
225 },
226 want: false,
227 },
228 {
229 name: "actor-not-nil",
230 args: args{
231 it: &Actor{},
232 },
233 want: false,
234 },
235 }
236 for _, tt := range tests {
237 t.Run(tt.name, func(t *testing.T) {
238 if got := IsNil(tt.args.it); got != tt.want {
239 t.Errorf("IsNil() = %v, want %v", got, tt.want)
240 }
241 })
242 }
243 }
244
245 func TestItemsEqual1(t *testing.T) {
246 type args struct {
247 it Item
248 with Item
249 }
250 tests := []struct {
251 name string
252 args args
253 want bool
254 }{
255 {
256 name: "nil",
257 args: args{},
258 want: true,
259 },
260 {
261 name: "equal empty items",
262 args: args{
263 it: &Object{},
264 with: &Actor{},
265 },
266 want: true,
267 },
268 {
269 name: "equal same ID items",
270 args: args{
271 it: &Object{ID: "example-1"},
272 with: &Object{ID: "example-1"},
273 },
274 want: true,
275 },
276 {
277 name: "different IDs",
278 args: args{
279 it: &Object{ID: "example-1"},
280 with: &Object{ID: "example-2"},
281 },
282 want: false,
283 },
284 {
285 name: "different properties",
286 args: args{
287 it: &Object{ID: "example-1"},
288 with: &Object{Type: ArticleType},
289 },
290 want: false,
291 },
292 }
293 for _, tt := range tests {
294 t.Run(tt.name, func(t *testing.T) {
295 if got := ItemsEqual(tt.args.it, tt.args.with); got != tt.want {
296 t.Errorf("ItemsEqual() = %v, want %v", got, tt.want)
297 }
298 })
299 }
300 }
301
302 var (
303 nilIRI *IRI = nil
304
305 nilLink *Link = nil
306
307 nilObject *Object = nil
308 nilTombstone *Tombstone = nil
309 nilProfile *Profile = nil
310 nilPlace *Place = nil
311 nilRelationship *Relationship = nil
312
313 nilActor *Actor = nil
314
315 nilActivity *Activity = nil
316 nilIntransitiveActivity *IntransitiveActivity = nil
317
318 nilCollectionIntf CollectionInterface = nil
319
320 nilCollection *Collection = nil
321 nilCollectionPage *CollectionPage = nil
322
323 nilOrderedCollection *OrderedCollection = nil
324 nilOrderedCollectionPage *OrderedCollectionPage = nil
325 )
326
327 func TestIsObject(t *testing.T) {
328 tests := []struct {
329 name string
330 it Item
331 want bool
332 }{
333 {
334 name: "nil",
335 want: false,
336 },
337 {
338 name: "interface with nil value",
339 it: Item(nil),
340 want: false,
341 },
342 {
343 name: "empty object",
344 it: Object{},
345 want: true,
346 },
347 {
348 name: "pointer to empty object",
349 it: &Object{},
350 want: true,
351 },
352 {
353 name: "pointer to nil object",
354 it: nilObject,
355 want: false,
356 },
357 {
358 name: "pointer to nil tombstone",
359 it: nilTombstone,
360 want: false,
361 },
362 {
363 name: "pointer to nil profile",
364 it: nilProfile,
365 want: false,
366 },
367 {
368 name: "pointer to nil place",
369 it: nilPlace,
370 want: false,
371 },
372 {
373 name: "pointer to nil relationship",
374 it: nilRelationship,
375 want: false,
376 },
377 {
378 name: "pointer to nil actor",
379 it: nilActor,
380 want: false,
381 },
382 {
383 name: "pointer to nil activity",
384 it: nilActivity,
385 want: false,
386 },
387 {
388 name: "pointer to nil intransitive activity",
389 it: nilIntransitiveActivity,
390 want: false,
391 },
392 {
393 name: "pointer to nil collection interface",
394 it: nilCollectionIntf,
395 want: false,
396 },
397 {
398 name: "pointer to nil collection",
399 it: nilCollection,
400 want: false,
401 },
402 {
403 name: "pointer to nil collection page",
404 it: nilCollectionPage,
405 want: false,
406 },
407 {
408 name: "pointer to nil ordered collection",
409 it: nilOrderedCollection,
410 want: false,
411 },
412 {
413 name: "pointer to nil ordered collection page",
414 it: nilOrderedCollectionPage,
415 want: false,
416 },
417 }
418 for _, tt := range tests {
419 t.Run(tt.name, func(t *testing.T) {
420 if got := IsObject(tt.it); got != tt.want {
421 t.Errorf("IsObject() = %v, want %v", got, tt.want)
422 }
423 })
424 }
425 }
426
427 func TestItemsEqual2(t *testing.T) {
428 type args struct {
429 it Item
430 with Item
431 }
432 tests := []struct {
433 name string
434 args args
435 want bool
436 }{
437 {
438 name: "nil vs nil",
439 args: args{
440 it: nil,
441 with: nil,
442 },
443 want: true,
444 },
445 {
446 name: "nil vs object",
447 args: args{
448 it: nil,
449 with: Object{},
450 },
451 want: false,
452 },
453 {
454 name: "object vs nil",
455 args: args{
456 it: Object{},
457 with: nil,
458 },
459 want: false,
460 },
461 {
462 name: "empty object vs empty object",
463 args: args{
464 it: Object{},
465 with: Object{},
466 },
467 want: true,
468 },
469 {
470 name: "object-id vs empty object",
471 args: args{
472 it: Object{ID: "https://example.com"},
473 with: Object{},
474 },
475 want: false,
476 },
477 {
478 name: "empty object vs object-id",
479 args: args{
480 it: Object{},
481 with: Object{ID: "https://example.com"},
482 },
483 want: false,
484 },
485 }
486 for _, tt := range tests {
487 t.Run(tt.name, func(t *testing.T) {
488 if got := ItemsEqual(tt.args.it, tt.args.with); got != tt.want {
489 t.Errorf("ItemsEqual() = %v, want %v", got, tt.want)
490 }
491 })
492 }
493 }
494
495 func TestIsItemCollection(t *testing.T) {
496 tests := []struct {
497 name string
498 it LinkOrIRI
499 want bool
500 }{
501 {
502 name: "empty",
503 it: nil,
504 want: false,
505 },
506 {
507 name: "object",
508 it: Object{},
509 want: false,
510 },
511 {
512 name: "nil item",
513 it: Item(nil),
514 want: false,
515 },
516 {
517 name: "nil item collection",
518 it: ItemCollection(nil),
519 want: true,
520 },
521 {
522 name: "item collection with nil item",
523 it: ItemCollection{nil},
524 want: true,
525 },
526 {
527 name: "item collection with one item",
528 it: ItemCollection{Object{}},
529 want: true,
530 },
531 {
532 name: "nil iris",
533 it: IRIs(nil),
534 want: false,
535 },
536 {
537 name: "iris with no items",
538 it: IRIs{},
539 want: true,
540 },
541 {
542 name: "iris with one item",
543 it: IRIs{""},
544 want: true,
545 },
546 }
547 for _, tt := range tests {
548 t.Run(tt.name, func(t *testing.T) {
549 if got := IsItemCollection(tt.it); got != tt.want {
550 t.Errorf("IsItemCollection() = %v, want %v", got, tt.want)
551 }
552 })
553 }
554 }
555
556 func TestIsIRI(t *testing.T) {
557 tests := []struct {
558 name string
559 it LinkOrIRI
560 want bool
561 }{
562 {
563 name: "empty",
564 it: nil,
565 want: false,
566 },
567 {
568 name: "nil iri",
569 it: nilIRI,
570 want: false,
571 },
572 {
573 name: "empty string",
574 it: IRI(""),
575 want: true,
576 },
577 }
578 for _, tt := range tests {
579 t.Run(tt.name, func(t *testing.T) {
580 if got := IsIRI(tt.it); got != tt.want {
581 t.Errorf("IsIRI() = %v, want %v", got, tt.want)
582 }
583 })
584 }
585 }
586
587 func TestIsIRIs(t *testing.T) {
588 tests := []struct {
589 name string
590 it LinkOrIRI
591 want bool
592 }{
593 {
594 name: "empty",
595 it: nil,
596 want: false,
597 },
598 {
599 name: "object",
600 it: Object{},
601 want: false,
602 },
603 {
604 name: "nil iri",
605 it: nilIRI,
606 want: false,
607 },
608 {
609 name: "nil item",
610 it: Item(nil),
611 want: false,
612 },
613 {
614 name: "nil item collection",
615 it: ItemCollection(nil),
616 want: false,
617 },
618 {
619 name: "item collection with nil item",
620 it: ItemCollection{nil},
621 want: false,
622 },
623 {
624 name: "item collection with one item",
625 it: ItemCollection{Object{}},
626 want: false,
627 },
628 {
629 name: "nil iris",
630 it: IRIs(nil),
631 want: false,
632 },
633 {
634 name: "iris with no items",
635 it: IRIs{},
636 want: true,
637 },
638 {
639 name: "iris with one item",
640 it: IRIs{""},
641 want: true,
642 },
643 }
644 for _, tt := range tests {
645 t.Run(tt.name, func(t *testing.T) {
646 if got := IsIRIs(tt.it); got != tt.want {
647 t.Errorf("IsIRIs() = %v, want %v", got, tt.want)
648 }
649 })
650 }
651 }
652
653 func TestIsLink(t *testing.T) {
654 tests := []struct {
655 name string
656 it LinkOrIRI
657 want bool
658 }{
659 {
660 name: "empty",
661 it: nil,
662 want: false,
663 },
664 {
665 name: "nil link",
666 it: nilLink,
667 want: false,
668 },
669 {
670 name: "object",
671 it: Object{},
672 want: false,
673 },
674 {
675 name: "link",
676 it: Link{},
677 want: true,
678 },
679 {
680 name: "link pointer",
681 it: &Link{},
682 want: true,
683 },
684 }
685 for _, tt := range tests {
686 t.Run(tt.name, func(t *testing.T) {
687 if got := IsLink(tt.it); got != tt.want {
688 t.Errorf("IsLink() = %v, want %v", got, tt.want)
689 }
690 })
691 }
692 }