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

Function TestMergeStatement_SQL

pkg/sql/ast/sql_coverage_test.go:179–199  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

177}
178
179func TestMergeStatement_SQL(t *testing.T) {
180 stmt := &MergeStatement{
181 TargetTable: TableReference{Name: "target"},
182 TargetAlias: "t",
183 SourceTable: TableReference{Name: "source"},
184 SourceAlias: "s",
185 OnCondition: &BinaryExpression{Left: &Identifier{Name: "t.id"}, Operator: "=", Right: &Identifier{Name: "s.id"}},
186 WhenClauses: []*MergeWhenClause{
187 {Type: "MATCHED", Action: &MergeAction{ActionType: "UPDATE", SetClauses: []SetClause{{Column: "name", Value: &Identifier{Name: "s.name"}}}}},
188 {Type: "NOT_MATCHED", Action: &MergeAction{ActionType: "INSERT", Columns: []string{"id"}, Values: []Expression{&Identifier{Name: "s.id"}}}},
189 {Type: "NOT_MATCHED_BY_SOURCE", Action: &MergeAction{ActionType: "DELETE"}},
190 {Type: "MATCHED", Condition: &Identifier{Name: "s.active"}, Action: &MergeAction{ActionType: "UPDATE", SetClauses: []SetClause{{Column: "x", Value: &LiteralValue{Value: "1"}}}}},
191 },
192 }
193 sql := stmt.SQL()
194 for _, want := range []string{"MERGE INTO", "USING", "ON", "WHEN MATCHED", "WHEN NOT MATCHED", "NOT MATCHED BY SOURCE", "THEN DELETE"} {
195 if !strings.Contains(sql, want) {
196 t.Errorf("missing %q in: %s", want, sql)
197 }
198 }
199}
200
201func TestMergeAction_InsertDefaultValues(t *testing.T) {
202 stmt := &MergeStatement{

Callers

nothing calls this directly

Calls 2

SQLMethod · 0.95
ErrorfMethod · 0.65

Tested by

no test coverage detected