-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdataset_test.go
129 lines (115 loc) · 4.31 KB
/
dataset_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
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
package validate
import (
"strings"
"testing"
"github.com/qri-io/dataset"
)
func TestDataset(t *testing.T) {
cm := &dataset.Commit{Title: "initial commit"}
st := &dataset.Structure{Format: "json", Schema: map[string]interface{}{"type": "array"}}
cases := []struct {
ds *dataset.Dataset
err string
}{
{nil, ""},
{&dataset.Dataset{}, "commit is required"},
{&dataset.Dataset{Commit: cm, Structure: &dataset.Structure{}}, "structure: format is required"},
{&dataset.Dataset{Commit: cm, Structure: st}, ""},
}
for i, c := range cases {
err := Dataset(c.ds)
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)
continue
}
}
}
func TestCommit(t *testing.T) {
cases := []struct {
cm *dataset.Commit
err string
}{
{nil, ""},
{&dataset.Commit{}, ""},
{&dataset.Commit{Title: strings.Repeat("f", 150)}, "title is too long. 150 length exceeds 100 character limit"},
{&dataset.Commit{Title: "message"}, ""},
}
for i, c := range cases {
err := Commit(c.cm)
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)
continue
}
}
}
func TestStructure(t *testing.T) {
cases := []struct {
st *dataset.Structure
err string
}{
{nil, ""},
{&dataset.Structure{}, "format is required"},
{&dataset.Structure{Format: "csv"}, "csv data format requires a schema"},
// {&dataset.Structure{Format: "csv"}, "schema: fields are required"},
{&dataset.Structure{Format: "json", Schema: map[string]interface{}{"type": "array"}}, ""},
}
for i, c := range cases {
err := Structure(c.st)
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)
continue
}
}
}
// func TestSchema(t *testing.T) {
// cases := []struct {
// sh *dataset.Schema
// err string
// }{
// {nil, ""},
// {&dataset.Schema{}, "fields are required"},
// {&dataset.Schema{Fields: []*dataset.Field{&dataset.Field{Name: "1"}}}, "fields: error: illegal name '1', names must start with a letter and consist of only a-z,0-9, and _. max length 144 characters"},
// {&dataset.Schema{Fields: []*dataset.Field{&dataset.Field{Name: "field", Type: vals.Float}}}, ""},
// }
// for i, c := range cases {
// err := Schema(c.sh)
// 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)
// continue
// }
// }
// }
// func TestFields(t *testing.T) {
// if err := Fields(nil); err != nil {
// t.Errorf("expected nil response. got: %s", err.Error())
// }
// cases := []struct {
// input []string
// err string
// }{
// {[]string{"abc", "12startsWithNumber"}, `error: illegal name '12startsWithNumber', names must start with a letter and consist of only a-z,0-9, and _. max length 144 characters`},
// {[]string{"abc", "$dollarsAtBeginning"}, `error: illegal name '$dollarsAtBeginning', names must start with a letter and consist of only a-z,0-9, and _. max length 144 characters`},
// {[]string{"abc", "Dollars$inTheMiddle"}, `error: illegal name 'Dollars$inTheMiddle', names must start with a letter and consist of only a-z,0-9, and _. max length 144 characters`},
// {[]string{"abc", ""}, `error: name cannot be empty`},
// {[]string{"abc", "No|pipes"}, `error: illegal name 'No|pipes', names must start with a letter and consist of only a-z,0-9, and _. max length 144 characters`},
// {[]string{"repeatedName", "repeatedName", "repeatedName"}, "error: cannot use the same name, 'repeatedName' more than once"},
// }
// for i, c := range cases {
// s := fieldsTestHelper(c.input)
// err := Fields(s)
// 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)
// continue
// }
// }
// }
// // takes a slice of strings and creates a pointer to a Structure
// // containing a schema containing those fields
// func fieldsTestHelper(s []string) []*dataset.Field {
// fields := []*dataset.Field{}
// for _, fieldName := range s {
// newField := dataset.Field{Name: fieldName}
// fields = append(fields, &newField)
// }
// return fields
// }