Debian Codegraph @

profile_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 TestProfile_Recipients(t *testing.T) {
11 t.Skipf("TODO")
12 }
13
14 func TestToProfile(t *testing.T) {
15 tests := []struct {
16 name string
17 it LinkOrIRI
18 want *Profile
19 wantErr error
20 }{
21 {
22 name: "empty",
23 },
24 {
25 name: "Valid Profile",
26 it: Profile{ID: "test", Type: ProfileType},
27 want: &Profile{ID: "test", Type: ProfileType},
28 },
29 {
30 name: "Valid *Profile",
31 it: &Profile{ID: "test", Type: ProfileType},
32 want: &Profile{ID: "test", Type: ProfileType},
33 },
34 {
35 name: "IRI",
36 it: IRI("https://example.com"),
37 wantErr: ErrorInvalidType[Profile](IRI("")),
38 },
39 {
40 name: "IRIs",
41 it: IRIs{IRI("https://example.com")},
42 wantErr: ErrorInvalidType[Profile](IRIs{}),
43 },
44 {
45 name: "ItemCollection",
46 it: ItemCollection{},
47 wantErr: ErrorInvalidType[Profile](ItemCollection{}),
48 },
49 {
50 name: "Object",
51 it: &Object{ID: "test", Type: ArticleType},
52 wantErr: ErrorInvalidType[Profile](&Object{}),
53 },
54 {
55 name: "Activity",
56 it: &Activity{ID: "test", Type: CreateType},
57 wantErr: ErrorInvalidType[Profile](&Activity{}),
58 },
59 {
60 name: "IntransitiveActivity",
61 it: &IntransitiveActivity{ID: "test", Type: ArriveType},
62 wantErr: ErrorInvalidType[Profile](&IntransitiveActivity{}),
63 },
64 }
65 for _, tt := range tests {
66 t.Run(tt.name, func(t *testing.T) {
67 got, err := ToProfile(tt.it)
68 if !cmp.Equal(err, tt.wantErr, EquateWeakErrors) {
69 t.Errorf("ToProfile() error = %v, wantErr %v", err, tt.wantErr)
70 return
71 }
72 if !cmp.Equal(got, tt.want) {
73 t.Errorf("ToProfile() got = %s", cmp.Diff(tt.want, got))
74 }
75 if got != nil && !got.Match(ProfileType) {
76 t.Errorf("ToProfile() expected to match Profile type, got = %v", got.GetType())
77 }
78 })
79 }
80 }
81
82 func TestProfile_GetID(t *testing.T) {
83 t.Skipf("TODO")
84 }
85
86 func TestProfile_GetLink(t *testing.T) {
87 t.Skipf("TODO")
88 }
89
90 func TestProfile_GetType(t *testing.T) {
91 t.Skipf("TODO")
92 }
93
94 func TestProfile_IsCollection(t *testing.T) {
95 t.Skipf("TODO")
96 }
97
98 func TestProfile_IsLink(t *testing.T) {
99 t.Skipf("TODO")
100 }
101
102 func TestProfile_IsObject(t *testing.T) {
103 t.Skipf("TODO")
104 }
105
106 func TestProfile_UnmarshalJSON(t *testing.T) {
107 t.Skipf("TODO")
108 }
109
110 func TestProfile_Clean(t *testing.T) {
111 t.Skipf("TODO")
112 }
113
114 func assertProfileWithTesting(fn canErrorFunc, expected *Profile) withProfileFn {
115 return func(p *Profile) error {
116 if !assertDeepEquals(fn, p, expected) {
117 return fmt.Errorf("not equal")
118 }
119 return nil
120 }
121 }
122
123 func TestOnProfile(t *testing.T) {
124 testProfile := Profile{
125 ID: "https://example.com",
126 }
127 type args struct {
128 it Item
129 fn func(canErrorFunc, *Profile) withProfileFn
130 }
131 tests := []struct {
132 name string
133 args args
134 wantErr bool
135 }{
136 {
137 name: "single",
138 args: args{testProfile, assertProfileWithTesting},
139 wantErr: false,
140 },
141 {
142 name: "single fails",
143 args: args{&Profile{ID: "https://not-equal"}, assertProfileWithTesting},
144 wantErr: true,
145 },
146 {
147 name: "collection of profiles",
148 args: args{ItemCollection{testProfile, testProfile}, assertProfileWithTesting},
149 wantErr: false,
150 },
151 {
152 name: "collection of profiles fails",
153 args: args{ItemCollection{testProfile, &Profile{ID: "not-equal"}}, assertProfileWithTesting},
154 wantErr: true,
155 },
156 }
157 for _, tt := range tests {
158 t.Run(tt.name, func(t *testing.T) {
159 var logFn canErrorFunc
160 if tt.wantErr {
161 logFn = t.Logf
162 } else {
163 logFn = t.Errorf
164 }
165 if err := OnProfile(tt.args.it, tt.args.fn(logFn, &testProfile)); (err != nil) != tt.wantErr {
166 t.Errorf("OnProfile() error = %v, wantErr %v", err, tt.wantErr)
167 }
168 })
169 }
170 }