You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

basic_undo_builder_test.go 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package exec
  18. import (
  19. "testing"
  20. "github.com/stretchr/testify/assert"
  21. )
  22. func TestBuildSelectSQLByUpdate(t *testing.T) {
  23. builder := BasicUndoBuilder{}
  24. tests := []struct {
  25. name string
  26. query string
  27. expect string
  28. }{
  29. {
  30. query: "update t_user set name = ?, age = ? where id = ?",
  31. expect: "SELECT SQL_NO_CACHE name,age FROM t_user WHERE id=?",
  32. },
  33. {
  34. query: "update t_user set name = ?, age = ? where id = ? and addr = ? order by id, name desc",
  35. expect: "SELECT SQL_NO_CACHE name,age FROM t_user WHERE id=? AND addr=? ORDER BY id,name DESC",
  36. },
  37. {
  38. query: "update t_user set name = ?, age = ? where id = ? and addr = ? order by id, name desc limit 99",
  39. expect: "SELECT SQL_NO_CACHE name,age FROM t_user WHERE id=? AND addr=? ORDER BY id,name DESC LIMIT 99",
  40. },
  41. }
  42. for _, tt := range tests {
  43. t.Run(tt.name, func(t *testing.T) {
  44. sql, err := builder.buildSelectSQLByUpdate(tt.query)
  45. assert.Nil(t, err)
  46. assert.Equal(t, tt.expect, sql)
  47. })
  48. }
  49. }