diff --git a/bulk_insert_test.go b/bulk_insert_test.go index 892972f..7cce126 100644 --- a/bulk_insert_test.go +++ b/bulk_insert_test.go @@ -85,9 +85,9 @@ func TestBulkInsertWithReturningValues_InvalidTypeOfReturnedVals(t *testing.T) { tests := []struct { name string vals interface{} - } { - {name: "not a pointer", vals: []struct{Name string}{{Name: "1"}}}, - {name: "element is not a slice", vals: &struct{Name string}{Name: "1"}}, + }{ + {name: "not a pointer", vals: []struct{ Name string }{{Name: "1"}}}, + {name: "element is not a slice", vals: &struct{ Name string }{Name: "1"}}, {name: "slice element is not a struct", vals: &[]string{"1"}}, } for _, tt := range tests { @@ -214,3 +214,27 @@ func Test_fieldIsAutoIncrement(t *testing.T) { } } } + +func Test_fieldIsPrimaryAndBlank(t *testing.T) { + type notPrimaryTable struct { + Dummy int + } + type primaryKeyTable struct { + ID int `gorm:"column:id;primary_key"` + } + + cases := []struct { + Value interface{} + Expected bool + }{ + {notPrimaryTable{Dummy: 0}, false}, + {notPrimaryTable{Dummy: 1}, false}, + {primaryKeyTable{ID: 0}, true}, + {primaryKeyTable{ID: 1}, false}, + } + for _, c := range cases { + for _, field := range (&gorm.Scope{Value: c.Value}).Fields() { + assert.Equal(t, fieldIsPrimaryAndBlank(field), c.Expected) + } + } +}