Skip to content

Commit

Permalink
added UT for update call
Browse files Browse the repository at this point in the history
  • Loading branch information
Vivek Yadav committed Nov 15, 2024
1 parent e54c4de commit 95b5c95
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
11 changes: 0 additions & 11 deletions webv2/api/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,6 @@ func UpdateCheckConstraint(w http.ResponseWriter, r *http.Request) {
if err != nil {
http.Error(w, fmt.Sprintf("Body Read Error : %v", err), http.StatusInternalServerError)
}
println(tableId)
println(reqBody)
// internal.ToSpannerCheckConstraintName()
sessionState := session.GetSessionState()
if sessionState.Conv == nil || sessionState.Driver == "" {
Expand All @@ -512,15 +510,6 @@ func UpdateCheckConstraint(w http.ResponseWriter, r *http.Request) {
return
}

// check for if requested data can be migrated to spanner

// for _, oldCk := range sessionState.Conv.SrcSchema[tableId].CheckConstraints {
// println(oldCk.Name)
// // if newFk.Id == oldFk.Id && newFk.Name != oldFk.Name && newFk.Name != "" {
// // newNames = append(newNames, strings.ToLower(newFk.Name))
// // }
// }

sp := sessionState.Conv.SpSchema[tableId]

sp.CheckConstraint = newCKs
Expand Down
40 changes: 40 additions & 0 deletions webv2/api/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2541,3 +2541,43 @@ func TestGetAutoGenMapMySQL(t *testing.T) {
}

}

func TestUpdateCheckConstraint(t *testing.T) {
sessionState := session.GetSessionState()
sessionState.Driver = constants.MYSQL
sessionState.Conv = internal.MakeConv()

tableID := "table1"

expectedCheckConstraint := []ddl.Checkconstraint{
{Id: "ck1", Name: "check_1", Expr: "(age > 18)"},
{Id: "ck2", Name: "check_2", Expr: "(age < 99)"},
}

checkConstraints := []schema.CheckConstraints{
{Id: "ck1", Name: "check_1", Expr: "(age > 18)"},
{Id: "ck2", Name: "check_2", Expr: "(age < 99)"},
}

body, err := json.Marshal(checkConstraints)
assert.NoError(t, err)

req, err := http.NewRequest("POST", "update/cks", bytes.NewBuffer(body))
assert.NoError(t, err)

q := req.URL.Query()
q.Add("table", tableID)
req.URL.RawQuery = q.Encode()

rr := httptest.NewRecorder()

handler := http.HandlerFunc(api.UpdateCheckConstraint)

handler.ServeHTTP(rr, req)

assert.Equal(t, http.StatusOK, rr.Code)

updatedSp := sessionState.Conv.SpSchema[tableID]

assert.Equal(t, expectedCheckConstraint, updatedSp.CheckConstraint)
}

0 comments on commit 95b5c95

Please sign in to comment.