MCPcopy
hub / github.com/writefreely/writefreely / TestAlterTableSqlBuilder_ToSQL

Function TestAlterTableSqlBuilder_ToSQL

db/alter_test.go:5–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3import "testing"
4
5func TestAlterTableSqlBuilder_ToSQL(t *testing.T) {
6 type fields struct {
7 Dialect DialectType
8 Name string
9 Changes []string
10 }
11 tests := []struct {
12 name string
13 builder *AlterTableSqlBuilder
14 want string
15 wantErr bool
16 }{
17 {
18 name: "MySQL add int",
19 builder: DialectMySQL.
20 AlterTable("the_table").
21 AddColumn(DialectMySQL.Column("the_col", ColumnTypeInteger, UnsetSize)),
22 want: "ALTER TABLE the_table ADD COLUMN the_col INT NOT NULL",
23 wantErr: false,
24 },
25 {
26 name: "MySQL add string",
27 builder: DialectMySQL.
28 AlterTable("the_table").
29 AddColumn(DialectMySQL.Column("the_col", ColumnTypeVarChar, OptionalInt{true, 128})),
30 want: "ALTER TABLE the_table ADD COLUMN the_col VARCHAR(128) NOT NULL",
31 wantErr: false,
32 },
33
34 {
35 name: "MySQL add int and string",
36 builder: DialectMySQL.
37 AlterTable("the_table").
38 AddColumn(DialectMySQL.Column("first_col", ColumnTypeInteger, UnsetSize)).
39 AddColumn(DialectMySQL.Column("second_col", ColumnTypeVarChar, OptionalInt{true, 128})),
40 want: "ALTER TABLE the_table ADD COLUMN first_col INT NOT NULL, ADD COLUMN second_col VARCHAR(128) NOT NULL",
41 wantErr: false,
42 },
43 }
44 for _, tt := range tests {
45 t.Run(tt.name, func(t *testing.T) {
46 got, err := tt.builder.ToSQL()
47 if (err != nil) != tt.wantErr {
48 t.Errorf("ToSQL() error = %v, wantErr %v", err, tt.wantErr)
49 return
50 }
51 if got != tt.want {
52 t.Errorf("ToSQL() got = %v, want %v", got, tt.want)
53 }
54 })
55 }
56}

Callers

nothing calls this directly

Calls 4

AddColumnMethod · 0.80
AlterTableMethod · 0.80
ToSQLMethod · 0.65
ColumnMethod · 0.45

Tested by

no test coverage detected