style: fix coding typo (#5184)

This commit is contained in:
Jin 2022-03-24 09:31:58 +08:00 committed by GitHub
parent f92e6747cb
commit 9a4d10be64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 12 deletions

View File

@ -44,7 +44,7 @@ func (ct ColumnType) DatabaseTypeName() string {
return ct.SQLColumnType.DatabaseTypeName() return ct.SQLColumnType.DatabaseTypeName()
} }
// ColumnType returns the database type of the column. lke `varchar(16)` // ColumnType returns the database type of the column. like `varchar(16)`
func (ct ColumnType) ColumnType() (columnType string, ok bool) { func (ct ColumnType) ColumnType() (columnType string, ok bool) {
return ct.ColumnTypeValue.String, ct.ColumnTypeValue.Valid return ct.ColumnTypeValue.String, ct.ColumnTypeValue.Valid
} }

View File

@ -43,10 +43,8 @@ func TestExceptionsWithInvalidSql(t *testing.T) {
func TestSetAndGet(t *testing.T) { func TestSetAndGet(t *testing.T) {
if value, ok := DB.Set("hello", "world").Get("hello"); !ok { if value, ok := DB.Set("hello", "world").Get("hello"); !ok {
t.Errorf("Should be able to get setting after set") t.Errorf("Should be able to get setting after set")
} else { } else if value.(string) != "world" {
if value.(string) != "world" { t.Errorf("Set value should not be changed")
t.Errorf("Setted value should not be changed")
}
} }
if _, ok := DB.Get("non_existing"); ok { if _, ok := DB.Get("non_existing"); ok {

View File

@ -258,7 +258,7 @@ func TestMigrateTable(t *testing.T) {
DB.Migrator().DropTable("new_table_structs") DB.Migrator().DropTable("new_table_structs")
if DB.Migrator().HasTable(&NewTableStruct{}) { if DB.Migrator().HasTable(&NewTableStruct{}) {
t.Fatal("should not found droped table") t.Fatal("should not found dropped table")
} }
} }

View File

@ -360,7 +360,7 @@ func TestToSQL(t *testing.T) {
}) })
assertEqualSQL(t, `SELECT * FROM "users" WHERE id = 100 AND "users"."deleted_at" IS NULL ORDER BY age desc LIMIT 10`, sql) assertEqualSQL(t, `SELECT * FROM "users" WHERE id = 100 AND "users"."deleted_at" IS NULL ORDER BY age desc LIMIT 10`, sql)
// after model chagned // after model changed
if DB.Statement.DryRun || DB.DryRun { if DB.Statement.DryRun || DB.DryRun {
t.Fatal("Failed expect DB.DryRun and DB.Statement.ToSQL to be false") t.Fatal("Failed expect DB.DryRun and DB.Statement.ToSQL to be false")
} }
@ -426,13 +426,13 @@ func TestToSQL(t *testing.T) {
}) })
assertEqualSQL(t, `UPDATE "users" SET "name"='Foo',"age"=100 WHERE id = 100 AND "users"."deleted_at" IS NULL`, sql) assertEqualSQL(t, `UPDATE "users" SET "name"='Foo',"age"=100 WHERE id = 100 AND "users"."deleted_at" IS NULL`, sql)
// after model chagned // after model changed
if DB.Statement.DryRun || DB.DryRun { if DB.Statement.DryRun || DB.DryRun {
t.Fatal("Failed expect DB.DryRun and DB.Statement.ToSQL to be false") t.Fatal("Failed expect DB.DryRun and DB.Statement.ToSQL to be false")
} }
} }
// assertEqualSQL for assert that the sql is equal, this method will ignore quote, and dialect speicals. // assertEqualSQL for assert that the sql is equal, this method will ignore quote, and dialect specials.
func assertEqualSQL(t *testing.T, expected string, actually string) { func assertEqualSQL(t *testing.T, expected string, actually string) {
t.Helper() t.Helper()
@ -440,7 +440,7 @@ func assertEqualSQL(t *testing.T, expected string, actually string) {
expected = replaceQuoteInSQL(expected) expected = replaceQuoteInSQL(expected)
actually = replaceQuoteInSQL(actually) actually = replaceQuoteInSQL(actually)
// ignore updated_at value, becase it's generated in Gorm inernal, can't to mock value on update. // ignore updated_at value, because it's generated in Gorm internal, can't to mock value on update.
updatedAtRe := regexp.MustCompile(`(?i)"updated_at"=".+?"`) updatedAtRe := regexp.MustCompile(`(?i)"updated_at"=".+?"`)
actually = updatedAtRe.ReplaceAllString(actually, `"updated_at"=?`) actually = updatedAtRe.ReplaceAllString(actually, `"updated_at"=?`)
expected = updatedAtRe.ReplaceAllString(expected, `"updated_at"=?`) expected = updatedAtRe.ReplaceAllString(expected, `"updated_at"=?`)
@ -462,7 +462,7 @@ func replaceQuoteInSQL(sql string) string {
// convert single quote into double quote // convert single quote into double quote
sql = strings.ReplaceAll(sql, `'`, `"`) sql = strings.ReplaceAll(sql, `'`, `"`)
// convert dialect speical quote into double quote // convert dialect special quote into double quote
switch DB.Dialector.Name() { switch DB.Dialector.Name() {
case "postgres": case "postgres":
sql = strings.ReplaceAll(sql, `"`, `"`) sql = strings.ReplaceAll(sql, `"`, `"`)

View File

@ -319,7 +319,7 @@ func TestUpdateWithMissWhere(t *testing.T) {
tx := DB.Session(&gorm.Session{DryRun: true}).Save(&user) tx := DB.Session(&gorm.Session{DryRun: true}).Save(&user)
if err := tx.Error; err != nil { if err := tx.Error; err != nil {
t.Fatalf("failed to update user,missing where condtion,err=%+v", err) t.Fatalf("failed to update user,missing where condition,err=%+v", err)
} }
if !regexp.MustCompile("WHERE .id. = [^ ]+$").MatchString(tx.Statement.SQL.String()) { if !regexp.MustCompile("WHERE .id. = [^ ]+$").MatchString(tx.Statement.SQL.String()) {