diff --git a/sources/common/toddl.go b/sources/common/toddl.go index 371b1bc67..1b2127aca 100644 --- a/sources/common/toddl.go +++ b/sources/common/toddl.go @@ -294,7 +294,6 @@ func (ss *SchemaToSpannerImpl) SchemaToSpannerDDLHelper(conv *internal.Conv, tod Comment: comment, Id: srcTable.Id, } - return nil } diff --git a/sources/common/toddl_test.go b/sources/common/toddl_test.go index 43d133d1f..7d948ecdf 100644 --- a/sources/common/toddl_test.go +++ b/sources/common/toddl_test.go @@ -451,11 +451,6 @@ func Test_cvtCheckContraint(t *testing.T) { Expr: "age != 0", ExprId: "expr3", }, - { - Id: "cc3", - Name: "@invalid_name", // incompatabile name - Expr: "age != 0", - }, } spSchema := []ddl.CheckConstraint{ { @@ -476,11 +471,6 @@ func Test_cvtCheckContraint(t *testing.T) { Expr: "age != 0", ExprId: "expr3", }, - { - Id: "cc3", - Name: "Ainvalid_name", - Expr: "age != 0", - }, } result := cvtCheckConstraint(conv, srcSchema) assert.Equal(t, spSchema, result) diff --git a/webv2/api/schema_test.go b/webv2/api/schema_test.go index 5d22cd414..198cc0210 100644 --- a/webv2/api/schema_test.go +++ b/webv2/api/schema_test.go @@ -2731,106 +2731,3 @@ func TestVerifyCheckConstraintExpressions(t *testing.T) { }) } } - -func TestVerifyCheckConstraintExpressions(t *testing.T) { - tests := []struct { - name string - expressions []ddl.CheckConstraint - expectedResults []internal.ExpressionVerificationOutput - expectedResponse bool - }{ - { - name: "AllValidExpressions", - expressions: []ddl.CheckConstraint{ - {Expr: "(col1 > 0)", ExprId: "expr1", Name: "check1"}, - }, - expectedResults: []internal.ExpressionVerificationOutput{ - {Result: true, Err: nil, ExpressionDetail: internal.ExpressionDetail{Expression: "(col1 > 0)", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c1", "checkConstraintName": "check1"}, ExpressionId: "expr1"}}, - }, - expectedResponse: false, - }, - { - name: "InvalidSyntaxError", - expressions: []ddl.CheckConstraint{ - {Expr: "(col1 > 0)", ExprId: "expr1", Name: "check1"}, - {Expr: "(col1 > 18", ExprId: "expr2", Name: "check2"}, - }, - expectedResults: []internal.ExpressionVerificationOutput{ - {Result: true, Err: nil, ExpressionDetail: internal.ExpressionDetail{Expression: "(col1 > 0)", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c1", "checkConstraintName": "check1"}, ExpressionId: "expr1"}}, - {Result: false, Err: errors.New("Syntax error ..."), ExpressionDetail: internal.ExpressionDetail{Expression: "(col1 > 18", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c1", "checkConstraintName": "check2"}, ExpressionId: "expr2"}}, - }, - expectedResponse: true, - }, - { - name: "NameError", - expressions: []ddl.CheckConstraint{ - {Expr: "(col1 > 0)", ExprId: "expr1", Name: "check1"}, - {Expr: "(col1 > 18)", ExprId: "expr2", Name: "check2"}, - }, - expectedResults: []internal.ExpressionVerificationOutput{ - {Result: true, Err: nil, ExpressionDetail: internal.ExpressionDetail{Expression: "(col1 > 0)", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c1", "checkConstraintName": "check1"}, ExpressionId: "expr1"}}, - {Result: false, Err: errors.New("Unrecognized name ..."), ExpressionDetail: internal.ExpressionDetail{Expression: "(col1 > 18)", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c1", "checkConstraintName": "check2"}, ExpressionId: "expr2"}}, - }, - expectedResponse: true, - }, - { - name: "TypeError", - expressions: []ddl.CheckConstraint{ - {Expr: "(col1 > 0)", ExprId: "expr1", Name: "check1"}, - {Expr: "(col1 > 18)", ExprId: "expr2", Name: "check2"}, - }, - expectedResults: []internal.ExpressionVerificationOutput{ - {Result: true, Err: nil, ExpressionDetail: internal.ExpressionDetail{Expression: "(col1 > 0)", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c1", "checkConstraintName": "check1"}, ExpressionId: "expr1"}}, - {Result: false, Err: errors.New("No matching signature for operator"), ExpressionDetail: internal.ExpressionDetail{Expression: "(col1 > 18)", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c1", "checkConstraintName": "check2"}, ExpressionId: "expr2"}}, - }, - expectedResponse: true, - }, - } - - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - mockAccessor := new(mocks.MockExpressionVerificationAccessor) - handler := &api.ExpressionsVerificationHandler{ExpressionVerificationAccessor: mockAccessor} - - req, err := http.NewRequest("POST", "/verifyCheckConstraintExpression", nil) - if err != nil { - t.Fatal(err) - } - - ctx := req.Context() - sessionState := session.GetSessionState() - sessionState.Driver = constants.MYSQL - sessionState.SpannerInstanceID = "foo" - sessionState.SpannerProjectId = "daring-12" - sessionState.Conv = internal.MakeConv() - sessionState.Conv.SpSchema = map[string]ddl.CreateTable{ - "t1": { - Name: "table1", - Id: "t1", - PrimaryKeys: []ddl.IndexKey{{ColId: "c1"}}, - ColIds: []string{"c1"}, - ColDefs: map[string]ddl.ColumnDef{ - "c1": {Name: "col1", Id: "c1", T: ddl.Type{Name: ddl.Int64}}, - }, - CheckConstraints: tc.expressions, - }, - } - - mockAccessor.On("VerifyExpressions", ctx, mock.Anything).Return(internal.VerifyExpressionsOutput{ - ExpressionVerificationOutputList: tc.expectedResults, - }) - - rr := httptest.NewRecorder() - handler.VerifyCheckConstraintExpression(rr, req) - - assert.Equal(t, http.StatusOK, rr.Code) - - var response bool - err = json.NewDecoder(rr.Body).Decode(&response) - if err != nil { - t.Fatal(err) - } - assert.Equal(t, tc.expectedResponse, response) - }) - } -}