Skip to content

Commit 47ae801

Browse files
committed
add tet TestCreateWithInterfaceArrayType
1 parent 35e231b commit 47ae801

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

tests/create_test.go

+32-1
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ func TestCreateWithInterfaceType(t *testing.T) {
796796
user := *GetUser("create", Config{})
797797
type UserInterface interface{}
798798
var userInterface UserInterface = &user
799-
799+
800800
if results := DB.Create(userInterface); results.Error != nil {
801801
t.Fatalf("errors happened when create: %v", results.Error)
802802
} else if results.RowsAffected != 1 {
@@ -822,3 +822,34 @@ func TestCreateWithInterfaceType(t *testing.T) {
822822
CheckUser(t, newUser, user)
823823
}
824824
}
825+
826+
func TestCreateWithInterfaceArrayType(t *testing.T) {
827+
user := *GetUser("create", Config{})
828+
type UserInterface interface{}
829+
var userInterface UserInterface = &user
830+
831+
if results := DB.Create([]UserInterface{userInterface}); results.Error != nil {
832+
t.Fatalf("errors happened when create: %v", results.Error)
833+
} else if results.RowsAffected != 1 {
834+
t.Fatalf("rows affected expects: %v, got %v", 1, results.RowsAffected)
835+
}
836+
837+
if user.ID == 0 {
838+
t.Errorf("user's primary key should has value after create, got : %v", user.ID)
839+
}
840+
841+
if user.CreatedAt.IsZero() {
842+
t.Errorf("user's created at should be not zero")
843+
}
844+
845+
if user.UpdatedAt.IsZero() {
846+
t.Errorf("user's updated at should be not zero")
847+
}
848+
849+
var newUser User
850+
if err := DB.Where("id = ?", user.ID).First(&newUser).Error; err != nil {
851+
t.Fatalf("errors happened when query: %v", err)
852+
} else {
853+
CheckUser(t, newUser, user)
854+
}
855+
}

0 commit comments

Comments
 (0)