Debian Codegraph @

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