-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathocfl_test.go
61 lines (56 loc) · 1.31 KB
/
ocfl_test.go
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
package ocfl_test
import (
"testing"
"github.com/birkland/ocfl"
"github.com/go-test/deep"
)
func TestTypeRountTrip(t *testing.T) {
for _, typ := range []ocfl.Type{ocfl.Any, ocfl.File, ocfl.Version, ocfl.Object, ocfl.Intermediate, ocfl.Root, 42} {
typ := typ
t.Run(typ.String(), func(t *testing.T) {
rt := ocfl.ParseType(typ.String())
if rt != typ && rt != ocfl.Any {
t.Errorf("Roundrtip failed for %s", typ)
}
})
}
}
func TestCoords(t *testing.T) {
cases := []struct {
name string
entity ocfl.EntityRef
expected []string
}{
{"root", ocfl.EntityRef{Type: ocfl.Root}, nil},
{"object", ocfl.EntityRef{ID: "foo", Type: ocfl.Object}, []string{"foo"}},
{"version", ocfl.EntityRef{
ID: "bar",
Type: ocfl.Version,
Parent: &ocfl.EntityRef{
ID: "foo",
Type: ocfl.Object,
},
}, []string{"foo", "bar"}},
{"file", ocfl.EntityRef{
ID: "baz",
Type: ocfl.File,
Parent: &ocfl.EntityRef{
ID: "bar",
Type: ocfl.Version,
Parent: &ocfl.EntityRef{
ID: "foo",
Type: ocfl.Object,
},
},
}, []string{"foo", "bar", "baz"}},
}
for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
diffs := deep.Equal(c.expected, c.entity.Coords())
if len(diffs) != 0 {
t.Errorf("Did not get expected coords: %s", diffs)
}
})
}
}