search_test.go 668 B

123456789101112131415161718192021222324252627282930
  1. package gorm
  2. import (
  3. "reflect"
  4. "testing"
  5. )
  6. func TestCloneSearch(t *testing.T) {
  7. s := new(search)
  8. s.Where("name = ?", "jinzhu").Order("name").Attrs("name", "jinzhu").Select("name, age")
  9. s1 := s.clone()
  10. s1.Where("age = ?", 20).Order("age").Attrs("email", "a@e.org").Select("email")
  11. if reflect.DeepEqual(s.whereConditions, s1.whereConditions) {
  12. t.Errorf("Where should be copied")
  13. }
  14. if reflect.DeepEqual(s.orders, s1.orders) {
  15. t.Errorf("Order should be copied")
  16. }
  17. if reflect.DeepEqual(s.initAttrs, s1.initAttrs) {
  18. t.Errorf("InitAttrs should be copied")
  19. }
  20. if reflect.DeepEqual(s.Select, s1.Select) {
  21. t.Errorf("selectStr should be copied")
  22. }
  23. }