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

Function TestCreateViewStatementPool

pkg/sql/ast/pool_ddl_test.go:335–397  ·  view source on GitHub ↗

============================================================ CreateViewStatement pool tests ============================================================

(t *testing.T)

Source from the content-addressed store, hash-verified

333// ============================================================
334
335func TestCreateViewStatementPool(t *testing.T) {
336 t.Run("Get returns non-nil", func(t *testing.T) {
337 stmt := GetCreateViewStatement()
338 if stmt == nil {
339 t.Fatal("GetCreateViewStatement() returned nil")
340 }
341 PutCreateViewStatement(stmt)
342 })
343
344 t.Run("Put nil is safe", func(t *testing.T) {
345 PutCreateViewStatement(nil)
346 })
347
348 t.Run("Fields zeroed after Put", func(t *testing.T) {
349 inner := GetSelectStatement()
350 inner.TableName = "users"
351
352 stmt := GetCreateViewStatement()
353 stmt.Name = "active_users"
354 stmt.OrReplace = true
355 stmt.Temporary = true
356 stmt.IfNotExists = true
357 stmt.Columns = append(stmt.Columns, "id", "name")
358 stmt.Query = inner
359 stmt.WithOption = "CASCADED"
360
361 PutCreateViewStatement(stmt)
362
363 if stmt.Name != "" {
364 t.Errorf("Name not cleared, got %q", stmt.Name)
365 }
366 if stmt.OrReplace {
367 t.Error("OrReplace not cleared")
368 }
369 if stmt.Temporary {
370 t.Error("Temporary not cleared")
371 }
372 if stmt.IfNotExists {
373 t.Error("IfNotExists not cleared")
374 }
375 if len(stmt.Columns) != 0 {
376 t.Errorf("Columns not cleared, len=%d", len(stmt.Columns))
377 }
378 if stmt.Query != nil {
379 t.Error("Query not cleared")
380 }
381 if stmt.WithOption != "" {
382 t.Errorf("WithOption not cleared, got %q", stmt.WithOption)
383 }
384 })
385
386 t.Run("Pool roundtrip reuse", func(t *testing.T) {
387 stmt1 := GetCreateViewStatement()
388 stmt1.Name = "my_view"
389 PutCreateViewStatement(stmt1)
390
391 stmt2 := GetCreateViewStatement()
392 if stmt2.Name != "" {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected