-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_test.go
71 lines (57 loc) · 2 KB
/
template_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
// Copyright 2019 Job Stoit. All rights reserved.
package main
import (
"bytes"
"strings"
"testing"
)
func TestCreateQbModel(t *testing.T) {
buff := bytes.NewBufferString(``)
CreateQbModel(testModel, buff)
res := buff.String()
// Table
if !strings.Contains(res, "qbUserTable = qb.Table{Name: `user`}") {
t.Error(`Error or wrong format table instantiation`)
}
// Columns
if !strings.Contains(res, "qbUserFID = qb.TableField{Parent: &qbUserTable, Name: `id`, Type: qb.Int}") {
t.Errorf("Error or wrong in table column format, maybe wrong type\n\n%s", res)
}
if !strings.Contains(res, "qbUserFLastName = qb.TableField{Parent: &qbUserTable, Name: `last_name`, Type: qb.String, Size: 100}") {
t.Errorf("Error or wrong in table column format, maybe wrong or no Size\n\n%s", res)
}
if !strings.Contains(res, "qbUserFBio = qb.TableField{Parent: &qbUserTable, Name: `bio`, Type: qb.String, Nullable: true}") {
t.Errorf("Error or wrong in table column format, maybe wrong nullable\n\n%s", res)
}
// enums
if !strings.Contains(res, "type RoleType []string") {
t.Errorf("Error or wrong in enum generation\n\n%s", res)
}
}
func TestCreateMigration(t *testing.T) {
buff := new(bytes.Buffer)
CreateMigration(testModel, buff)
res := buff.String()
if !strings.Contains(res, `CREATE TABLE IF NOT EXISTS user (
id int NOT NULL PRIMARY KEY,
name varchar(100) NOT NULL,
last_name varchar(100) NOT NULL,
bio text,
role varchar DEFAULT 'GENERAL'
);`) {
t.Errorf("Error or wrong in table query generation:\n\n%s", res)
}
if !strings.Contains(res, `CREATE TYPE role AS ENUM ( ADMIN, GENERAL );`) {
t.Errorf("Error or wrong in enum query generation:\n\n%s", res)
}
}
func TestTitle(t *testing.T) {
expectStr(t, `UserID`, title(`user_id`))
expectStr(t, `UserModel`, title(`user_model`))
expectStr(t, `ModelSQL`, title(`model_sql`))
expectStr(t, `WebsiteURL`, title(`website_url`))
}
func TestQuote(t *testing.T) {
expectStr(t, "`test`", quote(`test`))
expectStr(t, "`furter testing`", quote(`furter testing`))
}