MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestCreateTableStatementPool

Function TestCreateTableStatementPool

pkg/sql/ast/pool_ddl_test.go:25–118  ·  view source on GitHub ↗

============================================================ CreateTableStatement pool tests ============================================================

(t *testing.T)

Source from the content-addressed store, hash-verified

23// ============================================================
24
25func TestCreateTableStatementPool(t *testing.T) {
26 t.Run("Get returns non-nil", func(t *testing.T) {
27 stmt := GetCreateTableStatement()
28 if stmt == nil {
29 t.Fatal("GetCreateTableStatement() returned nil")
30 }
31 PutCreateTableStatement(stmt)
32 })
33
34 t.Run("Put nil is safe", func(t *testing.T) {
35 PutCreateTableStatement(nil) // must not panic
36 })
37
38 t.Run("Fields zeroed after Put", func(t *testing.T) {
39 stmt := GetCreateTableStatement()
40 stmt.Name = "users"
41 stmt.IfNotExists = true
42 stmt.Temporary = true
43 stmt.Columns = append(stmt.Columns, ColumnDef{
44 Name: "id",
45 Type: "INT",
46 Constraints: []ColumnConstraint{
47 {
48 Type: "NOT NULL",
49 Default: &LiteralValue{Value: "0"},
50 Check: &BinaryExpression{Left: &Identifier{Name: "id"}, Operator: ">", Right: &LiteralValue{Value: "0"}},
51 },
52 },
53 })
54 stmt.Constraints = append(stmt.Constraints, TableConstraint{
55 Name: "pk",
56 Type: "PRIMARY KEY",
57 Check: &BinaryExpression{Left: &Identifier{Name: "x"}, Operator: "=", Right: &LiteralValue{Value: "1"}},
58 })
59 stmt.PartitionBy = &PartitionBy{
60 Type: "RANGE",
61 Columns: []string{"created_at"},
62 Boundary: []Expression{
63 &LiteralValue{Value: "2024-01-01"},
64 },
65 }
66 stmt.Partitions = append(stmt.Partitions, PartitionDefinition{
67 Name: "p0",
68 LessThan: &LiteralValue{Value: "2024-01-01"},
69 From: &LiteralValue{Value: "2024-01-01"},
70 To: &LiteralValue{Value: "2025-01-01"},
71 InValues: []Expression{&LiteralValue{Value: "a"}},
72 })
73 stmt.Inherits = append(stmt.Inherits, "parent_table")
74 stmt.Options = append(stmt.Options, TableOption{Name: "ENGINE", Value: "InnoDB"})
75
76 PutCreateTableStatement(stmt)
77
78 if stmt.Name != "" {
79 t.Errorf("Name not cleared, got %q", stmt.Name)
80 }
81 if stmt.IfNotExists {
82 t.Error("IfNotExists not cleared")

Callers

nothing calls this directly

Calls 5

GetCreateTableStatementFunction · 0.85
PutCreateTableStatementFunction · 0.85
RunMethod · 0.80
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected