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

Function TestCreateMaterializedViewStatementPool

pkg/sql/ast/pool_ddl_test.go:403–462  ·  view source on GitHub ↗

============================================================ CreateMaterializedViewStatement pool tests ============================================================

(t *testing.T)

Source from the content-addressed store, hash-verified

401// ============================================================
402
403func TestCreateMaterializedViewStatementPool(t *testing.T) {
404 t.Run("Get returns non-nil", func(t *testing.T) {
405 stmt := GetCreateMaterializedViewStatement()
406 if stmt == nil {
407 t.Fatal("GetCreateMaterializedViewStatement() returned nil")
408 }
409 PutCreateMaterializedViewStatement(stmt)
410 })
411
412 t.Run("Put nil is safe", func(t *testing.T) {
413 PutCreateMaterializedViewStatement(nil)
414 })
415
416 t.Run("Fields zeroed after Put", func(t *testing.T) {
417 withData := true
418 inner := GetSelectStatement()
419 inner.TableName = "events"
420
421 stmt := GetCreateMaterializedViewStatement()
422 stmt.Name = "mv_events"
423 stmt.IfNotExists = true
424 stmt.Columns = append(stmt.Columns, "id", "ts")
425 stmt.Query = inner
426 stmt.WithData = &withData
427 stmt.Tablespace = "pg_default"
428
429 PutCreateMaterializedViewStatement(stmt)
430
431 if stmt.Name != "" {
432 t.Errorf("Name not cleared, got %q", stmt.Name)
433 }
434 if stmt.IfNotExists {
435 t.Error("IfNotExists not cleared")
436 }
437 if len(stmt.Columns) != 0 {
438 t.Errorf("Columns not cleared, len=%d", len(stmt.Columns))
439 }
440 if stmt.Query != nil {
441 t.Error("Query not cleared")
442 }
443 if stmt.WithData != nil {
444 t.Error("WithData not cleared")
445 }
446 if stmt.Tablespace != "" {
447 t.Errorf("Tablespace not cleared, got %q", stmt.Tablespace)
448 }
449 })
450
451 t.Run("Pool roundtrip reuse", func(t *testing.T) {
452 stmt1 := GetCreateMaterializedViewStatement()
453 stmt1.Name = "my_mv"
454 PutCreateMaterializedViewStatement(stmt1)
455
456 stmt2 := GetCreateMaterializedViewStatement()
457 if stmt2.Name != "" {
458 t.Errorf("Reused statement not clean, Name=%q", stmt2.Name)
459 }
460 PutCreateMaterializedViewStatement(stmt2)

Callers

nothing calls this directly

Calls 6

GetSelectStatementFunction · 0.85
RunMethod · 0.80
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected