-
Notifications
You must be signed in to change notification settings - Fork 91
/
builder_sqlite_test.go
89 lines (74 loc) · 2.6 KB
/
builder_sqlite_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
// Copyright 2016 Qiang Xue. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package dbx
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSqliteBuilder_QuoteSimpleTableName(t *testing.T) {
b := getSqliteBuilder()
assert.Equal(t, b.QuoteSimpleTableName(`abc`), "`abc`", "t1")
assert.Equal(t, b.QuoteSimpleTableName("`abc`"), "`abc`", "t2")
assert.Equal(t, b.QuoteSimpleTableName(`{{abc}}`), "`{{abc}}`", "t3")
assert.Equal(t, b.QuoteSimpleTableName(`a.bc`), "`a.bc`", "t4")
}
func TestSqliteBuilder_QuoteSimpleColumnName(t *testing.T) {
b := getSqliteBuilder()
assert.Equal(t, b.QuoteSimpleColumnName(`abc`), "`abc`", "t1")
assert.Equal(t, b.QuoteSimpleColumnName("`abc`"), "`abc`", "t2")
assert.Equal(t, b.QuoteSimpleColumnName(`{{abc}}`), "`{{abc}}`", "t3")
assert.Equal(t, b.QuoteSimpleColumnName(`a.bc`), "`a.bc`", "t4")
assert.Equal(t, b.QuoteSimpleColumnName(`*`), `*`, "t5")
}
func TestSqliteBuilder_DropIndex(t *testing.T) {
b := getSqliteBuilder()
q := b.DropIndex("users", "idx")
assert.Equal(t, q.SQL(), "DROP INDEX `idx`", "t1")
}
func TestSqliteBuilder_TruncateTable(t *testing.T) {
b := getSqliteBuilder()
q := b.TruncateTable("users")
assert.Equal(t, q.SQL(), "DELETE FROM `users`", "t1")
}
func TestSqliteBuilder_DropColumn(t *testing.T) {
b := getSqliteBuilder()
q := b.DropColumn("users", "age")
assert.NotEqual(t, q.LastError, nil, "t1")
}
func TestSqliteBuilder_RenameColumn(t *testing.T) {
b := getSqliteBuilder()
q := b.RenameColumn("users", "name", "username")
assert.NotEqual(t, q.LastError, nil, "t1")
}
func TestSqliteBuilder_AlterColumn(t *testing.T) {
b := getSqliteBuilder()
q := b.AlterColumn("users", "name", "int")
assert.NotEqual(t, q.LastError, nil, "t1")
}
func TestSqliteBuilder_AddPrimaryKey(t *testing.T) {
b := getSqliteBuilder()
q := b.AddPrimaryKey("users", "pk", "id1", "id2")
assert.NotEqual(t, q.LastError, nil, "t1")
}
func TestSqliteBuilder_DropPrimaryKey(t *testing.T) {
b := getSqliteBuilder()
q := b.DropPrimaryKey("users", "pk")
assert.NotEqual(t, q.LastError, nil, "t1")
}
func TestSqliteBuilder_AddForeignKey(t *testing.T) {
b := getSqliteBuilder()
q := b.AddForeignKey("users", "fk", []string{"p1", "p2"}, []string{"f1", "f2"}, "profile", "opt")
assert.NotEqual(t, q.LastError, nil, "t1")
}
func TestSqliteBuilder_DropForeignKey(t *testing.T) {
b := getSqliteBuilder()
q := b.DropForeignKey("users", "fk")
assert.NotEqual(t, q.LastError, nil, "t1")
}
func getSqliteBuilder() Builder {
db := getDB()
b := NewSqliteBuilder(db, db.sqlDB)
db.Builder = b
return b
}