From ab5f864a78098e4ac1e5df435571d113d29c3d07 Mon Sep 17 00:00:00 2001 From: Vasiliy Vasilyuk Date: Tue, 14 Nov 2023 22:15:16 +0300 Subject: [PATCH] Enable linter 'testpackage' This will avoid testing private functions and methods. --- .golangci.yml | 1 + user_repository_test.go | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 9e3be4d..329207a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,6 +10,7 @@ linters: - misspell - staticcheck - testifylint + - testpackage - typecheck - unused - whitespace diff --git a/user_repository_test.go b/user_repository_test.go index 1013e7d..082a71f 100644 --- a/user_repository_test.go +++ b/user_repository_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package testing_go_code_with_postgres +package testing_go_code_with_postgres_test import ( "context" @@ -12,6 +12,7 @@ import ( "github.com/google/uuid" "github.com/stretchr/testify/require" + rootpkg "github.com/xorcare/testing-go-code-with-postgres" "github.com/xorcare/testing-go-code-with-postgres/testingpg" ) @@ -19,11 +20,10 @@ func TestUserRepository_CreateUser(t *testing.T) { if testing.Short() { t.Skip("skipping test in short mode") } - t.Parallel() - newFullyFiledUser := func() User { - return User{ + newFullyFiledUser := func() rootpkg.User { + return rootpkg.User{ ID: uuid.New(), Username: "gopher", CreatedAt: time.Now().Truncate(time.Microsecond), @@ -35,7 +35,7 @@ func TestUserRepository_CreateUser(t *testing.T) { // Arrange postgres := testingpg.New(t) - repo := NewUserRepository(postgres.PgxPool()) + repo := rootpkg.NewUserRepository(postgres.PgxPool()) user := newFullyFiledUser() @@ -56,7 +56,7 @@ func TestUserRepository_CreateUser(t *testing.T) { // Arrange postgres := testingpg.New(t) - repo := NewUserRepository(postgres.PgxPool()) + repo := rootpkg.NewUserRepository(postgres.PgxPool()) user := newFullyFiledUser() @@ -84,7 +84,7 @@ func TestUserRepository_ReadUser(t *testing.T) { // Arrange postgres := testingpg.New(t) - repo := NewUserRepository(postgres.PgxPool()) + repo := rootpkg.NewUserRepository(postgres.PgxPool()) // Act _, err := repo.ReadUser(context.Background(), uuid.New())