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

Function TestUpdateStatementPool

pkg/sql/ast/pool_test.go:68–109  ·  view source on GitHub ↗

Test UpdateStatement pool

(t *testing.T)

Source from the content-addressed store, hash-verified

66
67// Test UpdateStatement pool
68func TestUpdateStatementPool(t *testing.T) {
69 t.Run("Get and Put", func(t *testing.T) {
70 // Get from pool
71 stmt := GetUpdateStatement()
72 if stmt == nil {
73 t.Fatal("GetUpdateStatement() returned nil")
74 }
75
76 // Use it
77 stmt.TableName = "users"
78 stmt.Assignments = []UpdateExpression{
79 {
80 Column: &Identifier{Name: "email"},
81 Value: &LiteralValue{Value: "new@example.com"},
82 },
83 }
84 stmt.Where = &BinaryExpression{
85 Left: &Identifier{Name: "id"},
86 Operator: "=",
87 Right: &LiteralValue{Value: "1"},
88 }
89
90 // Return to pool
91 PutUpdateStatement(stmt)
92
93 // Verify it was cleaned
94 if stmt.TableName != "" {
95 t.Errorf("TableName not cleared, got %v", stmt.TableName)
96 }
97 if len(stmt.Assignments) != 0 {
98 t.Errorf("Updates not cleared, len = %d", len(stmt.Assignments))
99 }
100 if stmt.Where != nil {
101 t.Errorf("Where not cleared, got %v", stmt.Where)
102 }
103 })
104
105 t.Run("Put nil statement", func(t *testing.T) {
106 // Should not panic
107 PutUpdateStatement(nil)
108 })
109}
110
111// Test DeleteStatement pool
112func TestDeleteStatementPool(t *testing.T) {

Callers

nothing calls this directly

Calls 4

GetUpdateStatementFunction · 0.85
PutUpdateStatementFunction · 0.85
RunMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected