Skip to content

Commit

Permalink
Initial test to show failure
Browse files Browse the repository at this point in the history
This initial test, against this code base, shows that "update" against a
table, with only one column, where that coumn is the primary key, and is
not auto-incrementing, will fail.
  • Loading branch information
kungfumike authored and James Cooper committed May 14, 2014
1 parent b795354 commit ed5dce5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions gorp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ type UniqueColumns struct {
ZipCode int64
}

type SingleColumnTable struct {
SomeId string
}

type testTypeConverter struct{}

func (me testTypeConverter) ToDb(val interface{}) (interface{}, error) {
Expand Down Expand Up @@ -1491,6 +1495,37 @@ func TestMysqlPanicIfDialectNotInitialized(t *testing.T) {
db.CreateTables()
}

func TestSingleColumnKeyDbReturnsZeroRowsUpdatedOnPKChange(t *testing.T) {
dbmap := initDbMap()
defer dropAndClose(dbmap)
dbmap.AddTableWithName(SingleColumnTable{}, "single_column_table").SetKeys(false, "SomeId")
err := dbmap.DropTablesIfExists()
if err != nil {
t.Error("Drop tables failed")
}
err = dbmap.CreateTablesIfNotExists()
if err != nil {
t.Error("Create tables failed")
}
err = dbmap.TruncateTables()
if err != nil {
t.Error("Truncate tables failed")
}

sct := SingleColumnTable{
SomeId: "A Unique Id String",
}

count, err := dbmap.Update(&sct)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Errorf("Expected 0 updated rows, got %d", count)
}

}

func BenchmarkNativeCrud(b *testing.B) {
b.StopTimer()
dbmap := initDbMapBench()
Expand Down

0 comments on commit ed5dce5

Please sign in to comment.