============================================================ AlterTableStatement pool tests ============================================================
(t *testing.T)
| 122 | // ============================================================ |
| 123 | |
| 124 | func TestAlterTableStatementPool(t *testing.T) { |
| 125 | t.Run("Get returns non-nil", func(t *testing.T) { |
| 126 | stmt := GetAlterTableStatement() |
| 127 | if stmt == nil { |
| 128 | t.Fatal("GetAlterTableStatement() returned nil") |
| 129 | } |
| 130 | PutAlterTableStatement(stmt) |
| 131 | }) |
| 132 | |
| 133 | t.Run("Put nil is safe", func(t *testing.T) { |
| 134 | PutAlterTableStatement(nil) |
| 135 | }) |
| 136 | |
| 137 | t.Run("Fields zeroed after Put", func(t *testing.T) { |
| 138 | stmt := GetAlterTableStatement() |
| 139 | stmt.Table = "users" |
| 140 | stmt.Actions = append(stmt.Actions, AlterTableAction{ |
| 141 | Type: "ADD COLUMN", |
| 142 | ColumnName: "email", |
| 143 | ColumnDef: &ColumnDef{ |
| 144 | Name: "email", |
| 145 | Type: "VARCHAR(255)", |
| 146 | Constraints: []ColumnConstraint{ |
| 147 | { |
| 148 | Type: "DEFAULT", |
| 149 | Default: &LiteralValue{Value: "''"}, |
| 150 | Check: &BinaryExpression{Left: &Identifier{Name: "email"}, Operator: "IS NOT", Right: &LiteralValue{Value: "NULL"}}, |
| 151 | }, |
| 152 | }, |
| 153 | }, |
| 154 | Constraint: &TableConstraint{ |
| 155 | Type: "UNIQUE", |
| 156 | Check: &BinaryExpression{Left: &Identifier{Name: "email"}, Operator: "!=", Right: &LiteralValue{Value: "''"}}, |
| 157 | }, |
| 158 | }) |
| 159 | |
| 160 | PutAlterTableStatement(stmt) |
| 161 | |
| 162 | if stmt.Table != "" { |
| 163 | t.Errorf("Table not cleared, got %q", stmt.Table) |
| 164 | } |
| 165 | if len(stmt.Actions) != 0 { |
| 166 | t.Errorf("Actions not cleared, len=%d", len(stmt.Actions)) |
| 167 | } |
| 168 | }) |
| 169 | |
| 170 | t.Run("Pool roundtrip reuse", func(t *testing.T) { |
| 171 | stmt1 := GetAlterTableStatement() |
| 172 | stmt1.Table = "products" |
| 173 | PutAlterTableStatement(stmt1) |
| 174 | |
| 175 | stmt2 := GetAlterTableStatement() |
| 176 | if stmt2.Table != "" { |
| 177 | t.Errorf("Reused statement not clean, Table=%q", stmt2.Table) |
| 178 | } |
| 179 | PutAlterTableStatement(stmt2) |
| 180 | }) |
| 181 | } |
nothing calls this directly
no test coverage detected