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

Function TestCreateIndexStatementPool

pkg/sql/ast/pool_ddl_test.go:187–250  ·  view source on GitHub ↗

============================================================ CreateIndexStatement pool tests ============================================================

(t *testing.T)

Source from the content-addressed store, hash-verified

185// ============================================================
186
187func TestCreateIndexStatementPool(t *testing.T) {
188 t.Run("Get returns non-nil", func(t *testing.T) {
189 stmt := GetCreateIndexStatement()
190 if stmt == nil {
191 t.Fatal("GetCreateIndexStatement() returned nil")
192 }
193 PutCreateIndexStatement(stmt)
194 })
195
196 t.Run("Put nil is safe", func(t *testing.T) {
197 PutCreateIndexStatement(nil)
198 })
199
200 t.Run("Fields zeroed after Put", func(t *testing.T) {
201 stmt := GetCreateIndexStatement()
202 stmt.Name = "idx_users_email"
203 stmt.Table = "users"
204 stmt.Unique = true
205 stmt.IfNotExists = true
206 stmt.Using = "BTREE"
207 stmt.Columns = append(stmt.Columns, IndexColumn{Column: "email", Direction: "ASC"})
208 stmt.Where = &BinaryExpression{
209 Left: &Identifier{Name: "active"},
210 Operator: "=",
211 Right: &LiteralValue{Value: "true"},
212 }
213
214 PutCreateIndexStatement(stmt)
215
216 if stmt.Name != "" {
217 t.Errorf("Name not cleared, got %q", stmt.Name)
218 }
219 if stmt.Table != "" {
220 t.Errorf("Table not cleared, got %q", stmt.Table)
221 }
222 if stmt.Unique {
223 t.Error("Unique not cleared")
224 }
225 if stmt.IfNotExists {
226 t.Error("IfNotExists not cleared")
227 }
228 if stmt.Using != "" {
229 t.Errorf("Using not cleared, got %q", stmt.Using)
230 }
231 if len(stmt.Columns) != 0 {
232 t.Errorf("Columns not cleared, len=%d", len(stmt.Columns))
233 }
234 if stmt.Where != nil {
235 t.Error("Where not cleared")
236 }
237 })
238
239 t.Run("Pool roundtrip reuse", func(t *testing.T) {
240 stmt1 := GetCreateIndexStatement()
241 stmt1.Name = "idx_foo"
242 PutCreateIndexStatement(stmt1)
243
244 stmt2 := GetCreateIndexStatement()

Callers

nothing calls this directly

Calls 5

GetCreateIndexStatementFunction · 0.85
PutCreateIndexStatementFunction · 0.85
RunMethod · 0.80
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected