2013-11-16 05:12:22 +04:00
|
|
|
package gorm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCloneSearch(t *testing.T) {
|
|
|
|
s := new(search)
|
2015-03-12 08:52:29 +03:00
|
|
|
s.Where("name = ?", "jinzhu").Order("name").Attrs("name", "jinzhu").Selects("name, age")
|
2013-11-16 05:12:22 +04:00
|
|
|
|
|
|
|
s1 := s.clone()
|
2015-03-12 08:52:29 +03:00
|
|
|
s1.Where("age = ?", 20).Order("age").Attrs("email", "a@e.org").Selects("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
|
|
|
}
|
|
|
|
|
2014-11-17 15:12:32 +03:00
|
|
|
if reflect.DeepEqual(s.Selects, s1.Selects) {
|
2013-11-16 05:12:22 +04:00
|
|
|
t.Errorf("selectStr should be copied")
|
|
|
|
}
|
|
|
|
}
|