gorm/search_test.go

31 lines
668 B
Go
Raw Normal View History

2013-11-16 05:12:22 +04:00
package gorm
import (
"reflect"
"testing"
)
func TestCloneSearch(t *testing.T) {
s := new(search)
2015-03-12 10:50:38 +03:00
s.Where("name = ?", "jinzhu").Order("name").Attrs("name", "jinzhu").Select("name, age")
2013-11-16 05:12:22 +04:00
s1 := s.clone()
2015-03-12 10:50:38 +03:00
s1.Where("age = ?", 20).Order("age").Attrs("email", "a@e.org").Select("email")
2013-11-16 05:12:22 +04:00
2015-03-12 08:52:29 +03:00
if reflect.DeepEqual(s.whereConditions, s1.whereConditions) {
2013-11-16 05:12:22 +04:00
t.Errorf("Where should be copied")
}
2015-03-12 08:52:29 +03:00
if reflect.DeepEqual(s.orders, s1.orders) {
2013-11-16 05:12:22 +04:00
t.Errorf("Order should be copied")
}
2015-03-12 08:52:29 +03:00
if reflect.DeepEqual(s.initAttrs, s1.initAttrs) {
2014-01-28 12:56:51 +04:00
t.Errorf("InitAttrs should be copied")
2013-11-16 05:12:22 +04:00
}
2015-03-12 10:50:38 +03:00
if reflect.DeepEqual(s.Select, s1.Select) {
2013-11-16 05:12:22 +04:00
t.Errorf("selectStr should be copied")
}
}