Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
demoManito committed Mar 16, 2024
1 parent 5a28fc5 commit 5a775c2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,3 +793,31 @@ func TestCreateFromMapWithTable(t *testing.T) {
t.Fatal("failed to create data from map with table, @id != id")
}
}

func TestCreateWithSliceWritebackPrimaryKey(t *testing.T) {
users := []*User{
{
Age: 20,
},
{
Model: gorm.Model{
ID: 100000,
},
Age: 21,
},
{
Age: 22,
},
}
err := DB.Create(users).Error
if err != nil {
t.Fatal(err)
}

if users[1].ID != 100000 {
t.Errorf("users[1].ID should be 100000, but got %v", users[1].ID)
}
if users[2].ID != users[1].ID+1 {
t.Errorf("failed to write back primary key, users[2].ID should be %v, but got %v", users[1].ID+1, users[2].ID)
}
}

0 comments on commit 5a775c2

Please sign in to comment.