From a739f8b03547c9b7d6c6a60af51e4fa750b04146 Mon Sep 17 00:00:00 2001 From: biju-kalissery Date: Tue, 8 Sep 2015 14:04:10 -0400 Subject: [PATCH] enable identity column insert optionally for mssql ref: https://github.com/jinzhu/gorm/issues/647 --- customize_column_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/customize_column_test.go b/customize_column_test.go index cf4f1d1a..8a472bdb 100644 --- a/customize_column_test.go +++ b/customize_column_test.go @@ -32,12 +32,23 @@ func TestCustomizeColumn(t *testing.T) { if scope.PrimaryKey() != col { t.Errorf("CustomizeColumn should have primary key %s, but got %q", col, scope.PrimaryKey()) } + + tableName := "customize_columns" + idInsRes := DB.EnableIdentityInsert(&DB, tableName) + if idInsRes.Error != nil { + t.Errorf("Error while setting IDENTITY_INSERT ON for table:%v :%v", tableName, idInsRes.Error) + } expected := "foo" cc := CustomizeColumn{ID: 666, Name: expected, Date: time.Now()} - if count := DB.Create(&cc).RowsAffected; count != 1 { - t.Error("There should be one record be affected when create record") + res := DB.Create(&cc) + if res.Error != nil { + t.Errorf("Error while creating CustomizeColumn:%v", res.Error) + } + + if count := res.RowsAffected; count != 1 { + t.Errorf("There should be one record be affected when create record. count:%v", count) } var cc1 CustomizeColumn