Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions auth-service/coverage.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
mode: set
auth-service/cmd/main.go:15.13,18.16 2 0
auth-service/cmd/main.go:18.16,20.3 1 0
auth-service/cmd/main.go:23.2,24.16 2 0
auth-service/cmd/main.go:24.16,26.3 1 0
auth-service/cmd/main.go:27.2,31.16 3 0
auth-service/cmd/main.go:31.16,33.3 1 0
auth-service/cmd/main.go:34.2,38.16 3 0
auth-service/cmd/main.go:38.16,40.3 1 0
auth-service/cmd/main.go:41.2,44.37 3 0
auth-service/cmd/main.go:44.37,51.42 4 0
auth-service/cmd/main.go:51.42,53.4 1 0
auth-service/cmd/main.go:57.2,57.53 1 0
auth-service/cmd/main.go:57.53,58.37 1 0
auth-service/cmd/main.go:58.37,63.39 4 0
auth-service/cmd/main.go:63.39,66.5 2 0
auth-service/cmd/main.go:67.4,67.18 1 0
auth-service/cmd/main.go:72.2,76.2 3 0
auth-service/cmd/main.go:76.2,79.3 2 0
auth-service/cmd/main.go:82.2,84.2 3 0
auth-service/cmd/main.go:84.2,88.3 3 0
auth-service/cmd/main.go:91.2,101.76 4 0
auth-service/cmd/main.go:101.76,103.3 1 0
auth-service/cmd/main.go:106.43,115.2 4 0
auth-service/pkg/db/redis/redis.go:12.62,20.70 2 0
auth-service/pkg/db/redis/redis.go:20.70,22.3 1 0
auth-service/pkg/db/redis/redis.go:24.2,24.36 1 0
auth-service/pkg/db/redis/redis.go:27.45,29.2 1 0
auth-service/pkg/db/redis/redis.go:31.31,33.2 1 0
auth-service/pkg/logger/zap.go:14.53,19.33 4 0
auth-service/pkg/logger/zap.go:19.33,24.3 4 0
auth-service/pkg/logger/zap.go:24.8,29.3 4 0
auth-service/pkg/logger/zap.go:32.2,36.16 4 0
auth-service/pkg/logger/zap.go:36.16,38.3 1 0
auth-service/pkg/logger/zap.go:40.2,40.29 1 0
auth-service/pkg/logger/zap.go:44.31,46.2 1 0
auth-service/pkg/logger/zap.go:49.60,51.40 2 0
auth-service/pkg/logger/zap.go:51.40,52.40 1 0
auth-service/pkg/logger/zap.go:52.40,54.4 1 0
auth-service/pkg/logger/zap.go:56.2,56.45 1 0
auth-service/pkg/logger/zap.go:60.59,62.2 1 0
auth-service/pkg/logger/zap.go:64.58,66.2 1 0
auth-service/pkg/logger/zap.go:68.58,70.2 1 0
auth-service/pkg/logger/zap.go:72.59,74.2 1 0
auth-service/pkg/logger/zap.go:76.59,78.2 1 0
auth-service/pkg/db/postgres/postgres.go:21.62,24.16 2 0
auth-service/pkg/db/postgres/postgres.go:24.16,26.3 1 0
auth-service/pkg/db/postgres/postgres.go:29.2,34.34 4 0
auth-service/pkg/db/postgres/postgres.go:34.34,36.3 1 0
auth-service/pkg/db/postgres/postgres.go:39.2,39.42 1 0
auth-service/pkg/db/postgres/postgres.go:39.42,41.3 1 0
auth-service/pkg/db/postgres/postgres.go:43.2,43.31 1 0
auth-service/pkg/db/postgres/postgres.go:46.38,48.16 2 0
auth-service/pkg/db/postgres/postgres.go:48.16,50.3 1 0
auth-service/pkg/db/postgres/postgres.go:52.2,57.16 2 0
auth-service/pkg/db/postgres/postgres.go:57.16,59.3 1 0
auth-service/pkg/db/postgres/postgres.go:61.2,61.61 1 0
auth-service/pkg/db/postgres/postgres.go:61.61,63.3 1 0
auth-service/pkg/db/postgres/postgres.go:65.2,66.12 2 0
auth-service/internal/config/config.go:43.30,76.2 21 1
auth-service/internal/config/config.go:78.46,79.42 1 1
auth-service/internal/config/config.go:79.42,81.3 1 1
auth-service/internal/config/config.go:82.2,82.21 1 1
auth-service/internal/config/config.go:85.34,94.2 1 0
auth-service/internal/middleware/middleware.go:17.102,18.54 1 0
auth-service/internal/middleware/middleware.go:18.54,19.37 1 0
auth-service/internal/middleware/middleware.go:19.37,21.24 2 0
auth-service/internal/middleware/middleware.go:21.24,27.5 3 0
auth-service/internal/middleware/middleware.go:29.4,30.47 2 0
auth-service/internal/middleware/middleware.go:30.47,36.5 3 0
auth-service/internal/middleware/middleware.go:38.4,41.37 4 0
auth-service/internal/middleware/middleware.go:41.37,47.5 3 0
auth-service/internal/middleware/middleware.go:47.10,47.25 1 0
auth-service/internal/middleware/middleware.go:47.25,54.5 3 0
auth-service/internal/middleware/middleware.go:56.4,56.85 1 0
auth-service/internal/middleware/middleware.go:56.85,57.60 1 0
auth-service/internal/middleware/middleware.go:57.60,59.6 1 0
auth-service/internal/middleware/middleware.go:60.5,60.26 1 0
auth-service/internal/middleware/middleware.go:63.4,63.18 1 0
auth-service/internal/middleware/middleware.go:63.18,64.39 1 0
auth-service/internal/middleware/middleware.go:64.39,70.6 2 0
auth-service/internal/middleware/middleware.go:70.11,76.6 2 0
auth-service/internal/middleware/middleware.go:77.5,77.15 1 0
auth-service/internal/middleware/middleware.go:80.4,81.27 2 0
auth-service/internal/middleware/middleware.go:81.27,87.5 3 0
auth-service/internal/middleware/middleware.go:89.4,89.46 1 0
auth-service/internal/middleware/middleware.go:89.46,90.39 1 0
auth-service/internal/middleware/middleware.go:90.39,96.6 3 0
auth-service/internal/middleware/middleware.go:99.4,103.18 4 0
auth-service/internal/middleware/middleware.go:109.61,111.54 2 0
auth-service/internal/middleware/middleware.go:111.54,112.37 1 0
auth-service/internal/middleware/middleware.go:112.37,113.24 1 0
auth-service/internal/middleware/middleware.go:113.24,119.5 3 0
auth-service/internal/middleware/middleware.go:121.4,121.18 1 0
auth-service/internal/models/user.go:31.41,33.38 2 1
auth-service/internal/models/user.go:33.38,35.3 1 1
auth-service/internal/models/user.go:36.2,36.12 1 1
auth-service/internal/utils/password.go:9.52,11.16 2 1
auth-service/internal/utils/password.go:11.16,13.3 1 0
auth-service/internal/utils/password.go:14.2,14.27 1 1
auth-service/internal/utils/password.go:18.52,21.2 2 1
auth-service/internal/utils/password.go:24.46,25.23 1 0
auth-service/internal/utils/password.go:25.23,27.3 1 0
auth-service/internal/utils/password.go:28.2,28.12 1 0
40 changes: 33 additions & 7 deletions auth-service/internal/handlers/handlers_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package handlers

import (
database "auth-service/internal/postgres"
"auth-service/internal/redis"
"auth-service/internal/utils"
database "auth-service/pkg/db/postgres"
"auth-service/pkg/db/redis"
"auth-service/pkg/logger"
"encoding/json"
"net/http"
"net/http/httptest"
Expand All @@ -17,22 +18,47 @@ import (
"github.com/stretchr/testify/require"
)

func setupAuth(t *testing.T) (*AuthHandler, sqlmock.Sqlmock, *echo.Echo) {
type MockLogger struct {
Calls []LogCall
}

type LogCall struct {
Level string
Msg string
Args []interface{}
}

func (m *MockLogger) Info(msg string, keysAndValues ...interface{}) {
m.Calls = append(m.Calls, LogCall{Level: "Info", Msg: msg, Args: keysAndValues})
}

func (m *MockLogger) Warn(msg string, keysAndValues ...interface{}) {
m.Calls = append(m.Calls, LogCall{Level: "Warn", Msg: msg, Args: keysAndValues})
}

func (m *MockLogger) Error(msg string, keysAndValues ...interface{}) {
m.Calls = append(m.Calls, LogCall{Level: "Error", Msg: msg, Args: keysAndValues})
}

func setupAuth(t *testing.T) (*AuthHandler, sqlmock.Sqlmock, *echo.Echo, *MockLogger) {
sqlDB, mock, err := sqlmock.New()
require.NoError(t, err)

mock.ExpectPing()

mockLogger := &MockLogger{}
logger := &logger.Logger{}

db := &database.Database{DB: sqlDB}
rd, _ := redis.NewRedis("localhost:6379", "", 0) // real Redis не нужен: только client.Set/Del/Get
ah := NewAuthHandler(db, rd, []byte("secret"), time.Hour)
ah := NewAuthHandler(db, rd, []byte("secret"), time.Hour, logger)

e := echo.New()
return ah, mock, e
return ah, mock, e, mockLogger
}

func TestRegister_Success(t *testing.T) {
ah, mock, e := setupAuth(t)
ah, mock, e, _ := setupAuth(t)

mock.ExpectQuery(`SELECT EXISTS`).
WithArgs("alice@mail.com").
Expand Down Expand Up @@ -63,7 +89,7 @@ func TestRegister_Success(t *testing.T) {
}

func TestLogin_Success(t *testing.T) {
ah, mock, e := setupAuth(t)
ah, mock, e, _ := setupAuth(t)

plaintext := "P@ssw0rd!"
hash, _ := utils.HashPassword(plaintext)
Expand Down
Loading