You've already forked testing-go-code-with-postgres
mirror of
https://github.com/xorcare/testing-go-code-with-postgres.git
synced 2025-06-30 23:23:40 +02:00
Enable linter 'wsl'
This is a highly controversial linter, but it generally has a positive effect on code readability.
This commit is contained in:
@ -14,6 +14,7 @@ linters:
|
|||||||
- typecheck
|
- typecheck
|
||||||
- unused
|
- unused
|
||||||
- whitespace
|
- whitespace
|
||||||
|
- wsl
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
goimports:
|
goimports:
|
||||||
|
@ -48,7 +48,9 @@ func newPostgres(t TestingT) *Postgres {
|
|||||||
urlStr := os.Getenv("TESTING_DB_URL")
|
urlStr := os.Getenv("TESTING_DB_URL")
|
||||||
if urlStr == "" {
|
if urlStr == "" {
|
||||||
urlStr = "postgresql://postgres:postgres@localhost:32260/postgres?sslmode=disable"
|
urlStr = "postgresql://postgres:postgres@localhost:32260/postgres?sslmode=disable"
|
||||||
|
|
||||||
const format = "env TESTING_DB_URL is empty, used default value: %s"
|
const format = "env TESTING_DB_URL is empty, used default value: %s"
|
||||||
|
|
||||||
t.Logf(format, urlStr)
|
t.Logf(format, urlStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,16 +127,20 @@ func newUniqueHumanReadableDatabaseName(t TestingT) string {
|
|||||||
maxHumanReadableLenBytes := maxIdentifierLengthBytes - len(uid)
|
maxHumanReadableLenBytes := maxIdentifierLengthBytes - len(uid)
|
||||||
|
|
||||||
lastSymbolIsHyphen := false
|
lastSymbolIsHyphen := false
|
||||||
|
|
||||||
for _, r := range t.Name() {
|
for _, r := range t.Name() {
|
||||||
if unicode.IsLetter(r) || unicode.IsNumber(r) {
|
if unicode.IsLetter(r) || unicode.IsNumber(r) {
|
||||||
output.WriteRune(r)
|
output.WriteRune(r)
|
||||||
|
|
||||||
lastSymbolIsHyphen = false
|
lastSymbolIsHyphen = false
|
||||||
} else {
|
} else {
|
||||||
if !lastSymbolIsHyphen {
|
if !lastSymbolIsHyphen {
|
||||||
output.WriteRune('-')
|
output.WriteRune('-')
|
||||||
}
|
}
|
||||||
|
|
||||||
lastSymbolIsHyphen = true
|
lastSymbolIsHyphen = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if output.Len() >= maxHumanReadableLenBytes {
|
if output.Len() >= maxHumanReadableLenBytes {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -157,7 +163,9 @@ func genUnique8BytesID(t TestingT) string {
|
|||||||
func replaceDBName(t TestingT, dataSourceURL, dbname string) string {
|
func replaceDBName(t TestingT, dataSourceURL, dbname string) string {
|
||||||
r, err := url.Parse(dataSourceURL)
|
r, err := url.Parse(dataSourceURL)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
r.Path = dbname
|
r.Path = dbname
|
||||||
|
|
||||||
return r.String()
|
return r.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,9 +26,11 @@ func (r *UserRepository) ReadUser(ctx context.Context, userID uuid.UUID) (User,
|
|||||||
user := User{}
|
user := User{}
|
||||||
|
|
||||||
row := r.db.QueryRow(ctx, sql, userID)
|
row := r.db.QueryRow(ctx, sql, userID)
|
||||||
|
|
||||||
err := row.Scan(&user.ID, &user.Username, &user.CreatedAt)
|
err := row.Scan(&user.ID, &user.Username, &user.CreatedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
const format = "failed selection of User from database: %v"
|
const format = "failed selection of User from database: %v"
|
||||||
|
|
||||||
return User{}, fmt.Errorf(format, err)
|
return User{}, fmt.Errorf(format, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ func TestUserRepository_CreateUser(t *testing.T) {
|
|||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("skipping test in short mode")
|
t.Skip("skipping test in short mode")
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
newFullyFiledUser := func() rootpkg.User {
|
newFullyFiledUser := func() rootpkg.User {
|
||||||
|
Reference in New Issue
Block a user