-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathrevisions_test.go
103 lines (89 loc) · 2.63 KB
/
revisions_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
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
package base
import (
"context"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/qri-io/dataset"
"github.com/qri-io/dataset/dstest"
"github.com/qri-io/qri/base/dsfs"
"github.com/qri-io/qri/dsref"
)
func TestLoadRevisions(t *testing.T) {
ctx := context.Background()
r := newTestRepo(t)
ref := addCitiesDataset(t, r)
cities, err := dsfs.LoadDataset(ctx, r.Filesystem(), ref.Path)
if err != nil {
t.Fatal(err)
}
cases := []struct {
ref dsref.Ref
revs string
ds *dataset.Dataset
err string
}{
// TODO - both of these are failing, let's make 'em work:
// "ds" Qri value is mismatching
// {ref, "ds", cities, ""},
// Logic on what to do in "body" is a little confusing atm, do we set BodyPath
// and move on?
// {ref, "bd", cities, ""},
{ref, "tf", &dataset.Dataset{Transform: cities.Transform}, ""},
{ref, "md,vz,tf,st", &dataset.Dataset{Transform: cities.Transform, Meta: cities.Meta, Structure: cities.Structure}, ""},
}
for i, c := range cases {
revs, err := dsref.ParseRevs(c.revs)
if err != nil {
t.Errorf("case %d error parsing revs: %s", i, err)
continue
}
got, err := LoadRevs(ctx, r.Filesystem(), c.ref, revs)
if !(err == nil && c.err == "" || err != nil && err.Error() == c.err) {
t.Errorf("case %d error mismatch. expected: %s, got: %s", i, c.err, err)
}
if diff := dstest.CompareDatasets(c.ds, got); diff != "" {
t.Errorf("case %d result mismatch (-want +got):\n%s", i, err)
}
}
}
func TestDrop(t *testing.T) {
good := []struct {
str string
ds *dataset.Dataset
}{
{"md,st,bd,tf,rm,vz", &dataset.Dataset{}},
{"md", &dataset.Dataset{Meta: &dataset.Meta{}}},
{"meta", &dataset.Dataset{Meta: &dataset.Meta{}}},
{"st", &dataset.Dataset{Structure: &dataset.Structure{}}},
{"structure", &dataset.Dataset{Structure: &dataset.Structure{}}},
}
expect := &dataset.Dataset{}
for _, c := range good {
t.Run(c.str, func(t *testing.T) {
if err := Drop(c.ds, c.str); err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(expect, c.ds, cmpopts.IgnoreUnexported(dataset.Dataset{})); diff != "" {
t.Errorf("result mismatch (-want +got):\n%s", diff)
}
})
}
bad := []struct {
str, err string
}{
{"ds", `cannot drop component: "ds"`},
{"snarfar", `unrecognized revision field: snarfar`},
}
for _, c := range bad {
t.Run(c.str, func(t *testing.T) {
err := Drop(&dataset.Dataset{}, c.str)
if err == nil {
t.Fatalf("expected error, got nil")
}
if diff := cmp.Diff(c.err, err.Error(), cmpopts.IgnoreUnexported(dataset.Dataset{})); diff != "" {
t.Errorf("result mismatch (-want +got):\n%s", diff)
}
})
}
}