-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tpl_test.go
53 lines (48 loc) · 953 Bytes
/
tpl_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
package zdb
import (
"bytes"
"strings"
"testing"
)
func TestTemplate(t *testing.T) {
const testSchema = `
create table x (
x_id {{auto_increment}},
created_at timestamp {{check_date "created_at"}}
);
{{sqlite "SQLITE"}}
{{psql "PSQL"}}
`
tests := []struct {
driver Dialect
want string
}{
{DialectSQLite, `
create table x (
x_id integer primary key autoincrement,
created_at timestamp check(created_at = strftime('%Y-%m-%d', created_at))
);
SQLITE
`},
{DialectPostgreSQL, `
create table x (
x_id serial primary key,
created_at timestamp
);
PSQL
`},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
got, err := Template(tt.driver, testSchema)
if err != nil {
t.Fatal(err)
}
got = bytes.TrimSpace(got)
tt.want = strings.TrimSpace(tt.want)
if string(got) != tt.want {
t.Errorf("\ngot:\n%s\nwant:\n%s", string(got), tt.want)
}
})
}
}