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
|
||||
- unused
|
||||
- whitespace
|
||||
- wsl
|
||||
|
||||
linters-settings:
|
||||
goimports:
|
||||
|
@ -48,7 +48,9 @@ func newPostgres(t TestingT) *Postgres {
|
||||
urlStr := os.Getenv("TESTING_DB_URL")
|
||||
if urlStr == "" {
|
||||
urlStr = "postgresql://postgres:postgres@localhost:32260/postgres?sslmode=disable"
|
||||
|
||||
const format = "env TESTING_DB_URL is empty, used default value: %s"
|
||||
|
||||
t.Logf(format, urlStr)
|
||||
}
|
||||
|
||||
@ -125,16 +127,20 @@ func newUniqueHumanReadableDatabaseName(t TestingT) string {
|
||||
maxHumanReadableLenBytes := maxIdentifierLengthBytes - len(uid)
|
||||
|
||||
lastSymbolIsHyphen := false
|
||||
|
||||
for _, r := range t.Name() {
|
||||
if unicode.IsLetter(r) || unicode.IsNumber(r) {
|
||||
output.WriteRune(r)
|
||||
|
||||
lastSymbolIsHyphen = false
|
||||
} else {
|
||||
if !lastSymbolIsHyphen {
|
||||
output.WriteRune('-')
|
||||
}
|
||||
|
||||
lastSymbolIsHyphen = true
|
||||
}
|
||||
|
||||
if output.Len() >= maxHumanReadableLenBytes {
|
||||
break
|
||||
}
|
||||
@ -157,7 +163,9 @@ func genUnique8BytesID(t TestingT) string {
|
||||
func replaceDBName(t TestingT, dataSourceURL, dbname string) string {
|
||||
r, err := url.Parse(dataSourceURL)
|
||||
require.NoError(t, err)
|
||||
|
||||
r.Path = dbname
|
||||
|
||||
return r.String()
|
||||
}
|
||||
|
||||
|
@ -26,9 +26,11 @@ func (r *UserRepository) ReadUser(ctx context.Context, userID uuid.UUID) (User,
|
||||
user := User{}
|
||||
|
||||
row := r.db.QueryRow(ctx, sql, userID)
|
||||
|
||||
err := row.Scan(&user.ID, &user.Username, &user.CreatedAt)
|
||||
if err != nil {
|
||||
const format = "failed selection of User from database: %v"
|
||||
|
||||
return User{}, fmt.Errorf(format, err)
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ func TestUserRepository_CreateUser(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
t.Parallel()
|
||||
|
||||
newFullyFiledUser := func() rootpkg.User {
|
||||
|
Reference in New Issue
Block a user