11package table
22
3- /*
4- func makeTable(url string, schema string) Table {
5- var result map[string]interface{}
3+ import (
4+ "encoding/json"
5+ "os"
6+ "testing"
7+ )
68
7- err := json.Unmarshal([]byte(jsonString), &result)
9+ func makeTable (fname string ) Table {
10+ data , err := os .ReadFile ("testdata/" + fname )
11+ if err != nil {
12+ panic (err )
13+ }
14+ var result map [string ]interface {}
15+ err = json .Unmarshal (data , & result )
816 if err != nil {
917 panic (err )
1018 }
@@ -15,22 +23,27 @@ func makeTable(url string, schema string) Table {
1523 return * tbl
1624}
1725
18- func TestTable_t(t *testing.T) {
19- var tests = []struct {
20- jsonCol string
21- input string
22- }{
23- {`{}`, "string"},
24- {`{"datatype": "boolean"}`, "boolean"},
25- {`{"datatype": {"base": "boolean"}}`, "boolean"},
26- }
27- for _, tt := range tests {
28- t.Run("Datatype", func(t *testing.T) {
29- col := makeCol(tt.jsonCol)
30- if tt.input != col.Datatype.Base {
31- t.Errorf(`problem: %q vs %q`, tt.input, col.Datatype.Base)
32- }
33- })
26+ func TestTable_simple (t * testing.T ) {
27+ tbl := makeTable ("table_simple.json" )
28+ if len (tbl .PrimaryKey ) > 0 {
29+ t .Errorf (`problem: %q vs %q` , len (tbl .PrimaryKey ), 0 )
30+ }
31+ if len (tbl .Columns ) != 1 {
32+ t .Errorf (`problem: %q vs %q` , len (tbl .Columns ), 1 )
33+ }
34+ if tbl .CanonicalName != "table_simple.csv" {
35+ t .Errorf (`problem: %q vs %q` , len (tbl .CanonicalName ), "table_simple.csv" )
36+ }
37+ result := make (chan TableRead , 1 )
38+ go tbl .Read ("testdata/" , result )
39+ tableRead := <- result
40+ if tableRead .Err != nil || tableRead .Url != "table_simple.csv" {
41+ t .Errorf (`problem` )
42+ }
43+ if len (tbl .Data ) != 3 {
44+ t .Errorf (`problem` )
45+ }
46+ if tbl .Data [0 ]["ID" ] != "a" {
47+ t .Errorf (`problem` )
3448 }
3549}
36- */
0 commit comments