-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathflatten_test.go
More file actions
189 lines (179 loc) · 4.27 KB
/
flatten_test.go
File metadata and controls
189 lines (179 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package activitypub
import (
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestFlattenPersonProperties(t *testing.T) {
t.Skipf("TODO")
}
func TestFlattenProperties(t *testing.T) {
t.Skipf("TODO")
}
func TestFlattenCollection(t *testing.T) {
t.Skipf("TODO")
}
func TestFlattenOrderedCollection(t *testing.T) {
t.Skipf("TODO")
}
func TestFlattenIntransitiveActivityProperties(t *testing.T) {
type args struct {
act *IntransitiveActivity
}
tests := []struct {
name string
args args
want *IntransitiveActivity
}{
{
name: "blank",
args: args{&IntransitiveActivity{}},
want: &IntransitiveActivity{},
},
{
name: "flatten-actor",
args: args{&IntransitiveActivity{Actor: &Actor{ID: "example-actor-iri"}}},
want: &IntransitiveActivity{Actor: IRI("example-actor-iri")},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := FlattenIntransitiveActivityProperties(tt.args.act); !reflect.DeepEqual(got, tt.want) {
t.Errorf("FlattenIntransitiveActivityProperties() = %v, want %v", got, tt.want)
}
})
}
}
func TestFlattenActivityProperties(t *testing.T) {
type args struct {
act *Activity
}
tests := []struct {
name string
args args
want *Activity
}{
{
name: "blank",
args: args{&Activity{}},
want: &Activity{},
},
{
name: "flatten-actor",
args: args{&Activity{Actor: &Actor{ID: "example-actor-iri"}}},
want: &Activity{Actor: IRI("example-actor-iri")},
},
{
name: "flatten-object",
args: args{&Activity{Object: &Object{ID: "example-actor-iri"}}},
want: &Activity{Object: IRI("example-actor-iri")},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := FlattenActivityProperties(tt.args.act); !reflect.DeepEqual(got, tt.want) {
t.Errorf("FlattenActivityProperties() = %v, want %v", got, tt.want)
}
})
}
}
func TestFlatten(t *testing.T) {
tests := []struct {
name string
it Item
want Item
}{
{
name: "nil",
it: nil,
want: nil,
},
{
name: "iri",
it: IRI("http://example.com"),
want: IRI("http://example.com"),
},
{
name: "object",
it: &Object{ID: IRI("http://example.com")},
want: IRI("http://example.com"),
},
{
name: "items",
it: ItemCollection{IRI("http://example.com"), IRI("http://jdoe.example.com")},
want: ItemCollection{IRI("http://example.com"), IRI("http://jdoe.example.com")},
},
{
name: "ordered collection",
it: &OrderedCollection{ID: "http://example.com"},
want: IRI("http://example.com"),
},
{
name: "ordered collection page",
it: &OrderedCollectionPage{ID: "http://example.com"},
want: IRI("http://example.com"),
},
{
name: "collection",
it: &Collection{ID: "http://example.com"},
want: IRI("http://example.com"),
},
{
name: "collection page",
it: &CollectionPage{ID: "http://example.com"},
want: IRI("http://example.com"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Flatten(tt.it); !cmp.Equal(got, tt.want) {
t.Errorf("Flatten() = %s", cmp.Diff(got, tt.want))
}
})
}
}
func TestFlattenItemCollection(t *testing.T) {
tests := []struct {
name string
col ItemCollection
want ItemCollection
}{
{
name: "nil",
col: nil,
want: nil,
},
{
name: "empty",
col: ItemCollection{},
want: nil,
},
{
name: "with iri",
col: ItemCollection{IRI("http://example.com")},
want: ItemCollection{IRI("http://example.com")},
},
{
name: "with object",
col: ItemCollection{&Object{ID: "http://example.com"}},
want: ItemCollection{IRI("http://example.com")},
},
{
name: "with objects",
col: ItemCollection{&Object{ID: "http://example.com"}, &Actor{ID: "http://example.com/~jdoe"}},
want: ItemCollection{IRI("http://example.com"), IRI("http://example.com/~jdoe")},
},
{
name: "with duplicates",
col: ItemCollection{&Object{ID: "http://example.com"}, &Actor{ID: "http://example.com/~jdoe"}, IRI("http://example.com")},
want: ItemCollection{IRI("http://example.com"), IRI("http://example.com/~jdoe")},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := FlattenItemCollection(tt.col); !cmp.Equal(got, tt.want) {
t.Errorf("FlattenItemCollection() = %s", cmp.Diff(got, tt.want))
}
})
}
}