diff --git a/main_test.go b/main_test.go index 60a388f7..18503e9e 100644 --- a/main_test.go +++ b/main_test.go @@ -2,6 +2,9 @@ package main import ( "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) // GORM_REPO: https://github.com/go-gorm/gorm.git @@ -9,12 +12,26 @@ import ( // TEST_DRIVERS: sqlite, mysql, postgres, sqlserver func TestGORM(t *testing.T) { - user := User{Name: "jinzhu"} + user := User{Name: "jinzhu", Age: 30} DB.Create(&user) - var result User - if err := DB.First(&result, user.ID).Error; err != nil { - t.Errorf("Failed, got error: %v", err) + type result struct { + Name string + IsExample bool + Age int } + var results []result + err := DB.Table("users").Select("name = 'test example.com' as is_example", "age").Scan(&results).Error + require.NoError(t, err) + assert.False(t, results[0].IsExample) + assert.Equal(t, results[0].Age, 30) + + // This time, an at-sign character is used in the select string. This causes the "age" string to not be included + // as a column in select, thus resulting in age being a default zero. + err = DB.Table("users").Select("name = 'test@example.com' as is_example", "age").Scan(&results).Error + assert.False(t, results[0].IsExample) + assert.Equal(t, results[0].Age, 30) + + require.NoError(t, err) }