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

Function TestMergeStatementPool

pkg/sql/ast/pool_ddl_test.go:256–329  ·  view source on GitHub ↗

============================================================ MergeStatement pool tests ============================================================

(t *testing.T)

Source from the content-addressed store, hash-verified

254// ============================================================
255
256func TestMergeStatementPool(t *testing.T) {
257 t.Run("Get returns non-nil", func(t *testing.T) {
258 stmt := GetMergeStatement()
259 if stmt == nil {
260 t.Fatal("GetMergeStatement() returned nil")
261 }
262 PutMergeStatement(stmt)
263 })
264
265 t.Run("Put nil is safe", func(t *testing.T) {
266 PutMergeStatement(nil)
267 })
268
269 t.Run("Fields zeroed after Put", func(t *testing.T) {
270 stmt := GetMergeStatement()
271 stmt.TargetTable = TableReference{Name: "target"}
272 stmt.TargetAlias = "t"
273 stmt.SourceTable = TableReference{Name: "source"}
274 stmt.SourceAlias = "s"
275 stmt.OnCondition = &BinaryExpression{
276 Left: &Identifier{Name: "t.id"},
277 Operator: "=",
278 Right: &Identifier{Name: "s.id"},
279 }
280 stmt.WhenClauses = append(stmt.WhenClauses, &MergeWhenClause{
281 Type: "MATCHED",
282 Condition: &BinaryExpression{Left: &Identifier{Name: "x"}, Operator: "=", Right: &LiteralValue{Value: "1"}},
283 Action: &MergeAction{
284 ActionType: "UPDATE",
285 SetClauses: []SetClause{
286 {Column: "name", Value: &LiteralValue{Value: "new_name"}},
287 },
288 Values: []Expression{&LiteralValue{Value: "v1"}},
289 },
290 })
291 stmt.Output = append(stmt.Output, &Identifier{Name: "inserted.id"})
292
293 PutMergeStatement(stmt)
294
295 if stmt.TargetAlias != "" {
296 t.Errorf("TargetAlias not cleared, got %q", stmt.TargetAlias)
297 }
298 if stmt.SourceAlias != "" {
299 t.Errorf("SourceAlias not cleared, got %q", stmt.SourceAlias)
300 }
301 if stmt.OnCondition != nil {
302 t.Error("OnCondition not cleared")
303 }
304 if len(stmt.WhenClauses) != 0 {
305 t.Errorf("WhenClauses not cleared, len=%d", len(stmt.WhenClauses))
306 }
307 if len(stmt.Output) != 0 {
308 t.Errorf("Output not cleared, len=%d", len(stmt.Output))
309 }
310 if stmt.TargetTable.Name != "" {
311 t.Errorf("TargetTable not cleared, Name=%q", stmt.TargetTable.Name)
312 }
313 if stmt.SourceTable.Name != "" {

Callers

nothing calls this directly

Calls 5

GetMergeStatementFunction · 0.85
PutMergeStatementFunction · 0.85
RunMethod · 0.80
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected