Debian Codegraph @

place_test.go

raw symbols SCIP
1 package activitypub
2
3 import (
4 "fmt"
5 "testing"
6
7 "github.com/google/go-cmp/cmp"
8 )
9
10 func TestPlace_Recipients(t *testing.T) {
11 t.Skipf("TODO")
12 }
13
14 func TestToPlace(t *testing.T) {
15 tests := []struct {
16 name string
17 it LinkOrIRI
18 want *Place
19 wantErr error
20 }{
21 {
22 name: "empty",
23 },
24 {
25 name: "Valid Place",
26 it: Place{ID: "test", Type: PlaceType},
27 want: &Place{ID: "test", Type: PlaceType},
28 },
29 {
30 name: "Valid *Place",
31 it: &Place{ID: "test", Type: PlaceType},
32 want: &Place{ID: "test", Type: PlaceType},
33 },
34 {
35 name: "IRI",
36 it: IRI("https://example.com"),
37 wantErr: ErrorInvalidType[Place](IRI("")),
38 },
39 {
40 name: "IRIs",
41 it: IRIs{IRI("https://example.com")},
42 wantErr: ErrorInvalidType[Place](IRIs{}),
43 },
44 {
45 name: "ItemCollection",
46 it: ItemCollection{},
47 wantErr: ErrorInvalidType[Place](ItemCollection{}),
48 },
49 {
50 name: "Object",
51 it: &Object{ID: "test", Type: ArticleType},
52 wantErr: ErrorInvalidType[Place](&Object{}),
53 },
54 {
55 name: "Activity",
56 it: &Activity{ID: "test", Type: CreateType},
57 wantErr: ErrorInvalidType[Place](&Activity{}),
58 },
59 {
60 name: "IntransitiveActivity",
61 it: &IntransitiveActivity{ID: "test", Type: ArriveType},
62 wantErr: ErrorInvalidType[Place](&IntransitiveActivity{}),
63 },
64 }
65 for _, tt := range tests {
66 t.Run(tt.name, func(t *testing.T) {
67 got, err := ToPlace(tt.it)
68 if !cmp.Equal(err, tt.wantErr, EquateWeakErrors) {
69 t.Errorf("ToPlace() error = %v, wantErr %v", err, tt.wantErr)
70 return
71 }
72 if !cmp.Equal(got, tt.want) {
73 t.Errorf("ToPlace() got = %s", cmp.Diff(tt.want, got))
74 }
75 if got != nil && !got.Match(PlaceType) {
76 t.Errorf("ToPlace() expected to match Place type, got = %v", got.GetType())
77 }
78 })
79 }
80 }
81
82 func TestPlace_GetID(t *testing.T) {
83 t.Skipf("TODO")
84 }
85
86 func TestPlace_GetLink(t *testing.T) {
87 t.Skipf("TODO")
88 }
89
90 func TestPlace_GetType(t *testing.T) {
91 t.Skipf("TODO")
92 }
93
94 func TestPlace_IsCollection(t *testing.T) {
95 t.Skipf("TODO")
96 }
97
98 func TestPlace_IsLink(t *testing.T) {
99 t.Skipf("TODO")
100 }
101
102 func TestPlace_IsObject(t *testing.T) {
103 t.Skipf("TODO")
104 }
105
106 func TestPlace_UnmarshalJSON(t *testing.T) {
107 t.Skipf("TODO")
108 }
109
110 func TestPlace_Clean(t *testing.T) {
111 t.Skipf("TODO")
112 }
113
114 func assertPlaceWithTesting(fn canErrorFunc, expected *Place) withPlaceFn {
115 return func(p *Place) error {
116 if !assertDeepEquals(fn, p, expected) {
117 return fmt.Errorf("not equal")
118 }
119 return nil
120 }
121 }
122
123 func TestOnPlace(t *testing.T) {
124 testPlace := Place{
125 ID: "https://example.com",
126 }
127 type args struct {
128 it Item
129 fn func(canErrorFunc, *Place) withPlaceFn
130 }
131 tests := []struct {
132 name string
133 args args
134 wantErr bool
135 }{
136 {
137 name: "single",
138 args: args{testPlace, assertPlaceWithTesting},
139 wantErr: false,
140 },
141 {
142 name: "single fails",
143 args: args{Place{ID: "https://not-equals"}, assertPlaceWithTesting},
144 wantErr: true,
145 },
146 {
147 name: "collectionOfPlaces",
148 args: args{ItemCollection{testPlace, testPlace}, assertPlaceWithTesting},
149 wantErr: false,
150 },
151 {
152 name: "collectionOfPlaces fails",
153 args: args{ItemCollection{testPlace, Place{ID: "https://not-equals"}}, assertPlaceWithTesting},
154 wantErr: true,
155 },
156 }
157 for _, tt := range tests {
158 var logFn canErrorFunc
159 if tt.wantErr {
160 logFn = t.Logf
161 } else {
162 logFn = t.Errorf
163 }
164 t.Run(tt.name, func(t *testing.T) {
165 if err := OnPlace(tt.args.it, tt.args.fn(logFn, &testPlace)); (err != nil) != tt.wantErr {
166 t.Errorf("OnPlace() error = %v, wantErr %v", err, tt.wantErr)
167 }
168 })
169 }
170 }