Skip to content

Commit

Permalink
recover test
Browse files Browse the repository at this point in the history
  • Loading branch information
t-tiger committed Nov 7, 2021
1 parent 88dc325 commit aad2d27
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions bulk_insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit aad2d27

Please sign in to comment.