This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema_test.go
89 lines (71 loc) · 1.68 KB
/
schema_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
package dataloading
import (
"testing"
"io"
"github.com/bloomapi/dataloading/tests"
)
type TestReader struct {
looped int
}
func (r *TestReader) Read() (Valuable, error) {
r.looped += 1
if r.looped > 10 {
return nil, io.EOF
}
v := &TestValuable{}
return v, nil
}
type TestValuable struct {}
func (v *TestValuable) Value(key string) string {
switch (key) {
case "tdate":
return "2014-12-15T01:01:01.000Z"
case "tbigint":
return "1234567890"
case "tdecimal":
return "12345.1234"
case "tint":
return "1234"
case "tbool":
return "true"
case "tstring":
return "hello world"
}
return "unknown"
}
type TestDescription struct {}
func (d *TestDescription) Available() ([]Source, error) {
return []Source{
Source{
"TestSource",
"Version1.2",
"",
},
}, nil
}
func (d *TestDescription) FieldNames(string) ([]string, error) {
return []string{ "tdate", "tbigint", "tint", "tdecimal", "tbool", "tstring" }, nil
}
func (d *TestDescription) Reader(Source) (ValueReader, error) {
r := &TestReader{}
return r, nil
}
func TestDiscoversSchema(t *testing.T) {
spec := tests.Spec(t)
desc := &TestDescription{}
s, err := Schema(desc)
if err != nil {
t.Error(err)
}
if s == nil {
t.Error("s Shouldn't be nil")
}
spec.Expect(s[0].SourceName).ToEqual("TestSource")
spec.Expect(s[0].Fields[0].FieldType).ToEqual("datetime")
spec.Expect(s[0].Fields[1].FieldType).ToEqual("bigint")
spec.Expect(s[0].Fields[2].FieldType).ToEqual("int")
spec.Expect(s[0].Fields[3].FieldType).ToEqual("decimal")
spec.Expect(s[0].Fields[4].FieldType).ToEqual("boolean")
spec.Expect(s[0].Fields[5].FieldType).ToEqual("string")
spec.Expect(s[0].Fields[5].FieldName).ToEqual("tstring")
}