From 9a4d10be64738f0c1f7a86841d56e2fe3165e3f0 Mon Sep 17 00:00:00 2001 From: Jin Date: Thu, 24 Mar 2022 09:31:58 +0800 Subject: [PATCH] style: fix coding typo (#5184) --- migrator/column_type.go | 2 +- tests/main_test.go | 6 ++---- tests/migrate_test.go | 2 +- tests/sql_builder_test.go | 10 +++++----- tests/upsert_test.go | 2 +- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/migrator/column_type.go b/migrator/column_type.go index cc1331b9..c6fdd6b2 100644 --- a/migrator/column_type.go +++ b/migrator/column_type.go @@ -44,7 +44,7 @@ func (ct ColumnType) DatabaseTypeName() string { 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) { return ct.ColumnTypeValue.String, ct.ColumnTypeValue.Valid } diff --git a/tests/main_test.go b/tests/main_test.go index 5b8c7dbb..997714b9 100644 --- a/tests/main_test.go +++ b/tests/main_test.go @@ -43,10 +43,8 @@ func TestExceptionsWithInvalidSql(t *testing.T) { func TestSetAndGet(t *testing.T) { if value, ok := DB.Set("hello", "world").Get("hello"); !ok { t.Errorf("Should be able to get setting after set") - } else { - if value.(string) != "world" { - t.Errorf("Setted value should not be changed") - } + } else if value.(string) != "world" { + t.Errorf("Set value should not be changed") } if _, ok := DB.Get("non_existing"); ok { diff --git a/tests/migrate_test.go b/tests/migrate_test.go index 94f562b4..f72c4c08 100644 --- a/tests/migrate_test.go +++ b/tests/migrate_test.go @@ -258,7 +258,7 @@ func TestMigrateTable(t *testing.T) { DB.Migrator().DropTable("new_table_structs") if DB.Migrator().HasTable(&NewTableStruct{}) { - t.Fatal("should not found droped table") + t.Fatal("should not found dropped table") } } diff --git a/tests/sql_builder_test.go b/tests/sql_builder_test.go index bc917c32..a7630271 100644 --- a/tests/sql_builder_test.go +++ b/tests/sql_builder_test.go @@ -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) - // after model chagned + // after model changed if DB.Statement.DryRun || DB.DryRun { 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) - // after model chagned + // after model changed if DB.Statement.DryRun || DB.DryRun { 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) { t.Helper() @@ -440,7 +440,7 @@ func assertEqualSQL(t *testing.T, expected string, actually string) { expected = replaceQuoteInSQL(expected) 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"=".+?"`) actually = updatedAtRe.ReplaceAllString(actually, `"updated_at"=?`) expected = updatedAtRe.ReplaceAllString(expected, `"updated_at"=?`) @@ -462,7 +462,7 @@ func replaceQuoteInSQL(sql string) string { // convert single quote into double quote sql = strings.ReplaceAll(sql, `'`, `"`) - // convert dialect speical quote into double quote + // convert dialect special quote into double quote switch DB.Dialector.Name() { case "postgres": sql = strings.ReplaceAll(sql, `"`, `"`) diff --git a/tests/upsert_test.go b/tests/upsert_test.go index c5d19605..f90c4518 100644 --- a/tests/upsert_test.go +++ b/tests/upsert_test.go @@ -319,7 +319,7 @@ func TestUpdateWithMissWhere(t *testing.T) { tx := DB.Session(&gorm.Session{DryRun: true}).Save(&user) 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()) {