mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2024-12-22 00:36:41 +02:00
49 lines
1022 B
Go
49 lines
1022 B
Go
|
package dbmeta
|
||
|
|
||
|
import (
|
||
|
"reflect"
|
||
|
"testing"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type Employee struct {
|
||
|
EmpNo int `gorm:"column:emp_no;primary_key" json:"emp_no"`
|
||
|
BirthDate time.Time `gorm:"column:birth_date" json:"birth_date"`
|
||
|
FirstName string `gorm:"column:first_name" json:"first_name"`
|
||
|
LastName string `gorm:"column:last_name" json:"last_name"`
|
||
|
Gender string `gorm:"column:gender" json:"gender"`
|
||
|
HireDate time.Time `gorm:"column:hire_date" json:"hire_date"`
|
||
|
}
|
||
|
|
||
|
func Test_Copy(t *testing.T) {
|
||
|
now := time.Now()
|
||
|
dst := &Employee{
|
||
|
EmpNo: 10001,
|
||
|
BirthDate: now,
|
||
|
FirstName: "Tom",
|
||
|
}
|
||
|
|
||
|
src := &Employee{
|
||
|
EmpNo: 10001,
|
||
|
BirthDate: now.Add(3600 * time.Second),
|
||
|
FirstName: "Jerry",
|
||
|
Gender: "Male",
|
||
|
}
|
||
|
|
||
|
err := Copy(dst, src)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
expected := &Employee{
|
||
|
EmpNo: 10001,
|
||
|
BirthDate: now.Add(3600 * time.Second),
|
||
|
FirstName: "Jerry",
|
||
|
Gender: "Male",
|
||
|
}
|
||
|
|
||
|
if !reflect.DeepEqual(expected, dst) {
|
||
|
t.Errorf("expect: %+v, but got %+x", expected, dst)
|
||
|
}
|
||
|
}
|