Skip to content

Commit

Permalink
Merge branch 'master' into support-check-constraint-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
akashthawaitcc committed Dec 26, 2024
2 parents 0c41388 + 731346f commit f220876
Showing 1 changed file with 0 additions and 179 deletions.
179 changes: 0 additions & 179 deletions sources/common/toddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,183 +577,4 @@ func TestSpannerSchemaApplyExpressions(t *testing.T) {
assert.Equal(t, tc.expectedConv, tc.conv)
})
}
func Test_cvtCheckContraint(t *testing.T) {

conv := internal.MakeConv()
srcSchema := []schema.CheckConstraint{
{
Id: "cc1",
Name: "check_1",
Expr: "age > 0",
},
{
Id: "cc2",
Name: "check_2",
Expr: "age < 99",
},
{
Id: "cc3",
Name: "@invalid_name", // incompatabile name
Expr: "age != 0",
},
}
spSchema := []ddl.CheckConstraint{
{
Id: "cc1",
Name: "check_1",
Expr: "age > 0",
},
{
Id: "cc2",
Name: "check_2",
Expr: "age < 99",
},
{
Id: "cc3",
Name: "Ainvalid_name",
Expr: "age != 0",
},
}
result := cvtCheckConstraint(conv, srcSchema)
assert.Equal(t, spSchema, result)
}

func TestSpannerSchemaApplyExpressions(t *testing.T) {
makeConv := func() *internal.Conv {
conv := internal.MakeConv()
conv.SchemaIssues = make(map[string]internal.TableIssues)
conv.SchemaIssues["table1"] = internal.TableIssues{
ColumnLevelIssues: make(map[string][]internal.SchemaIssue),
}
conv.SpSchema = ddl.Schema{
"table1": {
ColDefs: map[string]ddl.ColumnDef{
"col1": {},
},
},
}
return conv
}

makeResultConv := func(SpSchema ddl.Schema, SchemaIssues map[string]internal.TableIssues) *internal.Conv {
conv := internal.MakeConv()
conv.SpSchema = SpSchema
conv.SchemaIssues = SchemaIssues
return conv
}

testCases := []struct {
name string
conv *internal.Conv
expressions internal.VerifyExpressionsOutput
expectedConv *internal.Conv
}{
{
name: "successful default value application",
conv: makeConv(),
expressions: internal.VerifyExpressionsOutput{
ExpressionVerificationOutputList: []internal.ExpressionVerificationOutput{
{
Result: true,
ExpressionDetail: internal.ExpressionDetail{
Type: "DEFAULT",
ExpressionId: "expr1",
Expression: "SELECT 1",
Metadata: map[string]string{"TableId": "table1", "ColId": "col1"},
},
},
},
},
expectedConv: makeResultConv(
ddl.Schema{
"table1": {
ColDefs: map[string]ddl.ColumnDef{
"col1": {
DefaultValue: ddl.DefaultValue{
IsPresent: true,
Value: ddl.Expression{
ExpressionId: "expr1",
Statement: "SELECT 1",
},
},
},
},
},
}, map[string]internal.TableIssues{
"table1": {
ColumnLevelIssues: make(map[string][]internal.SchemaIssue),
},
}),
},
{
name: "failed default value application",
conv: makeConv(),
expressions: internal.VerifyExpressionsOutput{
ExpressionVerificationOutputList: []internal.ExpressionVerificationOutput{
{
Result: false,
ExpressionDetail: internal.ExpressionDetail{
Type: "DEFAULT",
ExpressionId: "expr1",
Expression: "SELECT 1",
Metadata: map[string]string{"TableId": "table1", "ColId": "col1"},
},
},
},
},
expectedConv: makeResultConv(
ddl.Schema{
"table1": {
ColDefs: map[string]ddl.ColumnDef{
"col1": {},
},
},
},
map[string]internal.TableIssues{
"table1": {
ColumnLevelIssues: map[string][]internal.SchemaIssue{
"col1": {internal.DefaultValue},
},
},
}),
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
spannerSchemaApplyExpressions(tc.conv, tc.expressions)
assert.Equal(t, tc.expectedConv, tc.conv)
})
}
}

func Test_cvtCheckContraint(t *testing.T) {

conv := internal.MakeConv()
srcSchema := []schema.CheckConstraint{
{
Id: "ck1",
Name: "check_1",
Expr: "age > 0",
},
{
Id: "ck1",
Name: "check_2",
Expr: "age < 99",
},
}
spSchema := []ddl.CheckConstraint{
{
Id: "ck1",
Name: "check_1",
Expr: "age > 0",
},
{
Id: "ck1",
Name: "check_2",
Expr: "age < 99",
},
}
result := cvtCheckConstraint(conv, srcSchema)
assert.Equal(t, spSchema, result)
}

0 comments on commit f220876

Please sign in to comment.