This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"smart-search-back/pkg/errors"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
)
|
||||
|
||||
type OpenAIClient struct {
|
||||
@@ -122,7 +122,7 @@ func (c *OpenAIClient) GenerateTZ(requestTxt string) (string, error) {
|
||||
if err != nil {
|
||||
return "", errors.NewInternalError(errors.AIAPIError, "failed to send request", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"smart-search-back/internal/model"
|
||||
"smart-search-back/pkg/errors"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
)
|
||||
|
||||
type PerplexityClient struct {
|
||||
@@ -149,7 +149,7 @@ func (c *PerplexityClient) FindSuppliers(tzText string) ([]*model.Supplier, int,
|
||||
if err != nil {
|
||||
return nil, 0, 0, errors.NewInternalError(errors.AIAPIError, "failed to send request", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
|
||||
@@ -3,17 +3,22 @@ package database
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
_ "github.com/jackc/pgx/v5/stdlib"
|
||||
"github.com/pressly/goose/v3"
|
||||
)
|
||||
|
||||
func RunMigrations(databaseURL string) error {
|
||||
return RunMigrationsFromPath(databaseURL, "migrations")
|
||||
}
|
||||
|
||||
func RunMigrationsFromPath(databaseURL, migrationsDir string) error {
|
||||
db, err := sql.Open("pgx", databaseURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open database connection for migrations: %w", err)
|
||||
}
|
||||
defer db.Close()
|
||||
defer func() { _ = db.Close() }()
|
||||
|
||||
if err := db.Ping(); err != nil {
|
||||
return fmt.Errorf("failed to ping database before migrations: %w", err)
|
||||
@@ -23,8 +28,13 @@ func RunMigrations(databaseURL string) error {
|
||||
return fmt.Errorf("failed to set goose dialect: %w", err)
|
||||
}
|
||||
|
||||
if err := goose.Up(db, "migrations"); err != nil {
|
||||
return fmt.Errorf("failed to run migrations: %w", err)
|
||||
absPath, err := filepath.Abs(migrationsDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve migrations path: %w", err)
|
||||
}
|
||||
|
||||
if err := goose.Up(db, absPath); err != nil {
|
||||
return fmt.Errorf("failed to run migrations from %s: %w", absPath, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -3,8 +3,8 @@ package grpc
|
||||
import (
|
||||
"context"
|
||||
|
||||
"smart-search-back/pkg/errors"
|
||||
pb "smart-search-back/pkg/pb/api/proto/auth"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
pb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/auth"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
pb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/invite"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
"smart-search-back/pkg/errors"
|
||||
pb "smart-search-back/pkg/pb/api/proto/invite"
|
||||
)
|
||||
|
||||
func (h *InviteHandler) Generate(ctx context.Context, req *pb.GenerateRequest) (*pb.GenerateResponse, error) {
|
||||
|
||||
@@ -4,10 +4,10 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
pb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/request"
|
||||
"github.com/google/uuid"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
"smart-search-back/pkg/errors"
|
||||
pb "smart-search-back/pkg/pb/api/proto/request"
|
||||
)
|
||||
|
||||
func (h *RequestHandler) CreateTZ(ctx context.Context, req *pb.CreateTZRequest) (*pb.CreateTZResponse, error) {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"smart-search-back/internal/ai"
|
||||
"smart-search-back/internal/repository"
|
||||
"smart-search-back/internal/service"
|
||||
authpb "smart-search-back/pkg/pb/api/proto/auth"
|
||||
invitepb "smart-search-back/pkg/pb/api/proto/invite"
|
||||
requestpb "smart-search-back/pkg/pb/api/proto/request"
|
||||
supplierpb "smart-search-back/pkg/pb/api/proto/supplier"
|
||||
userpb "smart-search-back/pkg/pb/api/proto/user"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/ai"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/repository"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/service"
|
||||
authpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/auth"
|
||||
invitepb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/invite"
|
||||
requestpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/request"
|
||||
supplierpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/supplier"
|
||||
userpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/user"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"go.uber.org/zap"
|
||||
@@ -53,13 +53,15 @@ func NewHandlers(pool *pgxpool.Pool, jwtSecret, cryptoSecret, openAIKey, perplex
|
||||
supplierRepo := repository.NewSupplierRepository(pool)
|
||||
tokenUsageRepo := repository.NewTokenUsageRepository(pool)
|
||||
|
||||
txManager := repository.NewTxManager(pool)
|
||||
|
||||
openAIClient := ai.NewOpenAIClient(openAIKey)
|
||||
perplexityClient := ai.NewPerplexityClient(perplexityKey)
|
||||
|
||||
authService := service.NewAuthService(userRepo, sessionRepo, jwtSecret, cryptoSecret)
|
||||
userService := service.NewUserService(userRepo, requestRepo, cryptoSecret)
|
||||
inviteService := service.NewInviteService(inviteRepo, userRepo)
|
||||
requestService := service.NewRequestService(requestRepo, supplierRepo, tokenUsageRepo, userRepo, openAIClient, perplexityClient)
|
||||
inviteService := service.NewInviteService(inviteRepo, userRepo, txManager)
|
||||
requestService := service.NewRequestService(requestRepo, supplierRepo, tokenUsageRepo, userRepo, openAIClient, perplexityClient, txManager)
|
||||
supplierService := service.NewSupplierService(supplierRepo)
|
||||
|
||||
return &AuthHandler{authService: authService, logger: logger},
|
||||
|
||||
@@ -3,9 +3,9 @@ package grpc
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
pb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/supplier"
|
||||
"github.com/google/uuid"
|
||||
"smart-search-back/pkg/errors"
|
||||
pb "smart-search-back/pkg/pb/api/proto/supplier"
|
||||
)
|
||||
|
||||
func (h *SupplierHandler) ExportExcel(ctx context.Context, req *pb.ExportExcelRequest) (*pb.ExportExcelResponse, error) {
|
||||
|
||||
158
internal/grpc/tests/auth_handler_test.go
Normal file
158
internal/grpc/tests/auth_handler_test.go
Normal file
@@ -0,0 +1,158 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
authpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/auth"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func (s *IntegrationSuite) TestAuthHandler_LoginWithNonExistentUser() {
|
||||
req := &authpb.LoginRequest{
|
||||
Email: "nonexistent@example.com",
|
||||
Password: "password123",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "test-agent",
|
||||
}
|
||||
|
||||
resp, err := s.authClient.Login(context.Background(), req)
|
||||
|
||||
s.Error(err)
|
||||
s.Nil(resp)
|
||||
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Equal(codes.NotFound, st.Code())
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestAuthHandler_ValidateWithInvalidToken() {
|
||||
req := &authpb.ValidateRequest{
|
||||
AccessToken: "invalid-token",
|
||||
}
|
||||
|
||||
resp, err := s.authClient.Validate(context.Background(), req)
|
||||
|
||||
s.NoError(err)
|
||||
s.NotNil(resp)
|
||||
s.False(resp.Valid)
|
||||
s.Equal(int64(0), resp.UserId)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestAuthHandler_ValidateWithEmptyToken() {
|
||||
req := &authpb.ValidateRequest{
|
||||
AccessToken: "",
|
||||
}
|
||||
|
||||
resp, err := s.authClient.Validate(context.Background(), req)
|
||||
|
||||
s.NoError(err)
|
||||
s.NotNil(resp)
|
||||
s.False(resp.Valid)
|
||||
s.Equal(int64(0), resp.UserId)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestAuthHandler_RefreshWithInvalidToken() {
|
||||
req := &authpb.RefreshRequest{
|
||||
RefreshToken: "invalid-refresh-token",
|
||||
}
|
||||
|
||||
resp, err := s.authClient.Refresh(context.Background(), req)
|
||||
|
||||
s.Error(err)
|
||||
s.Nil(resp)
|
||||
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Equal(codes.Unauthenticated, st.Code())
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestAuthHandler_LogoutWithInvalidToken() {
|
||||
req := &authpb.LogoutRequest{
|
||||
AccessToken: "invalid-token",
|
||||
}
|
||||
|
||||
resp, err := s.authClient.Logout(context.Background(), req)
|
||||
|
||||
s.NoError(err)
|
||||
s.NotNil(resp)
|
||||
s.True(resp.Success)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestAuthHandler_RefreshTokenFlow() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
s.NotNil(loginResp)
|
||||
s.NotEmpty(loginResp.AccessToken)
|
||||
s.NotEmpty(loginResp.RefreshToken)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
s.NotNil(validateResp)
|
||||
s.True(validateResp.Valid)
|
||||
|
||||
refreshReq := &authpb.RefreshRequest{
|
||||
RefreshToken: loginResp.RefreshToken,
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
refreshResp, err := s.authClient.Refresh(ctx, refreshReq)
|
||||
s.NoError(err)
|
||||
s.NotNil(refreshResp)
|
||||
s.NotEmpty(refreshResp.AccessToken)
|
||||
|
||||
logoutReq := &authpb.LogoutRequest{
|
||||
AccessToken: refreshResp.AccessToken,
|
||||
}
|
||||
|
||||
logoutResp, err := s.authClient.Logout(ctx, logoutReq)
|
||||
s.NoError(err)
|
||||
s.NotNil(logoutResp)
|
||||
s.True(logoutResp.Success)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestAuthHandler_LogoutInvalidatesSession() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
s.NotEmpty(loginResp.AccessToken)
|
||||
|
||||
logoutReq := &authpb.LogoutRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
logoutResp, err := s.authClient.Logout(ctx, logoutReq)
|
||||
s.NoError(err)
|
||||
s.True(logoutResp.Success)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
s.NotNil(validateResp)
|
||||
s.False(validateResp.Valid)
|
||||
}
|
||||
1105
internal/grpc/tests/concurrent_test.go
Normal file
1105
internal/grpc/tests/concurrent_test.go
Normal file
File diff suppressed because it is too large
Load Diff
285
internal/grpc/tests/edge_cases_test.go
Normal file
285
internal/grpc/tests/edge_cases_test.go
Normal file
@@ -0,0 +1,285 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
authpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/auth"
|
||||
invitepb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/invite"
|
||||
requestpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/request"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func (s *IntegrationSuite) TestEdgeCase_CreateTZWithEmptyRequestText() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
|
||||
req := &requestpb.CreateTZRequest{
|
||||
UserId: validateResp.UserId,
|
||||
RequestTxt: "",
|
||||
}
|
||||
|
||||
resp, err := s.requestClient.CreateTZ(ctx, req)
|
||||
|
||||
if err != nil {
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Contains([]codes.Code{codes.InvalidArgument, codes.Internal}, st.Code())
|
||||
return
|
||||
}
|
||||
|
||||
s.NotNil(resp)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestEdgeCase_GenerateInviteWithZeroMaxUses() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
|
||||
req := &invitepb.GenerateRequest{
|
||||
UserId: validateResp.UserId,
|
||||
TtlDays: 30,
|
||||
MaxUses: 0,
|
||||
}
|
||||
|
||||
resp, err := s.inviteClient.Generate(ctx, req)
|
||||
|
||||
if err != nil {
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Contains([]codes.Code{codes.InvalidArgument, codes.Internal}, st.Code())
|
||||
return
|
||||
}
|
||||
|
||||
s.NotNil(resp)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestEdgeCase_GenerateInviteWithZeroTTL() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
|
||||
req := &invitepb.GenerateRequest{
|
||||
UserId: validateResp.UserId,
|
||||
TtlDays: 0,
|
||||
MaxUses: 10,
|
||||
}
|
||||
|
||||
resp, err := s.inviteClient.Generate(ctx, req)
|
||||
|
||||
if err != nil {
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Contains([]codes.Code{codes.InvalidArgument, codes.Internal}, st.Code())
|
||||
return
|
||||
}
|
||||
|
||||
s.NotNil(resp)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestEdgeCase_ApproveTZWithEmptyFinalTZ() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
|
||||
createReq := &requestpb.CreateTZRequest{
|
||||
UserId: validateResp.UserId,
|
||||
RequestTxt: "Test request",
|
||||
}
|
||||
|
||||
createResp, err := s.requestClient.CreateTZ(ctx, createReq)
|
||||
if err != nil {
|
||||
s.T().Skip("Cannot test ApproveTZ without CreateTZ")
|
||||
return
|
||||
}
|
||||
|
||||
approveReq := &requestpb.ApproveTZRequest{
|
||||
RequestId: createResp.RequestId,
|
||||
FinalTz: "",
|
||||
UserId: validateResp.UserId,
|
||||
}
|
||||
|
||||
approveResp, err := s.requestClient.ApproveTZ(ctx, approveReq)
|
||||
|
||||
if err != nil {
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Contains([]codes.Code{codes.InvalidArgument, codes.Internal}, st.Code())
|
||||
return
|
||||
}
|
||||
|
||||
s.NotNil(approveResp)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestEdgeCase_DoubleLogout() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
|
||||
logoutReq := &authpb.LogoutRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
logoutResp1, err := s.authClient.Logout(ctx, logoutReq)
|
||||
s.NoError(err)
|
||||
s.True(logoutResp1.Success)
|
||||
|
||||
logoutResp2, err := s.authClient.Logout(ctx, logoutReq)
|
||||
s.NoError(err)
|
||||
s.True(logoutResp2.Success)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestEdgeCase_ValidateAfterLogout() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
|
||||
logoutReq := &authpb.LogoutRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
logoutResp, err := s.authClient.Logout(ctx, logoutReq)
|
||||
s.NoError(err)
|
||||
s.True(logoutResp.Success)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
s.False(validateResp.Valid)
|
||||
s.Equal(int64(0), validateResp.UserId)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestEdgeCase_RefreshAfterLogout() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
|
||||
logoutReq := &authpb.LogoutRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
logoutResp, err := s.authClient.Logout(ctx, logoutReq)
|
||||
s.NoError(err)
|
||||
s.True(logoutResp.Success)
|
||||
|
||||
refreshReq := &authpb.RefreshRequest{
|
||||
RefreshToken: loginResp.RefreshToken,
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
refreshResp, err := s.authClient.Refresh(ctx, refreshReq)
|
||||
s.Error(err)
|
||||
s.Nil(refreshResp)
|
||||
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Equal(codes.Unauthenticated, st.Code())
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestEdgeCase_LoginWithWrongPassword() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "wrongpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.Error(err)
|
||||
s.Nil(loginResp)
|
||||
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Equal(codes.Unauthenticated, st.Code())
|
||||
}
|
||||
239
internal/grpc/tests/full_flow_test.go
Normal file
239
internal/grpc/tests/full_flow_test.go
Normal file
@@ -0,0 +1,239 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
authpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/auth"
|
||||
invitepb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/invite"
|
||||
requestpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/request"
|
||||
supplierpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/supplier"
|
||||
userpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/user"
|
||||
)
|
||||
|
||||
func (s *IntegrationSuite) TestFullFlow_CompleteRequestLifecycle() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
s.NotEmpty(loginResp.AccessToken)
|
||||
s.NotEmpty(loginResp.RefreshToken)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
s.True(validateResp.Valid)
|
||||
userID := validateResp.UserId
|
||||
|
||||
getUserInfoReq := &userpb.GetInfoRequest{
|
||||
UserId: userID,
|
||||
}
|
||||
|
||||
userInfoResp, err := s.userClient.GetInfo(ctx, getUserInfoReq)
|
||||
s.NoError(err)
|
||||
s.NotNil(userInfoResp)
|
||||
s.Equal("test@example.com", userInfoResp.Email)
|
||||
|
||||
getBalanceReq := &userpb.GetBalanceRequest{
|
||||
UserId: userID,
|
||||
}
|
||||
|
||||
balanceResp, err := s.userClient.GetBalance(ctx, getBalanceReq)
|
||||
s.NoError(err)
|
||||
s.GreaterOrEqual(balanceResp.Balance, 0.0)
|
||||
|
||||
createTZReq := &requestpb.CreateTZRequest{
|
||||
UserId: userID,
|
||||
RequestTxt: "Нужны поставщики металлоконструкций",
|
||||
}
|
||||
|
||||
createTZResp, err := s.requestClient.CreateTZ(ctx, createTZReq)
|
||||
if err != nil {
|
||||
s.T().Logf("CreateTZ failed: %v", err)
|
||||
return
|
||||
}
|
||||
s.NotEmpty(createTZResp.RequestId)
|
||||
s.NotEmpty(createTZResp.TzText)
|
||||
requestID := createTZResp.RequestId
|
||||
|
||||
approveTZReq := &requestpb.ApproveTZRequest{
|
||||
RequestId: requestID,
|
||||
FinalTz: "Утвержденное ТЗ для поставщиков металлоконструкций",
|
||||
UserId: userID,
|
||||
}
|
||||
|
||||
approveTZResp, err := s.requestClient.ApproveTZ(ctx, approveTZReq)
|
||||
if err != nil {
|
||||
s.T().Logf("ApproveTZ failed: %v", err)
|
||||
return
|
||||
}
|
||||
s.True(approveTZResp.Success)
|
||||
|
||||
getMailingListReq := &requestpb.GetMailingListRequest{
|
||||
UserId: userID,
|
||||
}
|
||||
|
||||
mailingListResp, err := s.requestClient.GetMailingList(ctx, getMailingListReq)
|
||||
s.NoError(err)
|
||||
s.NotNil(mailingListResp.Items)
|
||||
s.GreaterOrEqual(len(mailingListResp.Items), 1)
|
||||
|
||||
getMailingListByIDReq := &requestpb.GetMailingListByIDRequest{
|
||||
RequestId: requestID,
|
||||
UserId: userID,
|
||||
}
|
||||
|
||||
mailingListByIDResp, err := s.requestClient.GetMailingListByID(ctx, getMailingListByIDReq)
|
||||
if err != nil {
|
||||
s.T().Logf("GetMailingListByID failed: %v", err)
|
||||
return
|
||||
}
|
||||
s.NotNil(mailingListByIDResp.Item)
|
||||
s.Equal(requestID, mailingListByIDResp.Item.RequestId)
|
||||
|
||||
exportExcelReq := &supplierpb.ExportExcelRequest{
|
||||
RequestId: requestID,
|
||||
UserId: userID,
|
||||
}
|
||||
|
||||
exportExcelResp, err := s.supplierClient.ExportExcel(ctx, exportExcelReq)
|
||||
if err != nil {
|
||||
s.T().Logf("ExportExcel failed (expected if no suppliers): %v", err)
|
||||
} else {
|
||||
s.NotNil(exportExcelResp)
|
||||
s.NotEmpty(exportExcelResp.FileName)
|
||||
}
|
||||
|
||||
getStatisticsReq := &userpb.GetStatisticsRequest{
|
||||
UserId: userID,
|
||||
}
|
||||
|
||||
statisticsResp, err := s.userClient.GetStatistics(ctx, getStatisticsReq)
|
||||
s.NoError(err)
|
||||
s.GreaterOrEqual(statisticsResp.TotalRequests, int32(0))
|
||||
|
||||
logoutReq := &authpb.LogoutRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
logoutResp, err := s.authClient.Logout(ctx, logoutReq)
|
||||
s.NoError(err)
|
||||
s.True(logoutResp.Success)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestFullFlow_InviteCodeLifecycle() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
userID := validateResp.UserId
|
||||
|
||||
generateInviteReq := &invitepb.GenerateRequest{
|
||||
UserId: userID,
|
||||
TtlDays: 7,
|
||||
MaxUses: 5,
|
||||
}
|
||||
|
||||
generateInviteResp, err := s.inviteClient.Generate(ctx, generateInviteReq)
|
||||
s.NoError(err)
|
||||
s.NotEmpty(generateInviteResp.Code)
|
||||
s.Greater(generateInviteResp.MaxUses, int32(0))
|
||||
inviteCode := generateInviteResp.Code
|
||||
|
||||
getInviteInfoReq := &invitepb.GetInfoRequest{
|
||||
Code: inviteCode,
|
||||
}
|
||||
|
||||
inviteInfoResp, err := s.inviteClient.GetInfo(ctx, getInviteInfoReq)
|
||||
s.NoError(err)
|
||||
s.Equal(inviteCode, inviteInfoResp.Code)
|
||||
s.Equal(userID, inviteInfoResp.UserId)
|
||||
s.Equal(generateInviteResp.MaxUses, inviteInfoResp.CanBeUsedCount)
|
||||
s.Equal(int32(0), inviteInfoResp.UsedCount)
|
||||
s.True(inviteInfoResp.IsActive)
|
||||
|
||||
logoutReq := &authpb.LogoutRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
logoutResp, err := s.authClient.Logout(ctx, logoutReq)
|
||||
s.NoError(err)
|
||||
s.True(logoutResp.Success)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestFullFlow_MultipleRefresh() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
s.NotEmpty(loginResp.AccessToken)
|
||||
s.NotEmpty(loginResp.RefreshToken)
|
||||
|
||||
refreshToken := loginResp.RefreshToken
|
||||
|
||||
refreshReq1 := &authpb.RefreshRequest{
|
||||
RefreshToken: refreshToken,
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
refreshResp1, err := s.authClient.Refresh(ctx, refreshReq1)
|
||||
s.NoError(err)
|
||||
s.NotEmpty(refreshResp1.AccessToken)
|
||||
|
||||
refreshReq2 := &authpb.RefreshRequest{
|
||||
RefreshToken: refreshToken,
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
refreshResp2, err := s.authClient.Refresh(ctx, refreshReq2)
|
||||
s.NoError(err)
|
||||
s.NotEmpty(refreshResp2.AccessToken)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: refreshResp2.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
s.True(validateResp.Valid)
|
||||
|
||||
logoutReq := &authpb.LogoutRequest{
|
||||
AccessToken: refreshResp2.AccessToken,
|
||||
}
|
||||
|
||||
logoutResp, err := s.authClient.Logout(ctx, logoutReq)
|
||||
s.NoError(err)
|
||||
s.True(logoutResp.Success)
|
||||
}
|
||||
211
internal/grpc/tests/integration_suite_test.go
Normal file
211
internal/grpc/tests/integration_suite_test.go
Normal file
@@ -0,0 +1,211 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/postgres"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/test/bufconn"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/database"
|
||||
grpchandlers "git.techease.ru/Smart-search/smart-search-back/internal/grpc"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/crypto"
|
||||
authpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/auth"
|
||||
invitepb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/invite"
|
||||
requestpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/request"
|
||||
supplierpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/supplier"
|
||||
userpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/user"
|
||||
)
|
||||
|
||||
const (
|
||||
testJWTSecret = "test-jwt-secret-key-for-integration-tests"
|
||||
testCryptoSecret = "test-crypto-secret-key-for-integration"
|
||||
bufSize = 1024 * 1024
|
||||
)
|
||||
|
||||
type IntegrationSuite struct {
|
||||
suite.Suite
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
pgContainer *postgres.PostgresContainer
|
||||
pool *pgxpool.Pool
|
||||
grpcServer *grpc.Server
|
||||
listener *bufconn.Listener
|
||||
authClient authpb.AuthServiceClient
|
||||
userClient userpb.UserServiceClient
|
||||
inviteClient invitepb.InviteServiceClient
|
||||
requestClient requestpb.RequestServiceClient
|
||||
supplierClient supplierpb.SupplierServiceClient
|
||||
testUserEmail string
|
||||
testUserPassword string
|
||||
testAccessToken string
|
||||
testRefreshToken string
|
||||
}
|
||||
|
||||
func TestIntegrationSuite(t *testing.T) {
|
||||
suite.Run(t, new(IntegrationSuite))
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) SetupSuite() {
|
||||
s.ctx, s.cancel = context.WithCancel(context.Background())
|
||||
|
||||
s.T().Log("Starting PostgreSQL container...")
|
||||
pgContainer, err := postgres.Run(s.ctx,
|
||||
"postgres:15-alpine",
|
||||
postgres.WithDatabase("test_db"),
|
||||
postgres.WithUsername("test_user"),
|
||||
postgres.WithPassword("test_password"),
|
||||
testcontainers.WithWaitStrategy(
|
||||
wait.ForLog("database system is ready to accept connections").
|
||||
WithOccurrence(2).
|
||||
WithStartupTimeout(60*time.Second)),
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
s.pgContainer = pgContainer
|
||||
|
||||
connStr, err := pgContainer.ConnectionString(s.ctx, "sslmode=disable")
|
||||
s.Require().NoError(err)
|
||||
s.T().Logf("PostgreSQL connection string: %s", connStr)
|
||||
|
||||
s.T().Log("Running migrations...")
|
||||
err = database.RunMigrationsFromPath(connStr, "../../../migrations")
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.T().Log("Creating connection pool...")
|
||||
poolConfig, err := pgxpool.ParseConfig(connStr)
|
||||
s.Require().NoError(err)
|
||||
poolConfig.MaxConns = 10
|
||||
|
||||
pool, err := pgxpool.NewWithConfig(s.ctx, poolConfig)
|
||||
s.Require().NoError(err)
|
||||
s.pool = pool
|
||||
|
||||
err = pool.Ping(s.ctx)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.T().Log("Creating gRPC server...")
|
||||
logger, _ := zap.NewDevelopment()
|
||||
|
||||
authHandler, userHandler, inviteHandler, requestHandler, supplierHandler := grpchandlers.NewHandlers(
|
||||
pool,
|
||||
testJWTSecret,
|
||||
testCryptoSecret,
|
||||
"",
|
||||
"",
|
||||
logger,
|
||||
)
|
||||
|
||||
s.listener = bufconn.Listen(bufSize)
|
||||
s.grpcServer = grpc.NewServer()
|
||||
|
||||
grpchandlers.RegisterServices(s.grpcServer, authHandler, userHandler, inviteHandler, requestHandler, supplierHandler)
|
||||
|
||||
go func() {
|
||||
if err := s.grpcServer.Serve(s.listener); err != nil {
|
||||
s.T().Logf("gRPC server error: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
s.T().Log("Creating gRPC clients...")
|
||||
conn, err := grpc.NewClient("passthrough://bufnet",
|
||||
grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) {
|
||||
return s.listener.Dial()
|
||||
}),
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.authClient = authpb.NewAuthServiceClient(conn)
|
||||
s.userClient = userpb.NewUserServiceClient(conn)
|
||||
s.inviteClient = invitepb.NewInviteServiceClient(conn)
|
||||
s.requestClient = requestpb.NewRequestServiceClient(conn)
|
||||
s.supplierClient = supplierpb.NewSupplierServiceClient(conn)
|
||||
|
||||
s.testUserEmail = fmt.Sprintf("test_%d@example.com", time.Now().Unix())
|
||||
s.testUserPassword = "testpassword123"
|
||||
|
||||
s.T().Log("Creating test user...")
|
||||
s.createTestUser("test@example.com", "testpassword")
|
||||
|
||||
s.T().Log("Integration suite setup completed")
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) createTestUser(email, password string) {
|
||||
cryptoHelper := crypto.NewCrypto(testCryptoSecret)
|
||||
|
||||
encryptedEmail, err := cryptoHelper.Encrypt(email)
|
||||
s.Require().NoError(err)
|
||||
|
||||
encryptedPhone, err := cryptoHelper.Encrypt("+1234567890")
|
||||
s.Require().NoError(err)
|
||||
|
||||
encryptedUserName, err := cryptoHelper.Encrypt("Test User")
|
||||
s.Require().NoError(err)
|
||||
|
||||
emailHash := cryptoHelper.EmailHash(email)
|
||||
passwordHash := crypto.PasswordHash(password)
|
||||
|
||||
query := `
|
||||
INSERT INTO users (email, email_hash, password_hash, phone, user_name, company_name, balance, payment_status, invites_issued, invites_limit)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
ON CONFLICT (email_hash) DO NOTHING
|
||||
`
|
||||
|
||||
_, err = s.pool.Exec(s.ctx, query,
|
||||
encryptedEmail,
|
||||
emailHash,
|
||||
passwordHash,
|
||||
encryptedPhone,
|
||||
encryptedUserName,
|
||||
"Test Company",
|
||||
1000.0,
|
||||
"active",
|
||||
0,
|
||||
10,
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TearDownSuite() {
|
||||
s.T().Log("Tearing down integration suite...")
|
||||
|
||||
if s.grpcServer != nil {
|
||||
s.grpcServer.Stop()
|
||||
}
|
||||
|
||||
if s.pool != nil {
|
||||
s.pool.Close()
|
||||
}
|
||||
|
||||
if s.pgContainer != nil {
|
||||
if err := s.pgContainer.Terminate(s.ctx); err != nil {
|
||||
s.T().Logf("Failed to terminate PostgreSQL container: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if s.cancel != nil {
|
||||
s.cancel()
|
||||
}
|
||||
|
||||
s.T().Log("Integration suite teardown completed")
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TearDownTest() {
|
||||
s.testAccessToken = ""
|
||||
s.testRefreshToken = ""
|
||||
|
||||
_, _ = s.pool.Exec(s.ctx, "DELETE FROM sessions")
|
||||
_, _ = s.pool.Exec(s.ctx, "DELETE FROM invite_codes")
|
||||
_, _ = s.pool.Exec(s.ctx, "DELETE FROM suppliers")
|
||||
_, _ = s.pool.Exec(s.ctx, "DELETE FROM requests_for_suppliers")
|
||||
}
|
||||
122
internal/grpc/tests/invite_handler_test.go
Normal file
122
internal/grpc/tests/invite_handler_test.go
Normal file
@@ -0,0 +1,122 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
authpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/auth"
|
||||
invitepb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/invite"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func (s *IntegrationSuite) TestInviteHandler_GenerateWithNonExistentUser() {
|
||||
req := &invitepb.GenerateRequest{
|
||||
UserId: 999999,
|
||||
TtlDays: 30,
|
||||
MaxUses: 10,
|
||||
}
|
||||
|
||||
resp, err := s.inviteClient.Generate(context.Background(), req)
|
||||
|
||||
s.Error(err)
|
||||
s.Nil(resp)
|
||||
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Contains([]codes.Code{codes.NotFound, codes.Internal, codes.Unknown}, st.Code())
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestInviteHandler_GetInfoWithInvalidCode() {
|
||||
req := &invitepb.GetInfoRequest{
|
||||
Code: "999999999",
|
||||
}
|
||||
|
||||
resp, err := s.inviteClient.GetInfo(context.Background(), req)
|
||||
|
||||
s.Error(err)
|
||||
s.Nil(resp)
|
||||
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Equal(codes.NotFound, st.Code())
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestInviteHandler_GetInfoWithInvalidCodeFormat() {
|
||||
req := &invitepb.GetInfoRequest{
|
||||
Code: "invalid-code",
|
||||
}
|
||||
|
||||
resp, err := s.inviteClient.GetInfo(context.Background(), req)
|
||||
|
||||
s.Error(err)
|
||||
s.Nil(resp)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestInviteHandler_GenerateAndGetInfoFlow() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
s.True(validateResp.Valid)
|
||||
|
||||
generateReq := &invitepb.GenerateRequest{
|
||||
UserId: validateResp.UserId,
|
||||
TtlDays: 30,
|
||||
MaxUses: 10,
|
||||
}
|
||||
|
||||
generateResp, err := s.inviteClient.Generate(ctx, generateReq)
|
||||
s.NoError(err)
|
||||
s.NotNil(generateResp)
|
||||
s.NotEmpty(generateResp.Code)
|
||||
s.Greater(generateResp.MaxUses, int32(0))
|
||||
s.NotNil(generateResp.ExpiresAt)
|
||||
|
||||
getInfoReq := &invitepb.GetInfoRequest{
|
||||
Code: generateResp.Code,
|
||||
}
|
||||
|
||||
infoResp, err := s.inviteClient.GetInfo(ctx, getInfoReq)
|
||||
s.NoError(err)
|
||||
s.NotNil(infoResp)
|
||||
s.Equal(generateResp.Code, infoResp.Code)
|
||||
s.Equal(validateResp.UserId, infoResp.UserId)
|
||||
s.Equal(generateResp.MaxUses, infoResp.CanBeUsedCount)
|
||||
s.Equal(int32(0), infoResp.UsedCount)
|
||||
s.True(infoResp.IsActive)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestInviteHandler_GenerateWithInvalidTTL() {
|
||||
ctx := context.Background()
|
||||
|
||||
req := &invitepb.GenerateRequest{
|
||||
UserId: 1,
|
||||
TtlDays: -1,
|
||||
MaxUses: 10,
|
||||
}
|
||||
|
||||
resp, err := s.inviteClient.Generate(ctx, req)
|
||||
|
||||
if err != nil {
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Contains([]codes.Code{codes.InvalidArgument, codes.Internal, codes.Unknown}, st.Code())
|
||||
return
|
||||
}
|
||||
|
||||
s.NotNil(resp)
|
||||
}
|
||||
138
internal/grpc/tests/request_handler_test.go
Normal file
138
internal/grpc/tests/request_handler_test.go
Normal file
@@ -0,0 +1,138 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
authpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/auth"
|
||||
requestpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/request"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func (s *IntegrationSuite) TestRequestHandler_CreateTZWithNonExistentUser() {
|
||||
req := &requestpb.CreateTZRequest{
|
||||
UserId: 999999,
|
||||
RequestTxt: "Нужны поставщики металлоконструкций",
|
||||
}
|
||||
|
||||
resp, err := s.requestClient.CreateTZ(context.Background(), req)
|
||||
|
||||
s.Error(err)
|
||||
s.Nil(resp)
|
||||
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Contains([]codes.Code{codes.NotFound, codes.Internal, codes.Unknown}, st.Code())
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestRequestHandler_GetMailingListByIDWithNonExistent() {
|
||||
req := &requestpb.GetMailingListByIDRequest{
|
||||
RequestId: "999999",
|
||||
UserId: 1,
|
||||
}
|
||||
|
||||
resp, err := s.requestClient.GetMailingListByID(context.Background(), req)
|
||||
|
||||
s.Error(err)
|
||||
s.Nil(resp)
|
||||
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Contains([]codes.Code{codes.NotFound, codes.Internal, codes.Unknown}, st.Code())
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestRequestHandler_GetMailingListWithNonExistentUser() {
|
||||
req := &requestpb.GetMailingListRequest{
|
||||
UserId: 999999,
|
||||
}
|
||||
|
||||
resp, err := s.requestClient.GetMailingList(context.Background(), req)
|
||||
|
||||
if err != nil {
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Contains([]codes.Code{codes.NotFound, codes.Internal}, st.Code())
|
||||
return
|
||||
}
|
||||
|
||||
s.NotNil(resp)
|
||||
s.Equal(0, len(resp.Items))
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestRequestHandler_ApproveTZWithInvalidRequest() {
|
||||
req := &requestpb.ApproveTZRequest{
|
||||
RequestId: "999999",
|
||||
FinalTz: "Approved TZ",
|
||||
UserId: 1,
|
||||
}
|
||||
|
||||
resp, err := s.requestClient.ApproveTZ(context.Background(), req)
|
||||
|
||||
s.Error(err)
|
||||
s.Nil(resp)
|
||||
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Contains([]codes.Code{codes.NotFound, codes.Internal, codes.Unknown, codes.InvalidArgument}, st.Code())
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestRequestHandler_CreateTZWithValidUser() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
|
||||
req := &requestpb.CreateTZRequest{
|
||||
UserId: validateResp.UserId,
|
||||
RequestTxt: "Нужны поставщики металлоконструкций",
|
||||
}
|
||||
|
||||
resp, err := s.requestClient.CreateTZ(ctx, req)
|
||||
s.NoError(err)
|
||||
s.NotNil(resp)
|
||||
s.NotEmpty(resp.RequestId)
|
||||
s.NotEmpty(resp.TzText)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestRequestHandler_GetMailingListWithValidUser() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
|
||||
req := &requestpb.GetMailingListRequest{
|
||||
UserId: validateResp.UserId,
|
||||
}
|
||||
|
||||
resp, err := s.requestClient.GetMailingList(ctx, req)
|
||||
s.NoError(err)
|
||||
s.NotNil(resp)
|
||||
}
|
||||
95
internal/grpc/tests/supplier_handler_test.go
Normal file
95
internal/grpc/tests/supplier_handler_test.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
authpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/auth"
|
||||
requestpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/request"
|
||||
supplierpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/supplier"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func (s *IntegrationSuite) TestSupplierHandler_ExportExcelWithNonExistentRequest() {
|
||||
req := &supplierpb.ExportExcelRequest{
|
||||
RequestId: "999999",
|
||||
UserId: 1,
|
||||
}
|
||||
|
||||
resp, err := s.supplierClient.ExportExcel(context.Background(), req)
|
||||
|
||||
s.Error(err)
|
||||
s.Nil(resp)
|
||||
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Contains([]codes.Code{codes.NotFound, codes.Internal, codes.Unknown, codes.InvalidArgument}, st.Code())
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestSupplierHandler_ExportExcelWithInvalidUser() {
|
||||
req := &supplierpb.ExportExcelRequest{
|
||||
RequestId: "1",
|
||||
UserId: 999999,
|
||||
}
|
||||
|
||||
resp, err := s.supplierClient.ExportExcel(context.Background(), req)
|
||||
|
||||
if err != nil {
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Contains([]codes.Code{codes.NotFound, codes.PermissionDenied, codes.Internal, codes.Unknown, codes.InvalidArgument}, st.Code())
|
||||
return
|
||||
}
|
||||
|
||||
s.NotNil(resp)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestSupplierHandler_ExportExcelWithValidRequest() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
|
||||
createReq := &requestpb.CreateTZRequest{
|
||||
UserId: validateResp.UserId,
|
||||
RequestTxt: "Нужны поставщики кирпича",
|
||||
}
|
||||
|
||||
createResp, err := s.requestClient.CreateTZ(ctx, createReq)
|
||||
if err != nil {
|
||||
s.T().Skip("Cannot test ExportExcel without CreateTZ")
|
||||
return
|
||||
}
|
||||
|
||||
exportReq := &supplierpb.ExportExcelRequest{
|
||||
RequestId: createResp.RequestId,
|
||||
UserId: validateResp.UserId,
|
||||
}
|
||||
|
||||
exportResp, err := s.supplierClient.ExportExcel(ctx, exportReq)
|
||||
|
||||
if err != nil {
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Contains([]codes.Code{codes.NotFound, codes.Internal}, st.Code())
|
||||
return
|
||||
}
|
||||
|
||||
s.NotNil(exportResp)
|
||||
s.NotEmpty(exportResp.FileName)
|
||||
s.Equal("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", exportResp.MimeType)
|
||||
}
|
||||
174
internal/grpc/tests/user_handler_test.go
Normal file
174
internal/grpc/tests/user_handler_test.go
Normal file
@@ -0,0 +1,174 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
authpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/auth"
|
||||
userpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/user"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func (s *IntegrationSuite) TestUserHandler_GetInfoWithNonExistentUser() {
|
||||
req := &userpb.GetInfoRequest{
|
||||
UserId: 999999,
|
||||
}
|
||||
|
||||
resp, err := s.userClient.GetInfo(context.Background(), req)
|
||||
|
||||
s.Error(err)
|
||||
s.Nil(resp)
|
||||
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Equal(codes.NotFound, st.Code())
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestUserHandler_GetBalanceWithNonExistentUser() {
|
||||
req := &userpb.GetBalanceRequest{
|
||||
UserId: 999999,
|
||||
}
|
||||
|
||||
resp, err := s.userClient.GetBalance(context.Background(), req)
|
||||
|
||||
s.Error(err)
|
||||
s.Nil(resp)
|
||||
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Equal(codes.NotFound, st.Code())
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestUserHandler_GetStatisticsWithNonExistentUser() {
|
||||
req := &userpb.GetStatisticsRequest{
|
||||
UserId: 999999,
|
||||
}
|
||||
|
||||
resp, err := s.userClient.GetStatistics(context.Background(), req)
|
||||
|
||||
if err != nil {
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Equal(codes.NotFound, st.Code())
|
||||
return
|
||||
}
|
||||
|
||||
s.NotNil(resp)
|
||||
s.Equal(int32(0), resp.TotalRequests)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestUserHandler_GetBalanceStatistics() {
|
||||
req := &userpb.GetBalanceStatisticsRequest{
|
||||
UserId: 1,
|
||||
}
|
||||
|
||||
resp, err := s.userClient.GetBalanceStatistics(context.Background(), req)
|
||||
|
||||
if err != nil {
|
||||
st, ok := status.FromError(err)
|
||||
s.True(ok)
|
||||
s.Equal(codes.NotFound, st.Code())
|
||||
return
|
||||
}
|
||||
|
||||
s.NotNil(resp)
|
||||
s.GreaterOrEqual(resp.Balance, 0.0)
|
||||
s.GreaterOrEqual(resp.TotalRequests, int32(0))
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestUserHandler_GetInfoWithValidUser() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
|
||||
req := &userpb.GetInfoRequest{
|
||||
UserId: validateResp.UserId,
|
||||
}
|
||||
|
||||
resp, err := s.userClient.GetInfo(ctx, req)
|
||||
s.NoError(err)
|
||||
s.NotNil(resp)
|
||||
s.Equal("test@example.com", resp.Email)
|
||||
s.Equal("Test User", resp.Name)
|
||||
s.Equal("+1234567890", resp.Phone)
|
||||
s.Equal("Test Company", resp.CompanyName)
|
||||
s.Equal("active", resp.PaymentStatus)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestUserHandler_GetBalanceWithValidUser() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
|
||||
req := &userpb.GetBalanceRequest{
|
||||
UserId: validateResp.UserId,
|
||||
}
|
||||
|
||||
resp, err := s.userClient.GetBalance(ctx, req)
|
||||
s.NoError(err)
|
||||
s.NotNil(resp)
|
||||
s.GreaterOrEqual(resp.Balance, 0.0)
|
||||
}
|
||||
|
||||
func (s *IntegrationSuite) TestUserHandler_GetStatisticsWithValidUser() {
|
||||
ctx := context.Background()
|
||||
|
||||
loginReq := &authpb.LoginRequest{
|
||||
Email: "test@example.com",
|
||||
Password: "testpassword",
|
||||
Ip: "127.0.0.1",
|
||||
UserAgent: "integration-test",
|
||||
}
|
||||
|
||||
loginResp, err := s.authClient.Login(ctx, loginReq)
|
||||
s.NoError(err)
|
||||
|
||||
validateReq := &authpb.ValidateRequest{
|
||||
AccessToken: loginResp.AccessToken,
|
||||
}
|
||||
|
||||
validateResp, err := s.authClient.Validate(ctx, validateReq)
|
||||
s.NoError(err)
|
||||
|
||||
req := &userpb.GetStatisticsRequest{
|
||||
UserId: validateResp.UserId,
|
||||
}
|
||||
|
||||
resp, err := s.userClient.GetStatistics(ctx, req)
|
||||
s.NoError(err)
|
||||
s.NotNil(resp)
|
||||
s.GreaterOrEqual(resp.TotalRequests, int32(0))
|
||||
s.GreaterOrEqual(resp.SuccessfulRequests, int32(0))
|
||||
s.GreaterOrEqual(resp.FailedRequests, int32(0))
|
||||
s.GreaterOrEqual(resp.TotalSpent, 0.0)
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package grpc
|
||||
import (
|
||||
"context"
|
||||
|
||||
"smart-search-back/pkg/errors"
|
||||
pb "smart-search-back/pkg/pb/api/proto/user"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
pb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/user"
|
||||
)
|
||||
|
||||
func (h *UserHandler) GetInfo(ctx context.Context, req *pb.GetInfoRequest) (*pb.GetInfoResponse, error) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
package mocks
|
||||
|
||||
//go:generate minimock -i smart-search-back/internal/service.AuthService -o auth_service_mock.go -n AuthServiceMock -p mocks
|
||||
//go:generate minimock -i git.techease.ru/Smart-search/smart-search-back/internal/service.AuthService -o auth_service_mock.go -n AuthServiceMock -p mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -25,9 +25,9 @@ type AuthServiceMock struct {
|
||||
beforeLoginCounter uint64
|
||||
LoginMock mAuthServiceMockLogin
|
||||
|
||||
funcLogout func(ctx context.Context, refreshToken string) (err error)
|
||||
funcLogout func(ctx context.Context, accessToken string) (err error)
|
||||
funcLogoutOrigin string
|
||||
inspectFuncLogout func(ctx context.Context, refreshToken string)
|
||||
inspectFuncLogout func(ctx context.Context, accessToken string)
|
||||
afterLogoutCounter uint64
|
||||
beforeLogoutCounter uint64
|
||||
LogoutMock mAuthServiceMockLogout
|
||||
@@ -535,14 +535,14 @@ type AuthServiceMockLogoutExpectation struct {
|
||||
|
||||
// AuthServiceMockLogoutParams contains parameters of the AuthService.Logout
|
||||
type AuthServiceMockLogoutParams struct {
|
||||
ctx context.Context
|
||||
refreshToken string
|
||||
ctx context.Context
|
||||
accessToken string
|
||||
}
|
||||
|
||||
// AuthServiceMockLogoutParamPtrs contains pointers to parameters of the AuthService.Logout
|
||||
type AuthServiceMockLogoutParamPtrs struct {
|
||||
ctx *context.Context
|
||||
refreshToken *string
|
||||
ctx *context.Context
|
||||
accessToken *string
|
||||
}
|
||||
|
||||
// AuthServiceMockLogoutResults contains results of the AuthService.Logout
|
||||
@@ -552,9 +552,9 @@ type AuthServiceMockLogoutResults struct {
|
||||
|
||||
// AuthServiceMockLogoutOrigins contains origins of expectations of the AuthService.Logout
|
||||
type AuthServiceMockLogoutExpectationOrigins struct {
|
||||
origin string
|
||||
originCtx string
|
||||
originRefreshToken string
|
||||
origin string
|
||||
originCtx string
|
||||
originAccessToken string
|
||||
}
|
||||
|
||||
// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning
|
||||
@@ -568,7 +568,7 @@ func (mmLogout *mAuthServiceMockLogout) Optional() *mAuthServiceMockLogout {
|
||||
}
|
||||
|
||||
// Expect sets up expected params for AuthService.Logout
|
||||
func (mmLogout *mAuthServiceMockLogout) Expect(ctx context.Context, refreshToken string) *mAuthServiceMockLogout {
|
||||
func (mmLogout *mAuthServiceMockLogout) Expect(ctx context.Context, accessToken string) *mAuthServiceMockLogout {
|
||||
if mmLogout.mock.funcLogout != nil {
|
||||
mmLogout.mock.t.Fatalf("AuthServiceMock.Logout mock is already set by Set")
|
||||
}
|
||||
@@ -581,7 +581,7 @@ func (mmLogout *mAuthServiceMockLogout) Expect(ctx context.Context, refreshToken
|
||||
mmLogout.mock.t.Fatalf("AuthServiceMock.Logout mock is already set by ExpectParams functions")
|
||||
}
|
||||
|
||||
mmLogout.defaultExpectation.params = &AuthServiceMockLogoutParams{ctx, refreshToken}
|
||||
mmLogout.defaultExpectation.params = &AuthServiceMockLogoutParams{ctx, accessToken}
|
||||
mmLogout.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1)
|
||||
for _, e := range mmLogout.expectations {
|
||||
if minimock.Equal(e.params, mmLogout.defaultExpectation.params) {
|
||||
@@ -615,8 +615,8 @@ func (mmLogout *mAuthServiceMockLogout) ExpectCtxParam1(ctx context.Context) *mA
|
||||
return mmLogout
|
||||
}
|
||||
|
||||
// ExpectRefreshTokenParam2 sets up expected param refreshToken for AuthService.Logout
|
||||
func (mmLogout *mAuthServiceMockLogout) ExpectRefreshTokenParam2(refreshToken string) *mAuthServiceMockLogout {
|
||||
// ExpectAccessTokenParam2 sets up expected param accessToken for AuthService.Logout
|
||||
func (mmLogout *mAuthServiceMockLogout) ExpectAccessTokenParam2(accessToken string) *mAuthServiceMockLogout {
|
||||
if mmLogout.mock.funcLogout != nil {
|
||||
mmLogout.mock.t.Fatalf("AuthServiceMock.Logout mock is already set by Set")
|
||||
}
|
||||
@@ -632,14 +632,14 @@ func (mmLogout *mAuthServiceMockLogout) ExpectRefreshTokenParam2(refreshToken st
|
||||
if mmLogout.defaultExpectation.paramPtrs == nil {
|
||||
mmLogout.defaultExpectation.paramPtrs = &AuthServiceMockLogoutParamPtrs{}
|
||||
}
|
||||
mmLogout.defaultExpectation.paramPtrs.refreshToken = &refreshToken
|
||||
mmLogout.defaultExpectation.expectationOrigins.originRefreshToken = minimock.CallerInfo(1)
|
||||
mmLogout.defaultExpectation.paramPtrs.accessToken = &accessToken
|
||||
mmLogout.defaultExpectation.expectationOrigins.originAccessToken = minimock.CallerInfo(1)
|
||||
|
||||
return mmLogout
|
||||
}
|
||||
|
||||
// Inspect accepts an inspector function that has same arguments as the AuthService.Logout
|
||||
func (mmLogout *mAuthServiceMockLogout) Inspect(f func(ctx context.Context, refreshToken string)) *mAuthServiceMockLogout {
|
||||
func (mmLogout *mAuthServiceMockLogout) Inspect(f func(ctx context.Context, accessToken string)) *mAuthServiceMockLogout {
|
||||
if mmLogout.mock.inspectFuncLogout != nil {
|
||||
mmLogout.mock.t.Fatalf("Inspect function is already set for AuthServiceMock.Logout")
|
||||
}
|
||||
@@ -664,7 +664,7 @@ func (mmLogout *mAuthServiceMockLogout) Return(err error) *AuthServiceMock {
|
||||
}
|
||||
|
||||
// Set uses given function f to mock the AuthService.Logout method
|
||||
func (mmLogout *mAuthServiceMockLogout) Set(f func(ctx context.Context, refreshToken string) (err error)) *AuthServiceMock {
|
||||
func (mmLogout *mAuthServiceMockLogout) Set(f func(ctx context.Context, accessToken string) (err error)) *AuthServiceMock {
|
||||
if mmLogout.defaultExpectation != nil {
|
||||
mmLogout.mock.t.Fatalf("Default expectation is already set for the AuthService.Logout method")
|
||||
}
|
||||
@@ -680,14 +680,14 @@ func (mmLogout *mAuthServiceMockLogout) Set(f func(ctx context.Context, refreshT
|
||||
|
||||
// When sets expectation for the AuthService.Logout which will trigger the result defined by the following
|
||||
// Then helper
|
||||
func (mmLogout *mAuthServiceMockLogout) When(ctx context.Context, refreshToken string) *AuthServiceMockLogoutExpectation {
|
||||
func (mmLogout *mAuthServiceMockLogout) When(ctx context.Context, accessToken string) *AuthServiceMockLogoutExpectation {
|
||||
if mmLogout.mock.funcLogout != nil {
|
||||
mmLogout.mock.t.Fatalf("AuthServiceMock.Logout mock is already set by Set")
|
||||
}
|
||||
|
||||
expectation := &AuthServiceMockLogoutExpectation{
|
||||
mock: mmLogout.mock,
|
||||
params: &AuthServiceMockLogoutParams{ctx, refreshToken},
|
||||
params: &AuthServiceMockLogoutParams{ctx, accessToken},
|
||||
expectationOrigins: AuthServiceMockLogoutExpectationOrigins{origin: minimock.CallerInfo(1)},
|
||||
}
|
||||
mmLogout.expectations = append(mmLogout.expectations, expectation)
|
||||
@@ -722,17 +722,17 @@ func (mmLogout *mAuthServiceMockLogout) invocationsDone() bool {
|
||||
}
|
||||
|
||||
// Logout implements mm_service.AuthService
|
||||
func (mmLogout *AuthServiceMock) Logout(ctx context.Context, refreshToken string) (err error) {
|
||||
func (mmLogout *AuthServiceMock) Logout(ctx context.Context, accessToken string) (err error) {
|
||||
mm_atomic.AddUint64(&mmLogout.beforeLogoutCounter, 1)
|
||||
defer mm_atomic.AddUint64(&mmLogout.afterLogoutCounter, 1)
|
||||
|
||||
mmLogout.t.Helper()
|
||||
|
||||
if mmLogout.inspectFuncLogout != nil {
|
||||
mmLogout.inspectFuncLogout(ctx, refreshToken)
|
||||
mmLogout.inspectFuncLogout(ctx, accessToken)
|
||||
}
|
||||
|
||||
mm_params := AuthServiceMockLogoutParams{ctx, refreshToken}
|
||||
mm_params := AuthServiceMockLogoutParams{ctx, accessToken}
|
||||
|
||||
// Record call args
|
||||
mmLogout.LogoutMock.mutex.Lock()
|
||||
@@ -751,7 +751,7 @@ func (mmLogout *AuthServiceMock) Logout(ctx context.Context, refreshToken string
|
||||
mm_want := mmLogout.LogoutMock.defaultExpectation.params
|
||||
mm_want_ptrs := mmLogout.LogoutMock.defaultExpectation.paramPtrs
|
||||
|
||||
mm_got := AuthServiceMockLogoutParams{ctx, refreshToken}
|
||||
mm_got := AuthServiceMockLogoutParams{ctx, accessToken}
|
||||
|
||||
if mm_want_ptrs != nil {
|
||||
|
||||
@@ -760,9 +760,9 @@ func (mmLogout *AuthServiceMock) Logout(ctx context.Context, refreshToken string
|
||||
mmLogout.LogoutMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
|
||||
}
|
||||
|
||||
if mm_want_ptrs.refreshToken != nil && !minimock.Equal(*mm_want_ptrs.refreshToken, mm_got.refreshToken) {
|
||||
mmLogout.t.Errorf("AuthServiceMock.Logout got unexpected parameter refreshToken, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmLogout.LogoutMock.defaultExpectation.expectationOrigins.originRefreshToken, *mm_want_ptrs.refreshToken, mm_got.refreshToken, minimock.Diff(*mm_want_ptrs.refreshToken, mm_got.refreshToken))
|
||||
if mm_want_ptrs.accessToken != nil && !minimock.Equal(*mm_want_ptrs.accessToken, mm_got.accessToken) {
|
||||
mmLogout.t.Errorf("AuthServiceMock.Logout got unexpected parameter accessToken, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmLogout.LogoutMock.defaultExpectation.expectationOrigins.originAccessToken, *mm_want_ptrs.accessToken, mm_got.accessToken, minimock.Diff(*mm_want_ptrs.accessToken, mm_got.accessToken))
|
||||
}
|
||||
|
||||
} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
|
||||
@@ -777,9 +777,9 @@ func (mmLogout *AuthServiceMock) Logout(ctx context.Context, refreshToken string
|
||||
return (*mm_results).err
|
||||
}
|
||||
if mmLogout.funcLogout != nil {
|
||||
return mmLogout.funcLogout(ctx, refreshToken)
|
||||
return mmLogout.funcLogout(ctx, accessToken)
|
||||
}
|
||||
mmLogout.t.Fatalf("Unexpected call to AuthServiceMock.Logout. %v %v", ctx, refreshToken)
|
||||
mmLogout.t.Fatalf("Unexpected call to AuthServiceMock.Logout. %v %v", ctx, accessToken)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -2,16 +2,17 @@
|
||||
|
||||
package mocks
|
||||
|
||||
//go:generate minimock -i smart-search-back/internal/repository.InviteRepository -o invite_repository_mock.go -n InviteRepositoryMock -p mocks
|
||||
//go:generate minimock -i git.techease.ru/Smart-search/smart-search-back/internal/repository.InviteRepository -o invite_repository_mock.go -n InviteRepositoryMock -p mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"smart-search-back/internal/model"
|
||||
"sync"
|
||||
mm_atomic "sync/atomic"
|
||||
mm_time "time"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
"github.com/gojuno/minimock/v3"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
// InviteRepositoryMock implements mm_repository.InviteRepository
|
||||
@@ -26,6 +27,13 @@ type InviteRepositoryMock struct {
|
||||
beforeCreateCounter uint64
|
||||
CreateMock mInviteRepositoryMockCreate
|
||||
|
||||
funcCreateTx func(ctx context.Context, tx pgx.Tx, invite *model.InviteCode) (err error)
|
||||
funcCreateTxOrigin string
|
||||
inspectFuncCreateTx func(ctx context.Context, tx pgx.Tx, invite *model.InviteCode)
|
||||
afterCreateTxCounter uint64
|
||||
beforeCreateTxCounter uint64
|
||||
CreateTxMock mInviteRepositoryMockCreateTx
|
||||
|
||||
funcDeactivateExpired func(ctx context.Context) (i1 int, err error)
|
||||
funcDeactivateExpiredOrigin string
|
||||
inspectFuncDeactivateExpired func(ctx context.Context)
|
||||
@@ -66,6 +74,9 @@ func NewInviteRepositoryMock(t minimock.Tester) *InviteRepositoryMock {
|
||||
m.CreateMock = mInviteRepositoryMockCreate{mock: m}
|
||||
m.CreateMock.callArgs = []*InviteRepositoryMockCreateParams{}
|
||||
|
||||
m.CreateTxMock = mInviteRepositoryMockCreateTx{mock: m}
|
||||
m.CreateTxMock.callArgs = []*InviteRepositoryMockCreateTxParams{}
|
||||
|
||||
m.DeactivateExpiredMock = mInviteRepositoryMockDeactivateExpired{mock: m}
|
||||
m.DeactivateExpiredMock.callArgs = []*InviteRepositoryMockDeactivateExpiredParams{}
|
||||
|
||||
@@ -425,6 +436,379 @@ func (m *InviteRepositoryMock) MinimockCreateInspect() {
|
||||
}
|
||||
}
|
||||
|
||||
type mInviteRepositoryMockCreateTx struct {
|
||||
optional bool
|
||||
mock *InviteRepositoryMock
|
||||
defaultExpectation *InviteRepositoryMockCreateTxExpectation
|
||||
expectations []*InviteRepositoryMockCreateTxExpectation
|
||||
|
||||
callArgs []*InviteRepositoryMockCreateTxParams
|
||||
mutex sync.RWMutex
|
||||
|
||||
expectedInvocations uint64
|
||||
expectedInvocationsOrigin string
|
||||
}
|
||||
|
||||
// InviteRepositoryMockCreateTxExpectation specifies expectation struct of the InviteRepository.CreateTx
|
||||
type InviteRepositoryMockCreateTxExpectation struct {
|
||||
mock *InviteRepositoryMock
|
||||
params *InviteRepositoryMockCreateTxParams
|
||||
paramPtrs *InviteRepositoryMockCreateTxParamPtrs
|
||||
expectationOrigins InviteRepositoryMockCreateTxExpectationOrigins
|
||||
results *InviteRepositoryMockCreateTxResults
|
||||
returnOrigin string
|
||||
Counter uint64
|
||||
}
|
||||
|
||||
// InviteRepositoryMockCreateTxParams contains parameters of the InviteRepository.CreateTx
|
||||
type InviteRepositoryMockCreateTxParams struct {
|
||||
ctx context.Context
|
||||
tx pgx.Tx
|
||||
invite *model.InviteCode
|
||||
}
|
||||
|
||||
// InviteRepositoryMockCreateTxParamPtrs contains pointers to parameters of the InviteRepository.CreateTx
|
||||
type InviteRepositoryMockCreateTxParamPtrs struct {
|
||||
ctx *context.Context
|
||||
tx *pgx.Tx
|
||||
invite **model.InviteCode
|
||||
}
|
||||
|
||||
// InviteRepositoryMockCreateTxResults contains results of the InviteRepository.CreateTx
|
||||
type InviteRepositoryMockCreateTxResults struct {
|
||||
err error
|
||||
}
|
||||
|
||||
// InviteRepositoryMockCreateTxOrigins contains origins of expectations of the InviteRepository.CreateTx
|
||||
type InviteRepositoryMockCreateTxExpectationOrigins struct {
|
||||
origin string
|
||||
originCtx string
|
||||
originTx string
|
||||
originInvite string
|
||||
}
|
||||
|
||||
// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning
|
||||
// the test will fail minimock's automatic final call check if the mocked method was not called at least once.
|
||||
// Optional() makes method check to work in '0 or more' mode.
|
||||
// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to
|
||||
// catch the problems when the expected method call is totally skipped during test run.
|
||||
func (mmCreateTx *mInviteRepositoryMockCreateTx) Optional() *mInviteRepositoryMockCreateTx {
|
||||
mmCreateTx.optional = true
|
||||
return mmCreateTx
|
||||
}
|
||||
|
||||
// Expect sets up expected params for InviteRepository.CreateTx
|
||||
func (mmCreateTx *mInviteRepositoryMockCreateTx) Expect(ctx context.Context, tx pgx.Tx, invite *model.InviteCode) *mInviteRepositoryMockCreateTx {
|
||||
if mmCreateTx.mock.funcCreateTx != nil {
|
||||
mmCreateTx.mock.t.Fatalf("InviteRepositoryMock.CreateTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation == nil {
|
||||
mmCreateTx.defaultExpectation = &InviteRepositoryMockCreateTxExpectation{}
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation.paramPtrs != nil {
|
||||
mmCreateTx.mock.t.Fatalf("InviteRepositoryMock.CreateTx mock is already set by ExpectParams functions")
|
||||
}
|
||||
|
||||
mmCreateTx.defaultExpectation.params = &InviteRepositoryMockCreateTxParams{ctx, tx, invite}
|
||||
mmCreateTx.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1)
|
||||
for _, e := range mmCreateTx.expectations {
|
||||
if minimock.Equal(e.params, mmCreateTx.defaultExpectation.params) {
|
||||
mmCreateTx.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmCreateTx.defaultExpectation.params)
|
||||
}
|
||||
}
|
||||
|
||||
return mmCreateTx
|
||||
}
|
||||
|
||||
// ExpectCtxParam1 sets up expected param ctx for InviteRepository.CreateTx
|
||||
func (mmCreateTx *mInviteRepositoryMockCreateTx) ExpectCtxParam1(ctx context.Context) *mInviteRepositoryMockCreateTx {
|
||||
if mmCreateTx.mock.funcCreateTx != nil {
|
||||
mmCreateTx.mock.t.Fatalf("InviteRepositoryMock.CreateTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation == nil {
|
||||
mmCreateTx.defaultExpectation = &InviteRepositoryMockCreateTxExpectation{}
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation.params != nil {
|
||||
mmCreateTx.mock.t.Fatalf("InviteRepositoryMock.CreateTx mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation.paramPtrs == nil {
|
||||
mmCreateTx.defaultExpectation.paramPtrs = &InviteRepositoryMockCreateTxParamPtrs{}
|
||||
}
|
||||
mmCreateTx.defaultExpectation.paramPtrs.ctx = &ctx
|
||||
mmCreateTx.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1)
|
||||
|
||||
return mmCreateTx
|
||||
}
|
||||
|
||||
// ExpectTxParam2 sets up expected param tx for InviteRepository.CreateTx
|
||||
func (mmCreateTx *mInviteRepositoryMockCreateTx) ExpectTxParam2(tx pgx.Tx) *mInviteRepositoryMockCreateTx {
|
||||
if mmCreateTx.mock.funcCreateTx != nil {
|
||||
mmCreateTx.mock.t.Fatalf("InviteRepositoryMock.CreateTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation == nil {
|
||||
mmCreateTx.defaultExpectation = &InviteRepositoryMockCreateTxExpectation{}
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation.params != nil {
|
||||
mmCreateTx.mock.t.Fatalf("InviteRepositoryMock.CreateTx mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation.paramPtrs == nil {
|
||||
mmCreateTx.defaultExpectation.paramPtrs = &InviteRepositoryMockCreateTxParamPtrs{}
|
||||
}
|
||||
mmCreateTx.defaultExpectation.paramPtrs.tx = &tx
|
||||
mmCreateTx.defaultExpectation.expectationOrigins.originTx = minimock.CallerInfo(1)
|
||||
|
||||
return mmCreateTx
|
||||
}
|
||||
|
||||
// ExpectInviteParam3 sets up expected param invite for InviteRepository.CreateTx
|
||||
func (mmCreateTx *mInviteRepositoryMockCreateTx) ExpectInviteParam3(invite *model.InviteCode) *mInviteRepositoryMockCreateTx {
|
||||
if mmCreateTx.mock.funcCreateTx != nil {
|
||||
mmCreateTx.mock.t.Fatalf("InviteRepositoryMock.CreateTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation == nil {
|
||||
mmCreateTx.defaultExpectation = &InviteRepositoryMockCreateTxExpectation{}
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation.params != nil {
|
||||
mmCreateTx.mock.t.Fatalf("InviteRepositoryMock.CreateTx mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation.paramPtrs == nil {
|
||||
mmCreateTx.defaultExpectation.paramPtrs = &InviteRepositoryMockCreateTxParamPtrs{}
|
||||
}
|
||||
mmCreateTx.defaultExpectation.paramPtrs.invite = &invite
|
||||
mmCreateTx.defaultExpectation.expectationOrigins.originInvite = minimock.CallerInfo(1)
|
||||
|
||||
return mmCreateTx
|
||||
}
|
||||
|
||||
// Inspect accepts an inspector function that has same arguments as the InviteRepository.CreateTx
|
||||
func (mmCreateTx *mInviteRepositoryMockCreateTx) Inspect(f func(ctx context.Context, tx pgx.Tx, invite *model.InviteCode)) *mInviteRepositoryMockCreateTx {
|
||||
if mmCreateTx.mock.inspectFuncCreateTx != nil {
|
||||
mmCreateTx.mock.t.Fatalf("Inspect function is already set for InviteRepositoryMock.CreateTx")
|
||||
}
|
||||
|
||||
mmCreateTx.mock.inspectFuncCreateTx = f
|
||||
|
||||
return mmCreateTx
|
||||
}
|
||||
|
||||
// Return sets up results that will be returned by InviteRepository.CreateTx
|
||||
func (mmCreateTx *mInviteRepositoryMockCreateTx) Return(err error) *InviteRepositoryMock {
|
||||
if mmCreateTx.mock.funcCreateTx != nil {
|
||||
mmCreateTx.mock.t.Fatalf("InviteRepositoryMock.CreateTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation == nil {
|
||||
mmCreateTx.defaultExpectation = &InviteRepositoryMockCreateTxExpectation{mock: mmCreateTx.mock}
|
||||
}
|
||||
mmCreateTx.defaultExpectation.results = &InviteRepositoryMockCreateTxResults{err}
|
||||
mmCreateTx.defaultExpectation.returnOrigin = minimock.CallerInfo(1)
|
||||
return mmCreateTx.mock
|
||||
}
|
||||
|
||||
// Set uses given function f to mock the InviteRepository.CreateTx method
|
||||
func (mmCreateTx *mInviteRepositoryMockCreateTx) Set(f func(ctx context.Context, tx pgx.Tx, invite *model.InviteCode) (err error)) *InviteRepositoryMock {
|
||||
if mmCreateTx.defaultExpectation != nil {
|
||||
mmCreateTx.mock.t.Fatalf("Default expectation is already set for the InviteRepository.CreateTx method")
|
||||
}
|
||||
|
||||
if len(mmCreateTx.expectations) > 0 {
|
||||
mmCreateTx.mock.t.Fatalf("Some expectations are already set for the InviteRepository.CreateTx method")
|
||||
}
|
||||
|
||||
mmCreateTx.mock.funcCreateTx = f
|
||||
mmCreateTx.mock.funcCreateTxOrigin = minimock.CallerInfo(1)
|
||||
return mmCreateTx.mock
|
||||
}
|
||||
|
||||
// When sets expectation for the InviteRepository.CreateTx which will trigger the result defined by the following
|
||||
// Then helper
|
||||
func (mmCreateTx *mInviteRepositoryMockCreateTx) When(ctx context.Context, tx pgx.Tx, invite *model.InviteCode) *InviteRepositoryMockCreateTxExpectation {
|
||||
if mmCreateTx.mock.funcCreateTx != nil {
|
||||
mmCreateTx.mock.t.Fatalf("InviteRepositoryMock.CreateTx mock is already set by Set")
|
||||
}
|
||||
|
||||
expectation := &InviteRepositoryMockCreateTxExpectation{
|
||||
mock: mmCreateTx.mock,
|
||||
params: &InviteRepositoryMockCreateTxParams{ctx, tx, invite},
|
||||
expectationOrigins: InviteRepositoryMockCreateTxExpectationOrigins{origin: minimock.CallerInfo(1)},
|
||||
}
|
||||
mmCreateTx.expectations = append(mmCreateTx.expectations, expectation)
|
||||
return expectation
|
||||
}
|
||||
|
||||
// Then sets up InviteRepository.CreateTx return parameters for the expectation previously defined by the When method
|
||||
func (e *InviteRepositoryMockCreateTxExpectation) Then(err error) *InviteRepositoryMock {
|
||||
e.results = &InviteRepositoryMockCreateTxResults{err}
|
||||
return e.mock
|
||||
}
|
||||
|
||||
// Times sets number of times InviteRepository.CreateTx should be invoked
|
||||
func (mmCreateTx *mInviteRepositoryMockCreateTx) Times(n uint64) *mInviteRepositoryMockCreateTx {
|
||||
if n == 0 {
|
||||
mmCreateTx.mock.t.Fatalf("Times of InviteRepositoryMock.CreateTx mock can not be zero")
|
||||
}
|
||||
mm_atomic.StoreUint64(&mmCreateTx.expectedInvocations, n)
|
||||
mmCreateTx.expectedInvocationsOrigin = minimock.CallerInfo(1)
|
||||
return mmCreateTx
|
||||
}
|
||||
|
||||
func (mmCreateTx *mInviteRepositoryMockCreateTx) invocationsDone() bool {
|
||||
if len(mmCreateTx.expectations) == 0 && mmCreateTx.defaultExpectation == nil && mmCreateTx.mock.funcCreateTx == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
totalInvocations := mm_atomic.LoadUint64(&mmCreateTx.mock.afterCreateTxCounter)
|
||||
expectedInvocations := mm_atomic.LoadUint64(&mmCreateTx.expectedInvocations)
|
||||
|
||||
return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
|
||||
}
|
||||
|
||||
// CreateTx implements mm_repository.InviteRepository
|
||||
func (mmCreateTx *InviteRepositoryMock) CreateTx(ctx context.Context, tx pgx.Tx, invite *model.InviteCode) (err error) {
|
||||
mm_atomic.AddUint64(&mmCreateTx.beforeCreateTxCounter, 1)
|
||||
defer mm_atomic.AddUint64(&mmCreateTx.afterCreateTxCounter, 1)
|
||||
|
||||
mmCreateTx.t.Helper()
|
||||
|
||||
if mmCreateTx.inspectFuncCreateTx != nil {
|
||||
mmCreateTx.inspectFuncCreateTx(ctx, tx, invite)
|
||||
}
|
||||
|
||||
mm_params := InviteRepositoryMockCreateTxParams{ctx, tx, invite}
|
||||
|
||||
// Record call args
|
||||
mmCreateTx.CreateTxMock.mutex.Lock()
|
||||
mmCreateTx.CreateTxMock.callArgs = append(mmCreateTx.CreateTxMock.callArgs, &mm_params)
|
||||
mmCreateTx.CreateTxMock.mutex.Unlock()
|
||||
|
||||
for _, e := range mmCreateTx.CreateTxMock.expectations {
|
||||
if minimock.Equal(*e.params, mm_params) {
|
||||
mm_atomic.AddUint64(&e.Counter, 1)
|
||||
return e.results.err
|
||||
}
|
||||
}
|
||||
|
||||
if mmCreateTx.CreateTxMock.defaultExpectation != nil {
|
||||
mm_atomic.AddUint64(&mmCreateTx.CreateTxMock.defaultExpectation.Counter, 1)
|
||||
mm_want := mmCreateTx.CreateTxMock.defaultExpectation.params
|
||||
mm_want_ptrs := mmCreateTx.CreateTxMock.defaultExpectation.paramPtrs
|
||||
|
||||
mm_got := InviteRepositoryMockCreateTxParams{ctx, tx, invite}
|
||||
|
||||
if mm_want_ptrs != nil {
|
||||
|
||||
if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) {
|
||||
mmCreateTx.t.Errorf("InviteRepositoryMock.CreateTx got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmCreateTx.CreateTxMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
|
||||
}
|
||||
|
||||
if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
|
||||
mmCreateTx.t.Errorf("InviteRepositoryMock.CreateTx got unexpected parameter tx, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmCreateTx.CreateTxMock.defaultExpectation.expectationOrigins.originTx, *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
|
||||
}
|
||||
|
||||
if mm_want_ptrs.invite != nil && !minimock.Equal(*mm_want_ptrs.invite, mm_got.invite) {
|
||||
mmCreateTx.t.Errorf("InviteRepositoryMock.CreateTx got unexpected parameter invite, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmCreateTx.CreateTxMock.defaultExpectation.expectationOrigins.originInvite, *mm_want_ptrs.invite, mm_got.invite, minimock.Diff(*mm_want_ptrs.invite, mm_got.invite))
|
||||
}
|
||||
|
||||
} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
|
||||
mmCreateTx.t.Errorf("InviteRepositoryMock.CreateTx got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmCreateTx.CreateTxMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
|
||||
}
|
||||
|
||||
mm_results := mmCreateTx.CreateTxMock.defaultExpectation.results
|
||||
if mm_results == nil {
|
||||
mmCreateTx.t.Fatal("No results are set for the InviteRepositoryMock.CreateTx")
|
||||
}
|
||||
return (*mm_results).err
|
||||
}
|
||||
if mmCreateTx.funcCreateTx != nil {
|
||||
return mmCreateTx.funcCreateTx(ctx, tx, invite)
|
||||
}
|
||||
mmCreateTx.t.Fatalf("Unexpected call to InviteRepositoryMock.CreateTx. %v %v %v", ctx, tx, invite)
|
||||
return
|
||||
}
|
||||
|
||||
// CreateTxAfterCounter returns a count of finished InviteRepositoryMock.CreateTx invocations
|
||||
func (mmCreateTx *InviteRepositoryMock) CreateTxAfterCounter() uint64 {
|
||||
return mm_atomic.LoadUint64(&mmCreateTx.afterCreateTxCounter)
|
||||
}
|
||||
|
||||
// CreateTxBeforeCounter returns a count of InviteRepositoryMock.CreateTx invocations
|
||||
func (mmCreateTx *InviteRepositoryMock) CreateTxBeforeCounter() uint64 {
|
||||
return mm_atomic.LoadUint64(&mmCreateTx.beforeCreateTxCounter)
|
||||
}
|
||||
|
||||
// Calls returns a list of arguments used in each call to InviteRepositoryMock.CreateTx.
|
||||
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
|
||||
func (mmCreateTx *mInviteRepositoryMockCreateTx) Calls() []*InviteRepositoryMockCreateTxParams {
|
||||
mmCreateTx.mutex.RLock()
|
||||
|
||||
argCopy := make([]*InviteRepositoryMockCreateTxParams, len(mmCreateTx.callArgs))
|
||||
copy(argCopy, mmCreateTx.callArgs)
|
||||
|
||||
mmCreateTx.mutex.RUnlock()
|
||||
|
||||
return argCopy
|
||||
}
|
||||
|
||||
// MinimockCreateTxDone returns true if the count of the CreateTx invocations corresponds
|
||||
// the number of defined expectations
|
||||
func (m *InviteRepositoryMock) MinimockCreateTxDone() bool {
|
||||
if m.CreateTxMock.optional {
|
||||
// Optional methods provide '0 or more' call count restriction.
|
||||
return true
|
||||
}
|
||||
|
||||
for _, e := range m.CreateTxMock.expectations {
|
||||
if mm_atomic.LoadUint64(&e.Counter) < 1 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return m.CreateTxMock.invocationsDone()
|
||||
}
|
||||
|
||||
// MinimockCreateTxInspect logs each unmet expectation
|
||||
func (m *InviteRepositoryMock) MinimockCreateTxInspect() {
|
||||
for _, e := range m.CreateTxMock.expectations {
|
||||
if mm_atomic.LoadUint64(&e.Counter) < 1 {
|
||||
m.t.Errorf("Expected call to InviteRepositoryMock.CreateTx at\n%s with params: %#v", e.expectationOrigins.origin, *e.params)
|
||||
}
|
||||
}
|
||||
|
||||
afterCreateTxCounter := mm_atomic.LoadUint64(&m.afterCreateTxCounter)
|
||||
// if default expectation was set then invocations count should be greater than zero
|
||||
if m.CreateTxMock.defaultExpectation != nil && afterCreateTxCounter < 1 {
|
||||
if m.CreateTxMock.defaultExpectation.params == nil {
|
||||
m.t.Errorf("Expected call to InviteRepositoryMock.CreateTx at\n%s", m.CreateTxMock.defaultExpectation.returnOrigin)
|
||||
} else {
|
||||
m.t.Errorf("Expected call to InviteRepositoryMock.CreateTx at\n%s with params: %#v", m.CreateTxMock.defaultExpectation.expectationOrigins.origin, *m.CreateTxMock.defaultExpectation.params)
|
||||
}
|
||||
}
|
||||
// if func was set then invocations count should be greater than zero
|
||||
if m.funcCreateTx != nil && afterCreateTxCounter < 1 {
|
||||
m.t.Errorf("Expected call to InviteRepositoryMock.CreateTx at\n%s", m.funcCreateTxOrigin)
|
||||
}
|
||||
|
||||
if !m.CreateTxMock.invocationsDone() && afterCreateTxCounter > 0 {
|
||||
m.t.Errorf("Expected %d calls to InviteRepositoryMock.CreateTx at\n%s but found %d calls",
|
||||
mm_atomic.LoadUint64(&m.CreateTxMock.expectedInvocations), m.CreateTxMock.expectedInvocationsOrigin, afterCreateTxCounter)
|
||||
}
|
||||
}
|
||||
|
||||
type mInviteRepositoryMockDeactivateExpired struct {
|
||||
optional bool
|
||||
mock *InviteRepositoryMock
|
||||
@@ -1771,6 +2155,8 @@ func (m *InviteRepositoryMock) MinimockFinish() {
|
||||
if !m.minimockDone() {
|
||||
m.MinimockCreateInspect()
|
||||
|
||||
m.MinimockCreateTxInspect()
|
||||
|
||||
m.MinimockDeactivateExpiredInspect()
|
||||
|
||||
m.MinimockFindByCodeInspect()
|
||||
@@ -1802,6 +2188,7 @@ func (m *InviteRepositoryMock) minimockDone() bool {
|
||||
done := true
|
||||
return done &&
|
||||
m.MinimockCreateDone() &&
|
||||
m.MinimockCreateTxDone() &&
|
||||
m.MinimockDeactivateExpiredDone() &&
|
||||
m.MinimockFindByCodeDone() &&
|
||||
m.MinimockGetUserInvitesDone() &&
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
|
||||
package mocks
|
||||
|
||||
//go:generate minimock -i smart-search-back/internal/service.InviteService -o invite_service_mock.go -n InviteServiceMock -p mocks
|
||||
//go:generate minimock -i git.techease.ru/Smart-search/smart-search-back/internal/service.InviteService -o invite_service_mock.go -n InviteServiceMock -p mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"smart-search-back/internal/model"
|
||||
"sync"
|
||||
mm_atomic "sync/atomic"
|
||||
mm_time "time"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
"github.com/gojuno/minimock/v3"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,17 +2,18 @@
|
||||
|
||||
package mocks
|
||||
|
||||
//go:generate minimock -i smart-search-back/internal/repository.RequestRepository -o request_repository_mock.go -n RequestRepositoryMock -p mocks
|
||||
//go:generate minimock -i git.techease.ru/Smart-search/smart-search-back/internal/repository.RequestRepository -o request_repository_mock.go -n RequestRepositoryMock -p mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"smart-search-back/internal/model"
|
||||
"sync"
|
||||
mm_atomic "sync/atomic"
|
||||
mm_time "time"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
"github.com/gojuno/minimock/v3"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
// RequestRepositoryMock implements mm_repository.RequestRepository
|
||||
@@ -68,6 +69,13 @@ type RequestRepositoryMock struct {
|
||||
afterUpdateWithTZCounter uint64
|
||||
beforeUpdateWithTZCounter uint64
|
||||
UpdateWithTZMock mRequestRepositoryMockUpdateWithTZ
|
||||
|
||||
funcUpdateWithTZTx func(ctx context.Context, tx pgx.Tx, id uuid.UUID, tz string, generated bool) (err error)
|
||||
funcUpdateWithTZTxOrigin string
|
||||
inspectFuncUpdateWithTZTx func(ctx context.Context, tx pgx.Tx, id uuid.UUID, tz string, generated bool)
|
||||
afterUpdateWithTZTxCounter uint64
|
||||
beforeUpdateWithTZTxCounter uint64
|
||||
UpdateWithTZTxMock mRequestRepositoryMockUpdateWithTZTx
|
||||
}
|
||||
|
||||
// NewRequestRepositoryMock returns a mock for mm_repository.RequestRepository
|
||||
@@ -99,6 +107,9 @@ func NewRequestRepositoryMock(t minimock.Tester) *RequestRepositoryMock {
|
||||
m.UpdateWithTZMock = mRequestRepositoryMockUpdateWithTZ{mock: m}
|
||||
m.UpdateWithTZMock.callArgs = []*RequestRepositoryMockUpdateWithTZParams{}
|
||||
|
||||
m.UpdateWithTZTxMock = mRequestRepositoryMockUpdateWithTZTx{mock: m}
|
||||
m.UpdateWithTZTxMock.callArgs = []*RequestRepositoryMockUpdateWithTZTxParams{}
|
||||
|
||||
t.Cleanup(m.MinimockFinish)
|
||||
|
||||
return m
|
||||
@@ -2597,6 +2608,441 @@ func (m *RequestRepositoryMock) MinimockUpdateWithTZInspect() {
|
||||
}
|
||||
}
|
||||
|
||||
type mRequestRepositoryMockUpdateWithTZTx struct {
|
||||
optional bool
|
||||
mock *RequestRepositoryMock
|
||||
defaultExpectation *RequestRepositoryMockUpdateWithTZTxExpectation
|
||||
expectations []*RequestRepositoryMockUpdateWithTZTxExpectation
|
||||
|
||||
callArgs []*RequestRepositoryMockUpdateWithTZTxParams
|
||||
mutex sync.RWMutex
|
||||
|
||||
expectedInvocations uint64
|
||||
expectedInvocationsOrigin string
|
||||
}
|
||||
|
||||
// RequestRepositoryMockUpdateWithTZTxExpectation specifies expectation struct of the RequestRepository.UpdateWithTZTx
|
||||
type RequestRepositoryMockUpdateWithTZTxExpectation struct {
|
||||
mock *RequestRepositoryMock
|
||||
params *RequestRepositoryMockUpdateWithTZTxParams
|
||||
paramPtrs *RequestRepositoryMockUpdateWithTZTxParamPtrs
|
||||
expectationOrigins RequestRepositoryMockUpdateWithTZTxExpectationOrigins
|
||||
results *RequestRepositoryMockUpdateWithTZTxResults
|
||||
returnOrigin string
|
||||
Counter uint64
|
||||
}
|
||||
|
||||
// RequestRepositoryMockUpdateWithTZTxParams contains parameters of the RequestRepository.UpdateWithTZTx
|
||||
type RequestRepositoryMockUpdateWithTZTxParams struct {
|
||||
ctx context.Context
|
||||
tx pgx.Tx
|
||||
id uuid.UUID
|
||||
tz string
|
||||
generated bool
|
||||
}
|
||||
|
||||
// RequestRepositoryMockUpdateWithTZTxParamPtrs contains pointers to parameters of the RequestRepository.UpdateWithTZTx
|
||||
type RequestRepositoryMockUpdateWithTZTxParamPtrs struct {
|
||||
ctx *context.Context
|
||||
tx *pgx.Tx
|
||||
id *uuid.UUID
|
||||
tz *string
|
||||
generated *bool
|
||||
}
|
||||
|
||||
// RequestRepositoryMockUpdateWithTZTxResults contains results of the RequestRepository.UpdateWithTZTx
|
||||
type RequestRepositoryMockUpdateWithTZTxResults struct {
|
||||
err error
|
||||
}
|
||||
|
||||
// RequestRepositoryMockUpdateWithTZTxOrigins contains origins of expectations of the RequestRepository.UpdateWithTZTx
|
||||
type RequestRepositoryMockUpdateWithTZTxExpectationOrigins struct {
|
||||
origin string
|
||||
originCtx string
|
||||
originTx string
|
||||
originId string
|
||||
originTz string
|
||||
originGenerated string
|
||||
}
|
||||
|
||||
// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning
|
||||
// the test will fail minimock's automatic final call check if the mocked method was not called at least once.
|
||||
// Optional() makes method check to work in '0 or more' mode.
|
||||
// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to
|
||||
// catch the problems when the expected method call is totally skipped during test run.
|
||||
func (mmUpdateWithTZTx *mRequestRepositoryMockUpdateWithTZTx) Optional() *mRequestRepositoryMockUpdateWithTZTx {
|
||||
mmUpdateWithTZTx.optional = true
|
||||
return mmUpdateWithTZTx
|
||||
}
|
||||
|
||||
// Expect sets up expected params for RequestRepository.UpdateWithTZTx
|
||||
func (mmUpdateWithTZTx *mRequestRepositoryMockUpdateWithTZTx) Expect(ctx context.Context, tx pgx.Tx, id uuid.UUID, tz string, generated bool) *mRequestRepositoryMockUpdateWithTZTx {
|
||||
if mmUpdateWithTZTx.mock.funcUpdateWithTZTx != nil {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("RequestRepositoryMock.UpdateWithTZTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation == nil {
|
||||
mmUpdateWithTZTx.defaultExpectation = &RequestRepositoryMockUpdateWithTZTxExpectation{}
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation.paramPtrs != nil {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("RequestRepositoryMock.UpdateWithTZTx mock is already set by ExpectParams functions")
|
||||
}
|
||||
|
||||
mmUpdateWithTZTx.defaultExpectation.params = &RequestRepositoryMockUpdateWithTZTxParams{ctx, tx, id, tz, generated}
|
||||
mmUpdateWithTZTx.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1)
|
||||
for _, e := range mmUpdateWithTZTx.expectations {
|
||||
if minimock.Equal(e.params, mmUpdateWithTZTx.defaultExpectation.params) {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmUpdateWithTZTx.defaultExpectation.params)
|
||||
}
|
||||
}
|
||||
|
||||
return mmUpdateWithTZTx
|
||||
}
|
||||
|
||||
// ExpectCtxParam1 sets up expected param ctx for RequestRepository.UpdateWithTZTx
|
||||
func (mmUpdateWithTZTx *mRequestRepositoryMockUpdateWithTZTx) ExpectCtxParam1(ctx context.Context) *mRequestRepositoryMockUpdateWithTZTx {
|
||||
if mmUpdateWithTZTx.mock.funcUpdateWithTZTx != nil {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("RequestRepositoryMock.UpdateWithTZTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation == nil {
|
||||
mmUpdateWithTZTx.defaultExpectation = &RequestRepositoryMockUpdateWithTZTxExpectation{}
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation.params != nil {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("RequestRepositoryMock.UpdateWithTZTx mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation.paramPtrs == nil {
|
||||
mmUpdateWithTZTx.defaultExpectation.paramPtrs = &RequestRepositoryMockUpdateWithTZTxParamPtrs{}
|
||||
}
|
||||
mmUpdateWithTZTx.defaultExpectation.paramPtrs.ctx = &ctx
|
||||
mmUpdateWithTZTx.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1)
|
||||
|
||||
return mmUpdateWithTZTx
|
||||
}
|
||||
|
||||
// ExpectTxParam2 sets up expected param tx for RequestRepository.UpdateWithTZTx
|
||||
func (mmUpdateWithTZTx *mRequestRepositoryMockUpdateWithTZTx) ExpectTxParam2(tx pgx.Tx) *mRequestRepositoryMockUpdateWithTZTx {
|
||||
if mmUpdateWithTZTx.mock.funcUpdateWithTZTx != nil {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("RequestRepositoryMock.UpdateWithTZTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation == nil {
|
||||
mmUpdateWithTZTx.defaultExpectation = &RequestRepositoryMockUpdateWithTZTxExpectation{}
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation.params != nil {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("RequestRepositoryMock.UpdateWithTZTx mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation.paramPtrs == nil {
|
||||
mmUpdateWithTZTx.defaultExpectation.paramPtrs = &RequestRepositoryMockUpdateWithTZTxParamPtrs{}
|
||||
}
|
||||
mmUpdateWithTZTx.defaultExpectation.paramPtrs.tx = &tx
|
||||
mmUpdateWithTZTx.defaultExpectation.expectationOrigins.originTx = minimock.CallerInfo(1)
|
||||
|
||||
return mmUpdateWithTZTx
|
||||
}
|
||||
|
||||
// ExpectIdParam3 sets up expected param id for RequestRepository.UpdateWithTZTx
|
||||
func (mmUpdateWithTZTx *mRequestRepositoryMockUpdateWithTZTx) ExpectIdParam3(id uuid.UUID) *mRequestRepositoryMockUpdateWithTZTx {
|
||||
if mmUpdateWithTZTx.mock.funcUpdateWithTZTx != nil {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("RequestRepositoryMock.UpdateWithTZTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation == nil {
|
||||
mmUpdateWithTZTx.defaultExpectation = &RequestRepositoryMockUpdateWithTZTxExpectation{}
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation.params != nil {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("RequestRepositoryMock.UpdateWithTZTx mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation.paramPtrs == nil {
|
||||
mmUpdateWithTZTx.defaultExpectation.paramPtrs = &RequestRepositoryMockUpdateWithTZTxParamPtrs{}
|
||||
}
|
||||
mmUpdateWithTZTx.defaultExpectation.paramPtrs.id = &id
|
||||
mmUpdateWithTZTx.defaultExpectation.expectationOrigins.originId = minimock.CallerInfo(1)
|
||||
|
||||
return mmUpdateWithTZTx
|
||||
}
|
||||
|
||||
// ExpectTzParam4 sets up expected param tz for RequestRepository.UpdateWithTZTx
|
||||
func (mmUpdateWithTZTx *mRequestRepositoryMockUpdateWithTZTx) ExpectTzParam4(tz string) *mRequestRepositoryMockUpdateWithTZTx {
|
||||
if mmUpdateWithTZTx.mock.funcUpdateWithTZTx != nil {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("RequestRepositoryMock.UpdateWithTZTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation == nil {
|
||||
mmUpdateWithTZTx.defaultExpectation = &RequestRepositoryMockUpdateWithTZTxExpectation{}
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation.params != nil {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("RequestRepositoryMock.UpdateWithTZTx mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation.paramPtrs == nil {
|
||||
mmUpdateWithTZTx.defaultExpectation.paramPtrs = &RequestRepositoryMockUpdateWithTZTxParamPtrs{}
|
||||
}
|
||||
mmUpdateWithTZTx.defaultExpectation.paramPtrs.tz = &tz
|
||||
mmUpdateWithTZTx.defaultExpectation.expectationOrigins.originTz = minimock.CallerInfo(1)
|
||||
|
||||
return mmUpdateWithTZTx
|
||||
}
|
||||
|
||||
// ExpectGeneratedParam5 sets up expected param generated for RequestRepository.UpdateWithTZTx
|
||||
func (mmUpdateWithTZTx *mRequestRepositoryMockUpdateWithTZTx) ExpectGeneratedParam5(generated bool) *mRequestRepositoryMockUpdateWithTZTx {
|
||||
if mmUpdateWithTZTx.mock.funcUpdateWithTZTx != nil {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("RequestRepositoryMock.UpdateWithTZTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation == nil {
|
||||
mmUpdateWithTZTx.defaultExpectation = &RequestRepositoryMockUpdateWithTZTxExpectation{}
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation.params != nil {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("RequestRepositoryMock.UpdateWithTZTx mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation.paramPtrs == nil {
|
||||
mmUpdateWithTZTx.defaultExpectation.paramPtrs = &RequestRepositoryMockUpdateWithTZTxParamPtrs{}
|
||||
}
|
||||
mmUpdateWithTZTx.defaultExpectation.paramPtrs.generated = &generated
|
||||
mmUpdateWithTZTx.defaultExpectation.expectationOrigins.originGenerated = minimock.CallerInfo(1)
|
||||
|
||||
return mmUpdateWithTZTx
|
||||
}
|
||||
|
||||
// Inspect accepts an inspector function that has same arguments as the RequestRepository.UpdateWithTZTx
|
||||
func (mmUpdateWithTZTx *mRequestRepositoryMockUpdateWithTZTx) Inspect(f func(ctx context.Context, tx pgx.Tx, id uuid.UUID, tz string, generated bool)) *mRequestRepositoryMockUpdateWithTZTx {
|
||||
if mmUpdateWithTZTx.mock.inspectFuncUpdateWithTZTx != nil {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("Inspect function is already set for RequestRepositoryMock.UpdateWithTZTx")
|
||||
}
|
||||
|
||||
mmUpdateWithTZTx.mock.inspectFuncUpdateWithTZTx = f
|
||||
|
||||
return mmUpdateWithTZTx
|
||||
}
|
||||
|
||||
// Return sets up results that will be returned by RequestRepository.UpdateWithTZTx
|
||||
func (mmUpdateWithTZTx *mRequestRepositoryMockUpdateWithTZTx) Return(err error) *RequestRepositoryMock {
|
||||
if mmUpdateWithTZTx.mock.funcUpdateWithTZTx != nil {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("RequestRepositoryMock.UpdateWithTZTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.defaultExpectation == nil {
|
||||
mmUpdateWithTZTx.defaultExpectation = &RequestRepositoryMockUpdateWithTZTxExpectation{mock: mmUpdateWithTZTx.mock}
|
||||
}
|
||||
mmUpdateWithTZTx.defaultExpectation.results = &RequestRepositoryMockUpdateWithTZTxResults{err}
|
||||
mmUpdateWithTZTx.defaultExpectation.returnOrigin = minimock.CallerInfo(1)
|
||||
return mmUpdateWithTZTx.mock
|
||||
}
|
||||
|
||||
// Set uses given function f to mock the RequestRepository.UpdateWithTZTx method
|
||||
func (mmUpdateWithTZTx *mRequestRepositoryMockUpdateWithTZTx) Set(f func(ctx context.Context, tx pgx.Tx, id uuid.UUID, tz string, generated bool) (err error)) *RequestRepositoryMock {
|
||||
if mmUpdateWithTZTx.defaultExpectation != nil {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("Default expectation is already set for the RequestRepository.UpdateWithTZTx method")
|
||||
}
|
||||
|
||||
if len(mmUpdateWithTZTx.expectations) > 0 {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("Some expectations are already set for the RequestRepository.UpdateWithTZTx method")
|
||||
}
|
||||
|
||||
mmUpdateWithTZTx.mock.funcUpdateWithTZTx = f
|
||||
mmUpdateWithTZTx.mock.funcUpdateWithTZTxOrigin = minimock.CallerInfo(1)
|
||||
return mmUpdateWithTZTx.mock
|
||||
}
|
||||
|
||||
// When sets expectation for the RequestRepository.UpdateWithTZTx which will trigger the result defined by the following
|
||||
// Then helper
|
||||
func (mmUpdateWithTZTx *mRequestRepositoryMockUpdateWithTZTx) When(ctx context.Context, tx pgx.Tx, id uuid.UUID, tz string, generated bool) *RequestRepositoryMockUpdateWithTZTxExpectation {
|
||||
if mmUpdateWithTZTx.mock.funcUpdateWithTZTx != nil {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("RequestRepositoryMock.UpdateWithTZTx mock is already set by Set")
|
||||
}
|
||||
|
||||
expectation := &RequestRepositoryMockUpdateWithTZTxExpectation{
|
||||
mock: mmUpdateWithTZTx.mock,
|
||||
params: &RequestRepositoryMockUpdateWithTZTxParams{ctx, tx, id, tz, generated},
|
||||
expectationOrigins: RequestRepositoryMockUpdateWithTZTxExpectationOrigins{origin: minimock.CallerInfo(1)},
|
||||
}
|
||||
mmUpdateWithTZTx.expectations = append(mmUpdateWithTZTx.expectations, expectation)
|
||||
return expectation
|
||||
}
|
||||
|
||||
// Then sets up RequestRepository.UpdateWithTZTx return parameters for the expectation previously defined by the When method
|
||||
func (e *RequestRepositoryMockUpdateWithTZTxExpectation) Then(err error) *RequestRepositoryMock {
|
||||
e.results = &RequestRepositoryMockUpdateWithTZTxResults{err}
|
||||
return e.mock
|
||||
}
|
||||
|
||||
// Times sets number of times RequestRepository.UpdateWithTZTx should be invoked
|
||||
func (mmUpdateWithTZTx *mRequestRepositoryMockUpdateWithTZTx) Times(n uint64) *mRequestRepositoryMockUpdateWithTZTx {
|
||||
if n == 0 {
|
||||
mmUpdateWithTZTx.mock.t.Fatalf("Times of RequestRepositoryMock.UpdateWithTZTx mock can not be zero")
|
||||
}
|
||||
mm_atomic.StoreUint64(&mmUpdateWithTZTx.expectedInvocations, n)
|
||||
mmUpdateWithTZTx.expectedInvocationsOrigin = minimock.CallerInfo(1)
|
||||
return mmUpdateWithTZTx
|
||||
}
|
||||
|
||||
func (mmUpdateWithTZTx *mRequestRepositoryMockUpdateWithTZTx) invocationsDone() bool {
|
||||
if len(mmUpdateWithTZTx.expectations) == 0 && mmUpdateWithTZTx.defaultExpectation == nil && mmUpdateWithTZTx.mock.funcUpdateWithTZTx == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
totalInvocations := mm_atomic.LoadUint64(&mmUpdateWithTZTx.mock.afterUpdateWithTZTxCounter)
|
||||
expectedInvocations := mm_atomic.LoadUint64(&mmUpdateWithTZTx.expectedInvocations)
|
||||
|
||||
return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
|
||||
}
|
||||
|
||||
// UpdateWithTZTx implements mm_repository.RequestRepository
|
||||
func (mmUpdateWithTZTx *RequestRepositoryMock) UpdateWithTZTx(ctx context.Context, tx pgx.Tx, id uuid.UUID, tz string, generated bool) (err error) {
|
||||
mm_atomic.AddUint64(&mmUpdateWithTZTx.beforeUpdateWithTZTxCounter, 1)
|
||||
defer mm_atomic.AddUint64(&mmUpdateWithTZTx.afterUpdateWithTZTxCounter, 1)
|
||||
|
||||
mmUpdateWithTZTx.t.Helper()
|
||||
|
||||
if mmUpdateWithTZTx.inspectFuncUpdateWithTZTx != nil {
|
||||
mmUpdateWithTZTx.inspectFuncUpdateWithTZTx(ctx, tx, id, tz, generated)
|
||||
}
|
||||
|
||||
mm_params := RequestRepositoryMockUpdateWithTZTxParams{ctx, tx, id, tz, generated}
|
||||
|
||||
// Record call args
|
||||
mmUpdateWithTZTx.UpdateWithTZTxMock.mutex.Lock()
|
||||
mmUpdateWithTZTx.UpdateWithTZTxMock.callArgs = append(mmUpdateWithTZTx.UpdateWithTZTxMock.callArgs, &mm_params)
|
||||
mmUpdateWithTZTx.UpdateWithTZTxMock.mutex.Unlock()
|
||||
|
||||
for _, e := range mmUpdateWithTZTx.UpdateWithTZTxMock.expectations {
|
||||
if minimock.Equal(*e.params, mm_params) {
|
||||
mm_atomic.AddUint64(&e.Counter, 1)
|
||||
return e.results.err
|
||||
}
|
||||
}
|
||||
|
||||
if mmUpdateWithTZTx.UpdateWithTZTxMock.defaultExpectation != nil {
|
||||
mm_atomic.AddUint64(&mmUpdateWithTZTx.UpdateWithTZTxMock.defaultExpectation.Counter, 1)
|
||||
mm_want := mmUpdateWithTZTx.UpdateWithTZTxMock.defaultExpectation.params
|
||||
mm_want_ptrs := mmUpdateWithTZTx.UpdateWithTZTxMock.defaultExpectation.paramPtrs
|
||||
|
||||
mm_got := RequestRepositoryMockUpdateWithTZTxParams{ctx, tx, id, tz, generated}
|
||||
|
||||
if mm_want_ptrs != nil {
|
||||
|
||||
if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) {
|
||||
mmUpdateWithTZTx.t.Errorf("RequestRepositoryMock.UpdateWithTZTx got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmUpdateWithTZTx.UpdateWithTZTxMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
|
||||
}
|
||||
|
||||
if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
|
||||
mmUpdateWithTZTx.t.Errorf("RequestRepositoryMock.UpdateWithTZTx got unexpected parameter tx, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmUpdateWithTZTx.UpdateWithTZTxMock.defaultExpectation.expectationOrigins.originTx, *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
|
||||
}
|
||||
|
||||
if mm_want_ptrs.id != nil && !minimock.Equal(*mm_want_ptrs.id, mm_got.id) {
|
||||
mmUpdateWithTZTx.t.Errorf("RequestRepositoryMock.UpdateWithTZTx got unexpected parameter id, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmUpdateWithTZTx.UpdateWithTZTxMock.defaultExpectation.expectationOrigins.originId, *mm_want_ptrs.id, mm_got.id, minimock.Diff(*mm_want_ptrs.id, mm_got.id))
|
||||
}
|
||||
|
||||
if mm_want_ptrs.tz != nil && !minimock.Equal(*mm_want_ptrs.tz, mm_got.tz) {
|
||||
mmUpdateWithTZTx.t.Errorf("RequestRepositoryMock.UpdateWithTZTx got unexpected parameter tz, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmUpdateWithTZTx.UpdateWithTZTxMock.defaultExpectation.expectationOrigins.originTz, *mm_want_ptrs.tz, mm_got.tz, minimock.Diff(*mm_want_ptrs.tz, mm_got.tz))
|
||||
}
|
||||
|
||||
if mm_want_ptrs.generated != nil && !minimock.Equal(*mm_want_ptrs.generated, mm_got.generated) {
|
||||
mmUpdateWithTZTx.t.Errorf("RequestRepositoryMock.UpdateWithTZTx got unexpected parameter generated, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmUpdateWithTZTx.UpdateWithTZTxMock.defaultExpectation.expectationOrigins.originGenerated, *mm_want_ptrs.generated, mm_got.generated, minimock.Diff(*mm_want_ptrs.generated, mm_got.generated))
|
||||
}
|
||||
|
||||
} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
|
||||
mmUpdateWithTZTx.t.Errorf("RequestRepositoryMock.UpdateWithTZTx got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmUpdateWithTZTx.UpdateWithTZTxMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
|
||||
}
|
||||
|
||||
mm_results := mmUpdateWithTZTx.UpdateWithTZTxMock.defaultExpectation.results
|
||||
if mm_results == nil {
|
||||
mmUpdateWithTZTx.t.Fatal("No results are set for the RequestRepositoryMock.UpdateWithTZTx")
|
||||
}
|
||||
return (*mm_results).err
|
||||
}
|
||||
if mmUpdateWithTZTx.funcUpdateWithTZTx != nil {
|
||||
return mmUpdateWithTZTx.funcUpdateWithTZTx(ctx, tx, id, tz, generated)
|
||||
}
|
||||
mmUpdateWithTZTx.t.Fatalf("Unexpected call to RequestRepositoryMock.UpdateWithTZTx. %v %v %v %v %v", ctx, tx, id, tz, generated)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateWithTZTxAfterCounter returns a count of finished RequestRepositoryMock.UpdateWithTZTx invocations
|
||||
func (mmUpdateWithTZTx *RequestRepositoryMock) UpdateWithTZTxAfterCounter() uint64 {
|
||||
return mm_atomic.LoadUint64(&mmUpdateWithTZTx.afterUpdateWithTZTxCounter)
|
||||
}
|
||||
|
||||
// UpdateWithTZTxBeforeCounter returns a count of RequestRepositoryMock.UpdateWithTZTx invocations
|
||||
func (mmUpdateWithTZTx *RequestRepositoryMock) UpdateWithTZTxBeforeCounter() uint64 {
|
||||
return mm_atomic.LoadUint64(&mmUpdateWithTZTx.beforeUpdateWithTZTxCounter)
|
||||
}
|
||||
|
||||
// Calls returns a list of arguments used in each call to RequestRepositoryMock.UpdateWithTZTx.
|
||||
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
|
||||
func (mmUpdateWithTZTx *mRequestRepositoryMockUpdateWithTZTx) Calls() []*RequestRepositoryMockUpdateWithTZTxParams {
|
||||
mmUpdateWithTZTx.mutex.RLock()
|
||||
|
||||
argCopy := make([]*RequestRepositoryMockUpdateWithTZTxParams, len(mmUpdateWithTZTx.callArgs))
|
||||
copy(argCopy, mmUpdateWithTZTx.callArgs)
|
||||
|
||||
mmUpdateWithTZTx.mutex.RUnlock()
|
||||
|
||||
return argCopy
|
||||
}
|
||||
|
||||
// MinimockUpdateWithTZTxDone returns true if the count of the UpdateWithTZTx invocations corresponds
|
||||
// the number of defined expectations
|
||||
func (m *RequestRepositoryMock) MinimockUpdateWithTZTxDone() bool {
|
||||
if m.UpdateWithTZTxMock.optional {
|
||||
// Optional methods provide '0 or more' call count restriction.
|
||||
return true
|
||||
}
|
||||
|
||||
for _, e := range m.UpdateWithTZTxMock.expectations {
|
||||
if mm_atomic.LoadUint64(&e.Counter) < 1 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return m.UpdateWithTZTxMock.invocationsDone()
|
||||
}
|
||||
|
||||
// MinimockUpdateWithTZTxInspect logs each unmet expectation
|
||||
func (m *RequestRepositoryMock) MinimockUpdateWithTZTxInspect() {
|
||||
for _, e := range m.UpdateWithTZTxMock.expectations {
|
||||
if mm_atomic.LoadUint64(&e.Counter) < 1 {
|
||||
m.t.Errorf("Expected call to RequestRepositoryMock.UpdateWithTZTx at\n%s with params: %#v", e.expectationOrigins.origin, *e.params)
|
||||
}
|
||||
}
|
||||
|
||||
afterUpdateWithTZTxCounter := mm_atomic.LoadUint64(&m.afterUpdateWithTZTxCounter)
|
||||
// if default expectation was set then invocations count should be greater than zero
|
||||
if m.UpdateWithTZTxMock.defaultExpectation != nil && afterUpdateWithTZTxCounter < 1 {
|
||||
if m.UpdateWithTZTxMock.defaultExpectation.params == nil {
|
||||
m.t.Errorf("Expected call to RequestRepositoryMock.UpdateWithTZTx at\n%s", m.UpdateWithTZTxMock.defaultExpectation.returnOrigin)
|
||||
} else {
|
||||
m.t.Errorf("Expected call to RequestRepositoryMock.UpdateWithTZTx at\n%s with params: %#v", m.UpdateWithTZTxMock.defaultExpectation.expectationOrigins.origin, *m.UpdateWithTZTxMock.defaultExpectation.params)
|
||||
}
|
||||
}
|
||||
// if func was set then invocations count should be greater than zero
|
||||
if m.funcUpdateWithTZTx != nil && afterUpdateWithTZTxCounter < 1 {
|
||||
m.t.Errorf("Expected call to RequestRepositoryMock.UpdateWithTZTx at\n%s", m.funcUpdateWithTZTxOrigin)
|
||||
}
|
||||
|
||||
if !m.UpdateWithTZTxMock.invocationsDone() && afterUpdateWithTZTxCounter > 0 {
|
||||
m.t.Errorf("Expected %d calls to RequestRepositoryMock.UpdateWithTZTx at\n%s but found %d calls",
|
||||
mm_atomic.LoadUint64(&m.UpdateWithTZTxMock.expectedInvocations), m.UpdateWithTZTxMock.expectedInvocationsOrigin, afterUpdateWithTZTxCounter)
|
||||
}
|
||||
}
|
||||
|
||||
// MinimockFinish checks that all mocked methods have been called the expected number of times
|
||||
func (m *RequestRepositoryMock) MinimockFinish() {
|
||||
m.finishOnce.Do(func() {
|
||||
@@ -2614,6 +3060,8 @@ func (m *RequestRepositoryMock) MinimockFinish() {
|
||||
m.MinimockUpdateFinalTZInspect()
|
||||
|
||||
m.MinimockUpdateWithTZInspect()
|
||||
|
||||
m.MinimockUpdateWithTZTxInspect()
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -2643,5 +3091,6 @@ func (m *RequestRepositoryMock) minimockDone() bool {
|
||||
m.MinimockGetDetailByIDDone() &&
|
||||
m.MinimockGetUserStatisticsDone() &&
|
||||
m.MinimockUpdateFinalTZDone() &&
|
||||
m.MinimockUpdateWithTZDone()
|
||||
m.MinimockUpdateWithTZDone() &&
|
||||
m.MinimockUpdateWithTZTxDone()
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
|
||||
package mocks
|
||||
|
||||
//go:generate minimock -i smart-search-back/internal/service.RequestService -o request_service_mock.go -n RequestServiceMock -p mocks
|
||||
//go:generate minimock -i git.techease.ru/Smart-search/smart-search-back/internal/service.RequestService -o request_service_mock.go -n RequestServiceMock -p mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"smart-search-back/internal/model"
|
||||
"sync"
|
||||
mm_atomic "sync/atomic"
|
||||
mm_time "time"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
"github.com/gojuno/minimock/v3"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
|
||||
package mocks
|
||||
|
||||
//go:generate minimock -i smart-search-back/internal/repository.SessionRepository -o session_repository_mock.go -n SessionRepositoryMock -p mocks
|
||||
//go:generate minimock -i git.techease.ru/Smart-search/smart-search-back/internal/repository.SessionRepository -o session_repository_mock.go -n SessionRepositoryMock -p mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"smart-search-back/internal/model"
|
||||
"sync"
|
||||
mm_atomic "sync/atomic"
|
||||
mm_time "time"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
"github.com/gojuno/minimock/v3"
|
||||
)
|
||||
|
||||
@@ -40,6 +40,13 @@ type SessionRepositoryMock struct {
|
||||
beforeFindByRefreshTokenCounter uint64
|
||||
FindByRefreshTokenMock mSessionRepositoryMockFindByRefreshToken
|
||||
|
||||
funcIsAccessTokenValid func(ctx context.Context, accessToken string) (b1 bool, err error)
|
||||
funcIsAccessTokenValidOrigin string
|
||||
inspectFuncIsAccessTokenValid func(ctx context.Context, accessToken string)
|
||||
afterIsAccessTokenValidCounter uint64
|
||||
beforeIsAccessTokenValidCounter uint64
|
||||
IsAccessTokenValidMock mSessionRepositoryMockIsAccessTokenValid
|
||||
|
||||
funcRevoke func(ctx context.Context, refreshToken string) (err error)
|
||||
funcRevokeOrigin string
|
||||
inspectFuncRevoke func(ctx context.Context, refreshToken string)
|
||||
@@ -47,6 +54,13 @@ type SessionRepositoryMock struct {
|
||||
beforeRevokeCounter uint64
|
||||
RevokeMock mSessionRepositoryMockRevoke
|
||||
|
||||
funcRevokeByAccessToken func(ctx context.Context, accessToken string) (err error)
|
||||
funcRevokeByAccessTokenOrigin string
|
||||
inspectFuncRevokeByAccessToken func(ctx context.Context, accessToken string)
|
||||
afterRevokeByAccessTokenCounter uint64
|
||||
beforeRevokeByAccessTokenCounter uint64
|
||||
RevokeByAccessTokenMock mSessionRepositoryMockRevokeByAccessToken
|
||||
|
||||
funcUpdateAccessToken func(ctx context.Context, refreshToken string, newAccessToken string) (err error)
|
||||
funcUpdateAccessTokenOrigin string
|
||||
inspectFuncUpdateAccessToken func(ctx context.Context, refreshToken string, newAccessToken string)
|
||||
@@ -72,9 +86,15 @@ func NewSessionRepositoryMock(t minimock.Tester) *SessionRepositoryMock {
|
||||
m.FindByRefreshTokenMock = mSessionRepositoryMockFindByRefreshToken{mock: m}
|
||||
m.FindByRefreshTokenMock.callArgs = []*SessionRepositoryMockFindByRefreshTokenParams{}
|
||||
|
||||
m.IsAccessTokenValidMock = mSessionRepositoryMockIsAccessTokenValid{mock: m}
|
||||
m.IsAccessTokenValidMock.callArgs = []*SessionRepositoryMockIsAccessTokenValidParams{}
|
||||
|
||||
m.RevokeMock = mSessionRepositoryMockRevoke{mock: m}
|
||||
m.RevokeMock.callArgs = []*SessionRepositoryMockRevokeParams{}
|
||||
|
||||
m.RevokeByAccessTokenMock = mSessionRepositoryMockRevokeByAccessToken{mock: m}
|
||||
m.RevokeByAccessTokenMock.callArgs = []*SessionRepositoryMockRevokeByAccessTokenParams{}
|
||||
|
||||
m.UpdateAccessTokenMock = mSessionRepositoryMockUpdateAccessToken{mock: m}
|
||||
m.UpdateAccessTokenMock.callArgs = []*SessionRepositoryMockUpdateAccessTokenParams{}
|
||||
|
||||
@@ -1080,6 +1100,349 @@ func (m *SessionRepositoryMock) MinimockFindByRefreshTokenInspect() {
|
||||
}
|
||||
}
|
||||
|
||||
type mSessionRepositoryMockIsAccessTokenValid struct {
|
||||
optional bool
|
||||
mock *SessionRepositoryMock
|
||||
defaultExpectation *SessionRepositoryMockIsAccessTokenValidExpectation
|
||||
expectations []*SessionRepositoryMockIsAccessTokenValidExpectation
|
||||
|
||||
callArgs []*SessionRepositoryMockIsAccessTokenValidParams
|
||||
mutex sync.RWMutex
|
||||
|
||||
expectedInvocations uint64
|
||||
expectedInvocationsOrigin string
|
||||
}
|
||||
|
||||
// SessionRepositoryMockIsAccessTokenValidExpectation specifies expectation struct of the SessionRepository.IsAccessTokenValid
|
||||
type SessionRepositoryMockIsAccessTokenValidExpectation struct {
|
||||
mock *SessionRepositoryMock
|
||||
params *SessionRepositoryMockIsAccessTokenValidParams
|
||||
paramPtrs *SessionRepositoryMockIsAccessTokenValidParamPtrs
|
||||
expectationOrigins SessionRepositoryMockIsAccessTokenValidExpectationOrigins
|
||||
results *SessionRepositoryMockIsAccessTokenValidResults
|
||||
returnOrigin string
|
||||
Counter uint64
|
||||
}
|
||||
|
||||
// SessionRepositoryMockIsAccessTokenValidParams contains parameters of the SessionRepository.IsAccessTokenValid
|
||||
type SessionRepositoryMockIsAccessTokenValidParams struct {
|
||||
ctx context.Context
|
||||
accessToken string
|
||||
}
|
||||
|
||||
// SessionRepositoryMockIsAccessTokenValidParamPtrs contains pointers to parameters of the SessionRepository.IsAccessTokenValid
|
||||
type SessionRepositoryMockIsAccessTokenValidParamPtrs struct {
|
||||
ctx *context.Context
|
||||
accessToken *string
|
||||
}
|
||||
|
||||
// SessionRepositoryMockIsAccessTokenValidResults contains results of the SessionRepository.IsAccessTokenValid
|
||||
type SessionRepositoryMockIsAccessTokenValidResults struct {
|
||||
b1 bool
|
||||
err error
|
||||
}
|
||||
|
||||
// SessionRepositoryMockIsAccessTokenValidOrigins contains origins of expectations of the SessionRepository.IsAccessTokenValid
|
||||
type SessionRepositoryMockIsAccessTokenValidExpectationOrigins struct {
|
||||
origin string
|
||||
originCtx string
|
||||
originAccessToken string
|
||||
}
|
||||
|
||||
// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning
|
||||
// the test will fail minimock's automatic final call check if the mocked method was not called at least once.
|
||||
// Optional() makes method check to work in '0 or more' mode.
|
||||
// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to
|
||||
// catch the problems when the expected method call is totally skipped during test run.
|
||||
func (mmIsAccessTokenValid *mSessionRepositoryMockIsAccessTokenValid) Optional() *mSessionRepositoryMockIsAccessTokenValid {
|
||||
mmIsAccessTokenValid.optional = true
|
||||
return mmIsAccessTokenValid
|
||||
}
|
||||
|
||||
// Expect sets up expected params for SessionRepository.IsAccessTokenValid
|
||||
func (mmIsAccessTokenValid *mSessionRepositoryMockIsAccessTokenValid) Expect(ctx context.Context, accessToken string) *mSessionRepositoryMockIsAccessTokenValid {
|
||||
if mmIsAccessTokenValid.mock.funcIsAccessTokenValid != nil {
|
||||
mmIsAccessTokenValid.mock.t.Fatalf("SessionRepositoryMock.IsAccessTokenValid mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmIsAccessTokenValid.defaultExpectation == nil {
|
||||
mmIsAccessTokenValid.defaultExpectation = &SessionRepositoryMockIsAccessTokenValidExpectation{}
|
||||
}
|
||||
|
||||
if mmIsAccessTokenValid.defaultExpectation.paramPtrs != nil {
|
||||
mmIsAccessTokenValid.mock.t.Fatalf("SessionRepositoryMock.IsAccessTokenValid mock is already set by ExpectParams functions")
|
||||
}
|
||||
|
||||
mmIsAccessTokenValid.defaultExpectation.params = &SessionRepositoryMockIsAccessTokenValidParams{ctx, accessToken}
|
||||
mmIsAccessTokenValid.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1)
|
||||
for _, e := range mmIsAccessTokenValid.expectations {
|
||||
if minimock.Equal(e.params, mmIsAccessTokenValid.defaultExpectation.params) {
|
||||
mmIsAccessTokenValid.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmIsAccessTokenValid.defaultExpectation.params)
|
||||
}
|
||||
}
|
||||
|
||||
return mmIsAccessTokenValid
|
||||
}
|
||||
|
||||
// ExpectCtxParam1 sets up expected param ctx for SessionRepository.IsAccessTokenValid
|
||||
func (mmIsAccessTokenValid *mSessionRepositoryMockIsAccessTokenValid) ExpectCtxParam1(ctx context.Context) *mSessionRepositoryMockIsAccessTokenValid {
|
||||
if mmIsAccessTokenValid.mock.funcIsAccessTokenValid != nil {
|
||||
mmIsAccessTokenValid.mock.t.Fatalf("SessionRepositoryMock.IsAccessTokenValid mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmIsAccessTokenValid.defaultExpectation == nil {
|
||||
mmIsAccessTokenValid.defaultExpectation = &SessionRepositoryMockIsAccessTokenValidExpectation{}
|
||||
}
|
||||
|
||||
if mmIsAccessTokenValid.defaultExpectation.params != nil {
|
||||
mmIsAccessTokenValid.mock.t.Fatalf("SessionRepositoryMock.IsAccessTokenValid mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmIsAccessTokenValid.defaultExpectation.paramPtrs == nil {
|
||||
mmIsAccessTokenValid.defaultExpectation.paramPtrs = &SessionRepositoryMockIsAccessTokenValidParamPtrs{}
|
||||
}
|
||||
mmIsAccessTokenValid.defaultExpectation.paramPtrs.ctx = &ctx
|
||||
mmIsAccessTokenValid.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1)
|
||||
|
||||
return mmIsAccessTokenValid
|
||||
}
|
||||
|
||||
// ExpectAccessTokenParam2 sets up expected param accessToken for SessionRepository.IsAccessTokenValid
|
||||
func (mmIsAccessTokenValid *mSessionRepositoryMockIsAccessTokenValid) ExpectAccessTokenParam2(accessToken string) *mSessionRepositoryMockIsAccessTokenValid {
|
||||
if mmIsAccessTokenValid.mock.funcIsAccessTokenValid != nil {
|
||||
mmIsAccessTokenValid.mock.t.Fatalf("SessionRepositoryMock.IsAccessTokenValid mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmIsAccessTokenValid.defaultExpectation == nil {
|
||||
mmIsAccessTokenValid.defaultExpectation = &SessionRepositoryMockIsAccessTokenValidExpectation{}
|
||||
}
|
||||
|
||||
if mmIsAccessTokenValid.defaultExpectation.params != nil {
|
||||
mmIsAccessTokenValid.mock.t.Fatalf("SessionRepositoryMock.IsAccessTokenValid mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmIsAccessTokenValid.defaultExpectation.paramPtrs == nil {
|
||||
mmIsAccessTokenValid.defaultExpectation.paramPtrs = &SessionRepositoryMockIsAccessTokenValidParamPtrs{}
|
||||
}
|
||||
mmIsAccessTokenValid.defaultExpectation.paramPtrs.accessToken = &accessToken
|
||||
mmIsAccessTokenValid.defaultExpectation.expectationOrigins.originAccessToken = minimock.CallerInfo(1)
|
||||
|
||||
return mmIsAccessTokenValid
|
||||
}
|
||||
|
||||
// Inspect accepts an inspector function that has same arguments as the SessionRepository.IsAccessTokenValid
|
||||
func (mmIsAccessTokenValid *mSessionRepositoryMockIsAccessTokenValid) Inspect(f func(ctx context.Context, accessToken string)) *mSessionRepositoryMockIsAccessTokenValid {
|
||||
if mmIsAccessTokenValid.mock.inspectFuncIsAccessTokenValid != nil {
|
||||
mmIsAccessTokenValid.mock.t.Fatalf("Inspect function is already set for SessionRepositoryMock.IsAccessTokenValid")
|
||||
}
|
||||
|
||||
mmIsAccessTokenValid.mock.inspectFuncIsAccessTokenValid = f
|
||||
|
||||
return mmIsAccessTokenValid
|
||||
}
|
||||
|
||||
// Return sets up results that will be returned by SessionRepository.IsAccessTokenValid
|
||||
func (mmIsAccessTokenValid *mSessionRepositoryMockIsAccessTokenValid) Return(b1 bool, err error) *SessionRepositoryMock {
|
||||
if mmIsAccessTokenValid.mock.funcIsAccessTokenValid != nil {
|
||||
mmIsAccessTokenValid.mock.t.Fatalf("SessionRepositoryMock.IsAccessTokenValid mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmIsAccessTokenValid.defaultExpectation == nil {
|
||||
mmIsAccessTokenValid.defaultExpectation = &SessionRepositoryMockIsAccessTokenValidExpectation{mock: mmIsAccessTokenValid.mock}
|
||||
}
|
||||
mmIsAccessTokenValid.defaultExpectation.results = &SessionRepositoryMockIsAccessTokenValidResults{b1, err}
|
||||
mmIsAccessTokenValid.defaultExpectation.returnOrigin = minimock.CallerInfo(1)
|
||||
return mmIsAccessTokenValid.mock
|
||||
}
|
||||
|
||||
// Set uses given function f to mock the SessionRepository.IsAccessTokenValid method
|
||||
func (mmIsAccessTokenValid *mSessionRepositoryMockIsAccessTokenValid) Set(f func(ctx context.Context, accessToken string) (b1 bool, err error)) *SessionRepositoryMock {
|
||||
if mmIsAccessTokenValid.defaultExpectation != nil {
|
||||
mmIsAccessTokenValid.mock.t.Fatalf("Default expectation is already set for the SessionRepository.IsAccessTokenValid method")
|
||||
}
|
||||
|
||||
if len(mmIsAccessTokenValid.expectations) > 0 {
|
||||
mmIsAccessTokenValid.mock.t.Fatalf("Some expectations are already set for the SessionRepository.IsAccessTokenValid method")
|
||||
}
|
||||
|
||||
mmIsAccessTokenValid.mock.funcIsAccessTokenValid = f
|
||||
mmIsAccessTokenValid.mock.funcIsAccessTokenValidOrigin = minimock.CallerInfo(1)
|
||||
return mmIsAccessTokenValid.mock
|
||||
}
|
||||
|
||||
// When sets expectation for the SessionRepository.IsAccessTokenValid which will trigger the result defined by the following
|
||||
// Then helper
|
||||
func (mmIsAccessTokenValid *mSessionRepositoryMockIsAccessTokenValid) When(ctx context.Context, accessToken string) *SessionRepositoryMockIsAccessTokenValidExpectation {
|
||||
if mmIsAccessTokenValid.mock.funcIsAccessTokenValid != nil {
|
||||
mmIsAccessTokenValid.mock.t.Fatalf("SessionRepositoryMock.IsAccessTokenValid mock is already set by Set")
|
||||
}
|
||||
|
||||
expectation := &SessionRepositoryMockIsAccessTokenValidExpectation{
|
||||
mock: mmIsAccessTokenValid.mock,
|
||||
params: &SessionRepositoryMockIsAccessTokenValidParams{ctx, accessToken},
|
||||
expectationOrigins: SessionRepositoryMockIsAccessTokenValidExpectationOrigins{origin: minimock.CallerInfo(1)},
|
||||
}
|
||||
mmIsAccessTokenValid.expectations = append(mmIsAccessTokenValid.expectations, expectation)
|
||||
return expectation
|
||||
}
|
||||
|
||||
// Then sets up SessionRepository.IsAccessTokenValid return parameters for the expectation previously defined by the When method
|
||||
func (e *SessionRepositoryMockIsAccessTokenValidExpectation) Then(b1 bool, err error) *SessionRepositoryMock {
|
||||
e.results = &SessionRepositoryMockIsAccessTokenValidResults{b1, err}
|
||||
return e.mock
|
||||
}
|
||||
|
||||
// Times sets number of times SessionRepository.IsAccessTokenValid should be invoked
|
||||
func (mmIsAccessTokenValid *mSessionRepositoryMockIsAccessTokenValid) Times(n uint64) *mSessionRepositoryMockIsAccessTokenValid {
|
||||
if n == 0 {
|
||||
mmIsAccessTokenValid.mock.t.Fatalf("Times of SessionRepositoryMock.IsAccessTokenValid mock can not be zero")
|
||||
}
|
||||
mm_atomic.StoreUint64(&mmIsAccessTokenValid.expectedInvocations, n)
|
||||
mmIsAccessTokenValid.expectedInvocationsOrigin = minimock.CallerInfo(1)
|
||||
return mmIsAccessTokenValid
|
||||
}
|
||||
|
||||
func (mmIsAccessTokenValid *mSessionRepositoryMockIsAccessTokenValid) invocationsDone() bool {
|
||||
if len(mmIsAccessTokenValid.expectations) == 0 && mmIsAccessTokenValid.defaultExpectation == nil && mmIsAccessTokenValid.mock.funcIsAccessTokenValid == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
totalInvocations := mm_atomic.LoadUint64(&mmIsAccessTokenValid.mock.afterIsAccessTokenValidCounter)
|
||||
expectedInvocations := mm_atomic.LoadUint64(&mmIsAccessTokenValid.expectedInvocations)
|
||||
|
||||
return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
|
||||
}
|
||||
|
||||
// IsAccessTokenValid implements mm_repository.SessionRepository
|
||||
func (mmIsAccessTokenValid *SessionRepositoryMock) IsAccessTokenValid(ctx context.Context, accessToken string) (b1 bool, err error) {
|
||||
mm_atomic.AddUint64(&mmIsAccessTokenValid.beforeIsAccessTokenValidCounter, 1)
|
||||
defer mm_atomic.AddUint64(&mmIsAccessTokenValid.afterIsAccessTokenValidCounter, 1)
|
||||
|
||||
mmIsAccessTokenValid.t.Helper()
|
||||
|
||||
if mmIsAccessTokenValid.inspectFuncIsAccessTokenValid != nil {
|
||||
mmIsAccessTokenValid.inspectFuncIsAccessTokenValid(ctx, accessToken)
|
||||
}
|
||||
|
||||
mm_params := SessionRepositoryMockIsAccessTokenValidParams{ctx, accessToken}
|
||||
|
||||
// Record call args
|
||||
mmIsAccessTokenValid.IsAccessTokenValidMock.mutex.Lock()
|
||||
mmIsAccessTokenValid.IsAccessTokenValidMock.callArgs = append(mmIsAccessTokenValid.IsAccessTokenValidMock.callArgs, &mm_params)
|
||||
mmIsAccessTokenValid.IsAccessTokenValidMock.mutex.Unlock()
|
||||
|
||||
for _, e := range mmIsAccessTokenValid.IsAccessTokenValidMock.expectations {
|
||||
if minimock.Equal(*e.params, mm_params) {
|
||||
mm_atomic.AddUint64(&e.Counter, 1)
|
||||
return e.results.b1, e.results.err
|
||||
}
|
||||
}
|
||||
|
||||
if mmIsAccessTokenValid.IsAccessTokenValidMock.defaultExpectation != nil {
|
||||
mm_atomic.AddUint64(&mmIsAccessTokenValid.IsAccessTokenValidMock.defaultExpectation.Counter, 1)
|
||||
mm_want := mmIsAccessTokenValid.IsAccessTokenValidMock.defaultExpectation.params
|
||||
mm_want_ptrs := mmIsAccessTokenValid.IsAccessTokenValidMock.defaultExpectation.paramPtrs
|
||||
|
||||
mm_got := SessionRepositoryMockIsAccessTokenValidParams{ctx, accessToken}
|
||||
|
||||
if mm_want_ptrs != nil {
|
||||
|
||||
if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) {
|
||||
mmIsAccessTokenValid.t.Errorf("SessionRepositoryMock.IsAccessTokenValid got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmIsAccessTokenValid.IsAccessTokenValidMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
|
||||
}
|
||||
|
||||
if mm_want_ptrs.accessToken != nil && !minimock.Equal(*mm_want_ptrs.accessToken, mm_got.accessToken) {
|
||||
mmIsAccessTokenValid.t.Errorf("SessionRepositoryMock.IsAccessTokenValid got unexpected parameter accessToken, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmIsAccessTokenValid.IsAccessTokenValidMock.defaultExpectation.expectationOrigins.originAccessToken, *mm_want_ptrs.accessToken, mm_got.accessToken, minimock.Diff(*mm_want_ptrs.accessToken, mm_got.accessToken))
|
||||
}
|
||||
|
||||
} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
|
||||
mmIsAccessTokenValid.t.Errorf("SessionRepositoryMock.IsAccessTokenValid got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmIsAccessTokenValid.IsAccessTokenValidMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
|
||||
}
|
||||
|
||||
mm_results := mmIsAccessTokenValid.IsAccessTokenValidMock.defaultExpectation.results
|
||||
if mm_results == nil {
|
||||
mmIsAccessTokenValid.t.Fatal("No results are set for the SessionRepositoryMock.IsAccessTokenValid")
|
||||
}
|
||||
return (*mm_results).b1, (*mm_results).err
|
||||
}
|
||||
if mmIsAccessTokenValid.funcIsAccessTokenValid != nil {
|
||||
return mmIsAccessTokenValid.funcIsAccessTokenValid(ctx, accessToken)
|
||||
}
|
||||
mmIsAccessTokenValid.t.Fatalf("Unexpected call to SessionRepositoryMock.IsAccessTokenValid. %v %v", ctx, accessToken)
|
||||
return
|
||||
}
|
||||
|
||||
// IsAccessTokenValidAfterCounter returns a count of finished SessionRepositoryMock.IsAccessTokenValid invocations
|
||||
func (mmIsAccessTokenValid *SessionRepositoryMock) IsAccessTokenValidAfterCounter() uint64 {
|
||||
return mm_atomic.LoadUint64(&mmIsAccessTokenValid.afterIsAccessTokenValidCounter)
|
||||
}
|
||||
|
||||
// IsAccessTokenValidBeforeCounter returns a count of SessionRepositoryMock.IsAccessTokenValid invocations
|
||||
func (mmIsAccessTokenValid *SessionRepositoryMock) IsAccessTokenValidBeforeCounter() uint64 {
|
||||
return mm_atomic.LoadUint64(&mmIsAccessTokenValid.beforeIsAccessTokenValidCounter)
|
||||
}
|
||||
|
||||
// Calls returns a list of arguments used in each call to SessionRepositoryMock.IsAccessTokenValid.
|
||||
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
|
||||
func (mmIsAccessTokenValid *mSessionRepositoryMockIsAccessTokenValid) Calls() []*SessionRepositoryMockIsAccessTokenValidParams {
|
||||
mmIsAccessTokenValid.mutex.RLock()
|
||||
|
||||
argCopy := make([]*SessionRepositoryMockIsAccessTokenValidParams, len(mmIsAccessTokenValid.callArgs))
|
||||
copy(argCopy, mmIsAccessTokenValid.callArgs)
|
||||
|
||||
mmIsAccessTokenValid.mutex.RUnlock()
|
||||
|
||||
return argCopy
|
||||
}
|
||||
|
||||
// MinimockIsAccessTokenValidDone returns true if the count of the IsAccessTokenValid invocations corresponds
|
||||
// the number of defined expectations
|
||||
func (m *SessionRepositoryMock) MinimockIsAccessTokenValidDone() bool {
|
||||
if m.IsAccessTokenValidMock.optional {
|
||||
// Optional methods provide '0 or more' call count restriction.
|
||||
return true
|
||||
}
|
||||
|
||||
for _, e := range m.IsAccessTokenValidMock.expectations {
|
||||
if mm_atomic.LoadUint64(&e.Counter) < 1 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return m.IsAccessTokenValidMock.invocationsDone()
|
||||
}
|
||||
|
||||
// MinimockIsAccessTokenValidInspect logs each unmet expectation
|
||||
func (m *SessionRepositoryMock) MinimockIsAccessTokenValidInspect() {
|
||||
for _, e := range m.IsAccessTokenValidMock.expectations {
|
||||
if mm_atomic.LoadUint64(&e.Counter) < 1 {
|
||||
m.t.Errorf("Expected call to SessionRepositoryMock.IsAccessTokenValid at\n%s with params: %#v", e.expectationOrigins.origin, *e.params)
|
||||
}
|
||||
}
|
||||
|
||||
afterIsAccessTokenValidCounter := mm_atomic.LoadUint64(&m.afterIsAccessTokenValidCounter)
|
||||
// if default expectation was set then invocations count should be greater than zero
|
||||
if m.IsAccessTokenValidMock.defaultExpectation != nil && afterIsAccessTokenValidCounter < 1 {
|
||||
if m.IsAccessTokenValidMock.defaultExpectation.params == nil {
|
||||
m.t.Errorf("Expected call to SessionRepositoryMock.IsAccessTokenValid at\n%s", m.IsAccessTokenValidMock.defaultExpectation.returnOrigin)
|
||||
} else {
|
||||
m.t.Errorf("Expected call to SessionRepositoryMock.IsAccessTokenValid at\n%s with params: %#v", m.IsAccessTokenValidMock.defaultExpectation.expectationOrigins.origin, *m.IsAccessTokenValidMock.defaultExpectation.params)
|
||||
}
|
||||
}
|
||||
// if func was set then invocations count should be greater than zero
|
||||
if m.funcIsAccessTokenValid != nil && afterIsAccessTokenValidCounter < 1 {
|
||||
m.t.Errorf("Expected call to SessionRepositoryMock.IsAccessTokenValid at\n%s", m.funcIsAccessTokenValidOrigin)
|
||||
}
|
||||
|
||||
if !m.IsAccessTokenValidMock.invocationsDone() && afterIsAccessTokenValidCounter > 0 {
|
||||
m.t.Errorf("Expected %d calls to SessionRepositoryMock.IsAccessTokenValid at\n%s but found %d calls",
|
||||
mm_atomic.LoadUint64(&m.IsAccessTokenValidMock.expectedInvocations), m.IsAccessTokenValidMock.expectedInvocationsOrigin, afterIsAccessTokenValidCounter)
|
||||
}
|
||||
}
|
||||
|
||||
type mSessionRepositoryMockRevoke struct {
|
||||
optional bool
|
||||
mock *SessionRepositoryMock
|
||||
@@ -1422,6 +1785,348 @@ func (m *SessionRepositoryMock) MinimockRevokeInspect() {
|
||||
}
|
||||
}
|
||||
|
||||
type mSessionRepositoryMockRevokeByAccessToken struct {
|
||||
optional bool
|
||||
mock *SessionRepositoryMock
|
||||
defaultExpectation *SessionRepositoryMockRevokeByAccessTokenExpectation
|
||||
expectations []*SessionRepositoryMockRevokeByAccessTokenExpectation
|
||||
|
||||
callArgs []*SessionRepositoryMockRevokeByAccessTokenParams
|
||||
mutex sync.RWMutex
|
||||
|
||||
expectedInvocations uint64
|
||||
expectedInvocationsOrigin string
|
||||
}
|
||||
|
||||
// SessionRepositoryMockRevokeByAccessTokenExpectation specifies expectation struct of the SessionRepository.RevokeByAccessToken
|
||||
type SessionRepositoryMockRevokeByAccessTokenExpectation struct {
|
||||
mock *SessionRepositoryMock
|
||||
params *SessionRepositoryMockRevokeByAccessTokenParams
|
||||
paramPtrs *SessionRepositoryMockRevokeByAccessTokenParamPtrs
|
||||
expectationOrigins SessionRepositoryMockRevokeByAccessTokenExpectationOrigins
|
||||
results *SessionRepositoryMockRevokeByAccessTokenResults
|
||||
returnOrigin string
|
||||
Counter uint64
|
||||
}
|
||||
|
||||
// SessionRepositoryMockRevokeByAccessTokenParams contains parameters of the SessionRepository.RevokeByAccessToken
|
||||
type SessionRepositoryMockRevokeByAccessTokenParams struct {
|
||||
ctx context.Context
|
||||
accessToken string
|
||||
}
|
||||
|
||||
// SessionRepositoryMockRevokeByAccessTokenParamPtrs contains pointers to parameters of the SessionRepository.RevokeByAccessToken
|
||||
type SessionRepositoryMockRevokeByAccessTokenParamPtrs struct {
|
||||
ctx *context.Context
|
||||
accessToken *string
|
||||
}
|
||||
|
||||
// SessionRepositoryMockRevokeByAccessTokenResults contains results of the SessionRepository.RevokeByAccessToken
|
||||
type SessionRepositoryMockRevokeByAccessTokenResults struct {
|
||||
err error
|
||||
}
|
||||
|
||||
// SessionRepositoryMockRevokeByAccessTokenOrigins contains origins of expectations of the SessionRepository.RevokeByAccessToken
|
||||
type SessionRepositoryMockRevokeByAccessTokenExpectationOrigins struct {
|
||||
origin string
|
||||
originCtx string
|
||||
originAccessToken string
|
||||
}
|
||||
|
||||
// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning
|
||||
// the test will fail minimock's automatic final call check if the mocked method was not called at least once.
|
||||
// Optional() makes method check to work in '0 or more' mode.
|
||||
// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to
|
||||
// catch the problems when the expected method call is totally skipped during test run.
|
||||
func (mmRevokeByAccessToken *mSessionRepositoryMockRevokeByAccessToken) Optional() *mSessionRepositoryMockRevokeByAccessToken {
|
||||
mmRevokeByAccessToken.optional = true
|
||||
return mmRevokeByAccessToken
|
||||
}
|
||||
|
||||
// Expect sets up expected params for SessionRepository.RevokeByAccessToken
|
||||
func (mmRevokeByAccessToken *mSessionRepositoryMockRevokeByAccessToken) Expect(ctx context.Context, accessToken string) *mSessionRepositoryMockRevokeByAccessToken {
|
||||
if mmRevokeByAccessToken.mock.funcRevokeByAccessToken != nil {
|
||||
mmRevokeByAccessToken.mock.t.Fatalf("SessionRepositoryMock.RevokeByAccessToken mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmRevokeByAccessToken.defaultExpectation == nil {
|
||||
mmRevokeByAccessToken.defaultExpectation = &SessionRepositoryMockRevokeByAccessTokenExpectation{}
|
||||
}
|
||||
|
||||
if mmRevokeByAccessToken.defaultExpectation.paramPtrs != nil {
|
||||
mmRevokeByAccessToken.mock.t.Fatalf("SessionRepositoryMock.RevokeByAccessToken mock is already set by ExpectParams functions")
|
||||
}
|
||||
|
||||
mmRevokeByAccessToken.defaultExpectation.params = &SessionRepositoryMockRevokeByAccessTokenParams{ctx, accessToken}
|
||||
mmRevokeByAccessToken.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1)
|
||||
for _, e := range mmRevokeByAccessToken.expectations {
|
||||
if minimock.Equal(e.params, mmRevokeByAccessToken.defaultExpectation.params) {
|
||||
mmRevokeByAccessToken.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmRevokeByAccessToken.defaultExpectation.params)
|
||||
}
|
||||
}
|
||||
|
||||
return mmRevokeByAccessToken
|
||||
}
|
||||
|
||||
// ExpectCtxParam1 sets up expected param ctx for SessionRepository.RevokeByAccessToken
|
||||
func (mmRevokeByAccessToken *mSessionRepositoryMockRevokeByAccessToken) ExpectCtxParam1(ctx context.Context) *mSessionRepositoryMockRevokeByAccessToken {
|
||||
if mmRevokeByAccessToken.mock.funcRevokeByAccessToken != nil {
|
||||
mmRevokeByAccessToken.mock.t.Fatalf("SessionRepositoryMock.RevokeByAccessToken mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmRevokeByAccessToken.defaultExpectation == nil {
|
||||
mmRevokeByAccessToken.defaultExpectation = &SessionRepositoryMockRevokeByAccessTokenExpectation{}
|
||||
}
|
||||
|
||||
if mmRevokeByAccessToken.defaultExpectation.params != nil {
|
||||
mmRevokeByAccessToken.mock.t.Fatalf("SessionRepositoryMock.RevokeByAccessToken mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmRevokeByAccessToken.defaultExpectation.paramPtrs == nil {
|
||||
mmRevokeByAccessToken.defaultExpectation.paramPtrs = &SessionRepositoryMockRevokeByAccessTokenParamPtrs{}
|
||||
}
|
||||
mmRevokeByAccessToken.defaultExpectation.paramPtrs.ctx = &ctx
|
||||
mmRevokeByAccessToken.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1)
|
||||
|
||||
return mmRevokeByAccessToken
|
||||
}
|
||||
|
||||
// ExpectAccessTokenParam2 sets up expected param accessToken for SessionRepository.RevokeByAccessToken
|
||||
func (mmRevokeByAccessToken *mSessionRepositoryMockRevokeByAccessToken) ExpectAccessTokenParam2(accessToken string) *mSessionRepositoryMockRevokeByAccessToken {
|
||||
if mmRevokeByAccessToken.mock.funcRevokeByAccessToken != nil {
|
||||
mmRevokeByAccessToken.mock.t.Fatalf("SessionRepositoryMock.RevokeByAccessToken mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmRevokeByAccessToken.defaultExpectation == nil {
|
||||
mmRevokeByAccessToken.defaultExpectation = &SessionRepositoryMockRevokeByAccessTokenExpectation{}
|
||||
}
|
||||
|
||||
if mmRevokeByAccessToken.defaultExpectation.params != nil {
|
||||
mmRevokeByAccessToken.mock.t.Fatalf("SessionRepositoryMock.RevokeByAccessToken mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmRevokeByAccessToken.defaultExpectation.paramPtrs == nil {
|
||||
mmRevokeByAccessToken.defaultExpectation.paramPtrs = &SessionRepositoryMockRevokeByAccessTokenParamPtrs{}
|
||||
}
|
||||
mmRevokeByAccessToken.defaultExpectation.paramPtrs.accessToken = &accessToken
|
||||
mmRevokeByAccessToken.defaultExpectation.expectationOrigins.originAccessToken = minimock.CallerInfo(1)
|
||||
|
||||
return mmRevokeByAccessToken
|
||||
}
|
||||
|
||||
// Inspect accepts an inspector function that has same arguments as the SessionRepository.RevokeByAccessToken
|
||||
func (mmRevokeByAccessToken *mSessionRepositoryMockRevokeByAccessToken) Inspect(f func(ctx context.Context, accessToken string)) *mSessionRepositoryMockRevokeByAccessToken {
|
||||
if mmRevokeByAccessToken.mock.inspectFuncRevokeByAccessToken != nil {
|
||||
mmRevokeByAccessToken.mock.t.Fatalf("Inspect function is already set for SessionRepositoryMock.RevokeByAccessToken")
|
||||
}
|
||||
|
||||
mmRevokeByAccessToken.mock.inspectFuncRevokeByAccessToken = f
|
||||
|
||||
return mmRevokeByAccessToken
|
||||
}
|
||||
|
||||
// Return sets up results that will be returned by SessionRepository.RevokeByAccessToken
|
||||
func (mmRevokeByAccessToken *mSessionRepositoryMockRevokeByAccessToken) Return(err error) *SessionRepositoryMock {
|
||||
if mmRevokeByAccessToken.mock.funcRevokeByAccessToken != nil {
|
||||
mmRevokeByAccessToken.mock.t.Fatalf("SessionRepositoryMock.RevokeByAccessToken mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmRevokeByAccessToken.defaultExpectation == nil {
|
||||
mmRevokeByAccessToken.defaultExpectation = &SessionRepositoryMockRevokeByAccessTokenExpectation{mock: mmRevokeByAccessToken.mock}
|
||||
}
|
||||
mmRevokeByAccessToken.defaultExpectation.results = &SessionRepositoryMockRevokeByAccessTokenResults{err}
|
||||
mmRevokeByAccessToken.defaultExpectation.returnOrigin = minimock.CallerInfo(1)
|
||||
return mmRevokeByAccessToken.mock
|
||||
}
|
||||
|
||||
// Set uses given function f to mock the SessionRepository.RevokeByAccessToken method
|
||||
func (mmRevokeByAccessToken *mSessionRepositoryMockRevokeByAccessToken) Set(f func(ctx context.Context, accessToken string) (err error)) *SessionRepositoryMock {
|
||||
if mmRevokeByAccessToken.defaultExpectation != nil {
|
||||
mmRevokeByAccessToken.mock.t.Fatalf("Default expectation is already set for the SessionRepository.RevokeByAccessToken method")
|
||||
}
|
||||
|
||||
if len(mmRevokeByAccessToken.expectations) > 0 {
|
||||
mmRevokeByAccessToken.mock.t.Fatalf("Some expectations are already set for the SessionRepository.RevokeByAccessToken method")
|
||||
}
|
||||
|
||||
mmRevokeByAccessToken.mock.funcRevokeByAccessToken = f
|
||||
mmRevokeByAccessToken.mock.funcRevokeByAccessTokenOrigin = minimock.CallerInfo(1)
|
||||
return mmRevokeByAccessToken.mock
|
||||
}
|
||||
|
||||
// When sets expectation for the SessionRepository.RevokeByAccessToken which will trigger the result defined by the following
|
||||
// Then helper
|
||||
func (mmRevokeByAccessToken *mSessionRepositoryMockRevokeByAccessToken) When(ctx context.Context, accessToken string) *SessionRepositoryMockRevokeByAccessTokenExpectation {
|
||||
if mmRevokeByAccessToken.mock.funcRevokeByAccessToken != nil {
|
||||
mmRevokeByAccessToken.mock.t.Fatalf("SessionRepositoryMock.RevokeByAccessToken mock is already set by Set")
|
||||
}
|
||||
|
||||
expectation := &SessionRepositoryMockRevokeByAccessTokenExpectation{
|
||||
mock: mmRevokeByAccessToken.mock,
|
||||
params: &SessionRepositoryMockRevokeByAccessTokenParams{ctx, accessToken},
|
||||
expectationOrigins: SessionRepositoryMockRevokeByAccessTokenExpectationOrigins{origin: minimock.CallerInfo(1)},
|
||||
}
|
||||
mmRevokeByAccessToken.expectations = append(mmRevokeByAccessToken.expectations, expectation)
|
||||
return expectation
|
||||
}
|
||||
|
||||
// Then sets up SessionRepository.RevokeByAccessToken return parameters for the expectation previously defined by the When method
|
||||
func (e *SessionRepositoryMockRevokeByAccessTokenExpectation) Then(err error) *SessionRepositoryMock {
|
||||
e.results = &SessionRepositoryMockRevokeByAccessTokenResults{err}
|
||||
return e.mock
|
||||
}
|
||||
|
||||
// Times sets number of times SessionRepository.RevokeByAccessToken should be invoked
|
||||
func (mmRevokeByAccessToken *mSessionRepositoryMockRevokeByAccessToken) Times(n uint64) *mSessionRepositoryMockRevokeByAccessToken {
|
||||
if n == 0 {
|
||||
mmRevokeByAccessToken.mock.t.Fatalf("Times of SessionRepositoryMock.RevokeByAccessToken mock can not be zero")
|
||||
}
|
||||
mm_atomic.StoreUint64(&mmRevokeByAccessToken.expectedInvocations, n)
|
||||
mmRevokeByAccessToken.expectedInvocationsOrigin = minimock.CallerInfo(1)
|
||||
return mmRevokeByAccessToken
|
||||
}
|
||||
|
||||
func (mmRevokeByAccessToken *mSessionRepositoryMockRevokeByAccessToken) invocationsDone() bool {
|
||||
if len(mmRevokeByAccessToken.expectations) == 0 && mmRevokeByAccessToken.defaultExpectation == nil && mmRevokeByAccessToken.mock.funcRevokeByAccessToken == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
totalInvocations := mm_atomic.LoadUint64(&mmRevokeByAccessToken.mock.afterRevokeByAccessTokenCounter)
|
||||
expectedInvocations := mm_atomic.LoadUint64(&mmRevokeByAccessToken.expectedInvocations)
|
||||
|
||||
return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
|
||||
}
|
||||
|
||||
// RevokeByAccessToken implements mm_repository.SessionRepository
|
||||
func (mmRevokeByAccessToken *SessionRepositoryMock) RevokeByAccessToken(ctx context.Context, accessToken string) (err error) {
|
||||
mm_atomic.AddUint64(&mmRevokeByAccessToken.beforeRevokeByAccessTokenCounter, 1)
|
||||
defer mm_atomic.AddUint64(&mmRevokeByAccessToken.afterRevokeByAccessTokenCounter, 1)
|
||||
|
||||
mmRevokeByAccessToken.t.Helper()
|
||||
|
||||
if mmRevokeByAccessToken.inspectFuncRevokeByAccessToken != nil {
|
||||
mmRevokeByAccessToken.inspectFuncRevokeByAccessToken(ctx, accessToken)
|
||||
}
|
||||
|
||||
mm_params := SessionRepositoryMockRevokeByAccessTokenParams{ctx, accessToken}
|
||||
|
||||
// Record call args
|
||||
mmRevokeByAccessToken.RevokeByAccessTokenMock.mutex.Lock()
|
||||
mmRevokeByAccessToken.RevokeByAccessTokenMock.callArgs = append(mmRevokeByAccessToken.RevokeByAccessTokenMock.callArgs, &mm_params)
|
||||
mmRevokeByAccessToken.RevokeByAccessTokenMock.mutex.Unlock()
|
||||
|
||||
for _, e := range mmRevokeByAccessToken.RevokeByAccessTokenMock.expectations {
|
||||
if minimock.Equal(*e.params, mm_params) {
|
||||
mm_atomic.AddUint64(&e.Counter, 1)
|
||||
return e.results.err
|
||||
}
|
||||
}
|
||||
|
||||
if mmRevokeByAccessToken.RevokeByAccessTokenMock.defaultExpectation != nil {
|
||||
mm_atomic.AddUint64(&mmRevokeByAccessToken.RevokeByAccessTokenMock.defaultExpectation.Counter, 1)
|
||||
mm_want := mmRevokeByAccessToken.RevokeByAccessTokenMock.defaultExpectation.params
|
||||
mm_want_ptrs := mmRevokeByAccessToken.RevokeByAccessTokenMock.defaultExpectation.paramPtrs
|
||||
|
||||
mm_got := SessionRepositoryMockRevokeByAccessTokenParams{ctx, accessToken}
|
||||
|
||||
if mm_want_ptrs != nil {
|
||||
|
||||
if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) {
|
||||
mmRevokeByAccessToken.t.Errorf("SessionRepositoryMock.RevokeByAccessToken got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmRevokeByAccessToken.RevokeByAccessTokenMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
|
||||
}
|
||||
|
||||
if mm_want_ptrs.accessToken != nil && !minimock.Equal(*mm_want_ptrs.accessToken, mm_got.accessToken) {
|
||||
mmRevokeByAccessToken.t.Errorf("SessionRepositoryMock.RevokeByAccessToken got unexpected parameter accessToken, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmRevokeByAccessToken.RevokeByAccessTokenMock.defaultExpectation.expectationOrigins.originAccessToken, *mm_want_ptrs.accessToken, mm_got.accessToken, minimock.Diff(*mm_want_ptrs.accessToken, mm_got.accessToken))
|
||||
}
|
||||
|
||||
} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
|
||||
mmRevokeByAccessToken.t.Errorf("SessionRepositoryMock.RevokeByAccessToken got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmRevokeByAccessToken.RevokeByAccessTokenMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
|
||||
}
|
||||
|
||||
mm_results := mmRevokeByAccessToken.RevokeByAccessTokenMock.defaultExpectation.results
|
||||
if mm_results == nil {
|
||||
mmRevokeByAccessToken.t.Fatal("No results are set for the SessionRepositoryMock.RevokeByAccessToken")
|
||||
}
|
||||
return (*mm_results).err
|
||||
}
|
||||
if mmRevokeByAccessToken.funcRevokeByAccessToken != nil {
|
||||
return mmRevokeByAccessToken.funcRevokeByAccessToken(ctx, accessToken)
|
||||
}
|
||||
mmRevokeByAccessToken.t.Fatalf("Unexpected call to SessionRepositoryMock.RevokeByAccessToken. %v %v", ctx, accessToken)
|
||||
return
|
||||
}
|
||||
|
||||
// RevokeByAccessTokenAfterCounter returns a count of finished SessionRepositoryMock.RevokeByAccessToken invocations
|
||||
func (mmRevokeByAccessToken *SessionRepositoryMock) RevokeByAccessTokenAfterCounter() uint64 {
|
||||
return mm_atomic.LoadUint64(&mmRevokeByAccessToken.afterRevokeByAccessTokenCounter)
|
||||
}
|
||||
|
||||
// RevokeByAccessTokenBeforeCounter returns a count of SessionRepositoryMock.RevokeByAccessToken invocations
|
||||
func (mmRevokeByAccessToken *SessionRepositoryMock) RevokeByAccessTokenBeforeCounter() uint64 {
|
||||
return mm_atomic.LoadUint64(&mmRevokeByAccessToken.beforeRevokeByAccessTokenCounter)
|
||||
}
|
||||
|
||||
// Calls returns a list of arguments used in each call to SessionRepositoryMock.RevokeByAccessToken.
|
||||
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
|
||||
func (mmRevokeByAccessToken *mSessionRepositoryMockRevokeByAccessToken) Calls() []*SessionRepositoryMockRevokeByAccessTokenParams {
|
||||
mmRevokeByAccessToken.mutex.RLock()
|
||||
|
||||
argCopy := make([]*SessionRepositoryMockRevokeByAccessTokenParams, len(mmRevokeByAccessToken.callArgs))
|
||||
copy(argCopy, mmRevokeByAccessToken.callArgs)
|
||||
|
||||
mmRevokeByAccessToken.mutex.RUnlock()
|
||||
|
||||
return argCopy
|
||||
}
|
||||
|
||||
// MinimockRevokeByAccessTokenDone returns true if the count of the RevokeByAccessToken invocations corresponds
|
||||
// the number of defined expectations
|
||||
func (m *SessionRepositoryMock) MinimockRevokeByAccessTokenDone() bool {
|
||||
if m.RevokeByAccessTokenMock.optional {
|
||||
// Optional methods provide '0 or more' call count restriction.
|
||||
return true
|
||||
}
|
||||
|
||||
for _, e := range m.RevokeByAccessTokenMock.expectations {
|
||||
if mm_atomic.LoadUint64(&e.Counter) < 1 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return m.RevokeByAccessTokenMock.invocationsDone()
|
||||
}
|
||||
|
||||
// MinimockRevokeByAccessTokenInspect logs each unmet expectation
|
||||
func (m *SessionRepositoryMock) MinimockRevokeByAccessTokenInspect() {
|
||||
for _, e := range m.RevokeByAccessTokenMock.expectations {
|
||||
if mm_atomic.LoadUint64(&e.Counter) < 1 {
|
||||
m.t.Errorf("Expected call to SessionRepositoryMock.RevokeByAccessToken at\n%s with params: %#v", e.expectationOrigins.origin, *e.params)
|
||||
}
|
||||
}
|
||||
|
||||
afterRevokeByAccessTokenCounter := mm_atomic.LoadUint64(&m.afterRevokeByAccessTokenCounter)
|
||||
// if default expectation was set then invocations count should be greater than zero
|
||||
if m.RevokeByAccessTokenMock.defaultExpectation != nil && afterRevokeByAccessTokenCounter < 1 {
|
||||
if m.RevokeByAccessTokenMock.defaultExpectation.params == nil {
|
||||
m.t.Errorf("Expected call to SessionRepositoryMock.RevokeByAccessToken at\n%s", m.RevokeByAccessTokenMock.defaultExpectation.returnOrigin)
|
||||
} else {
|
||||
m.t.Errorf("Expected call to SessionRepositoryMock.RevokeByAccessToken at\n%s with params: %#v", m.RevokeByAccessTokenMock.defaultExpectation.expectationOrigins.origin, *m.RevokeByAccessTokenMock.defaultExpectation.params)
|
||||
}
|
||||
}
|
||||
// if func was set then invocations count should be greater than zero
|
||||
if m.funcRevokeByAccessToken != nil && afterRevokeByAccessTokenCounter < 1 {
|
||||
m.t.Errorf("Expected call to SessionRepositoryMock.RevokeByAccessToken at\n%s", m.funcRevokeByAccessTokenOrigin)
|
||||
}
|
||||
|
||||
if !m.RevokeByAccessTokenMock.invocationsDone() && afterRevokeByAccessTokenCounter > 0 {
|
||||
m.t.Errorf("Expected %d calls to SessionRepositoryMock.RevokeByAccessToken at\n%s but found %d calls",
|
||||
mm_atomic.LoadUint64(&m.RevokeByAccessTokenMock.expectedInvocations), m.RevokeByAccessTokenMock.expectedInvocationsOrigin, afterRevokeByAccessTokenCounter)
|
||||
}
|
||||
}
|
||||
|
||||
type mSessionRepositoryMockUpdateAccessToken struct {
|
||||
optional bool
|
||||
mock *SessionRepositoryMock
|
||||
@@ -1805,8 +2510,12 @@ func (m *SessionRepositoryMock) MinimockFinish() {
|
||||
|
||||
m.MinimockFindByRefreshTokenInspect()
|
||||
|
||||
m.MinimockIsAccessTokenValidInspect()
|
||||
|
||||
m.MinimockRevokeInspect()
|
||||
|
||||
m.MinimockRevokeByAccessTokenInspect()
|
||||
|
||||
m.MinimockUpdateAccessTokenInspect()
|
||||
}
|
||||
})
|
||||
@@ -1834,6 +2543,8 @@ func (m *SessionRepositoryMock) minimockDone() bool {
|
||||
m.MinimockCreateDone() &&
|
||||
m.MinimockDeleteExpiredDone() &&
|
||||
m.MinimockFindByRefreshTokenDone() &&
|
||||
m.MinimockIsAccessTokenValidDone() &&
|
||||
m.MinimockRevokeDone() &&
|
||||
m.MinimockRevokeByAccessTokenDone() &&
|
||||
m.MinimockUpdateAccessTokenDone()
|
||||
}
|
||||
|
||||
@@ -2,17 +2,18 @@
|
||||
|
||||
package mocks
|
||||
|
||||
//go:generate minimock -i smart-search-back/internal/repository.SupplierRepository -o supplier_repository_mock.go -n SupplierRepositoryMock -p mocks
|
||||
//go:generate minimock -i git.techease.ru/Smart-search/smart-search-back/internal/repository.SupplierRepository -o supplier_repository_mock.go -n SupplierRepositoryMock -p mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"smart-search-back/internal/model"
|
||||
"sync"
|
||||
mm_atomic "sync/atomic"
|
||||
mm_time "time"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
"github.com/gojuno/minimock/v3"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
// SupplierRepositoryMock implements mm_repository.SupplierRepository
|
||||
@@ -27,6 +28,13 @@ type SupplierRepositoryMock struct {
|
||||
beforeBulkInsertCounter uint64
|
||||
BulkInsertMock mSupplierRepositoryMockBulkInsert
|
||||
|
||||
funcBulkInsertTx func(ctx context.Context, tx pgx.Tx, requestID uuid.UUID, suppliers []*model.Supplier) (err error)
|
||||
funcBulkInsertTxOrigin string
|
||||
inspectFuncBulkInsertTx func(ctx context.Context, tx pgx.Tx, requestID uuid.UUID, suppliers []*model.Supplier)
|
||||
afterBulkInsertTxCounter uint64
|
||||
beforeBulkInsertTxCounter uint64
|
||||
BulkInsertTxMock mSupplierRepositoryMockBulkInsertTx
|
||||
|
||||
funcDeleteByRequestID func(ctx context.Context, requestID uuid.UUID) (err error)
|
||||
funcDeleteByRequestIDOrigin string
|
||||
inspectFuncDeleteByRequestID func(ctx context.Context, requestID uuid.UUID)
|
||||
@@ -53,6 +61,9 @@ func NewSupplierRepositoryMock(t minimock.Tester) *SupplierRepositoryMock {
|
||||
m.BulkInsertMock = mSupplierRepositoryMockBulkInsert{mock: m}
|
||||
m.BulkInsertMock.callArgs = []*SupplierRepositoryMockBulkInsertParams{}
|
||||
|
||||
m.BulkInsertTxMock = mSupplierRepositoryMockBulkInsertTx{mock: m}
|
||||
m.BulkInsertTxMock.callArgs = []*SupplierRepositoryMockBulkInsertTxParams{}
|
||||
|
||||
m.DeleteByRequestIDMock = mSupplierRepositoryMockDeleteByRequestID{mock: m}
|
||||
m.DeleteByRequestIDMock.callArgs = []*SupplierRepositoryMockDeleteByRequestIDParams{}
|
||||
|
||||
@@ -437,6 +448,410 @@ func (m *SupplierRepositoryMock) MinimockBulkInsertInspect() {
|
||||
}
|
||||
}
|
||||
|
||||
type mSupplierRepositoryMockBulkInsertTx struct {
|
||||
optional bool
|
||||
mock *SupplierRepositoryMock
|
||||
defaultExpectation *SupplierRepositoryMockBulkInsertTxExpectation
|
||||
expectations []*SupplierRepositoryMockBulkInsertTxExpectation
|
||||
|
||||
callArgs []*SupplierRepositoryMockBulkInsertTxParams
|
||||
mutex sync.RWMutex
|
||||
|
||||
expectedInvocations uint64
|
||||
expectedInvocationsOrigin string
|
||||
}
|
||||
|
||||
// SupplierRepositoryMockBulkInsertTxExpectation specifies expectation struct of the SupplierRepository.BulkInsertTx
|
||||
type SupplierRepositoryMockBulkInsertTxExpectation struct {
|
||||
mock *SupplierRepositoryMock
|
||||
params *SupplierRepositoryMockBulkInsertTxParams
|
||||
paramPtrs *SupplierRepositoryMockBulkInsertTxParamPtrs
|
||||
expectationOrigins SupplierRepositoryMockBulkInsertTxExpectationOrigins
|
||||
results *SupplierRepositoryMockBulkInsertTxResults
|
||||
returnOrigin string
|
||||
Counter uint64
|
||||
}
|
||||
|
||||
// SupplierRepositoryMockBulkInsertTxParams contains parameters of the SupplierRepository.BulkInsertTx
|
||||
type SupplierRepositoryMockBulkInsertTxParams struct {
|
||||
ctx context.Context
|
||||
tx pgx.Tx
|
||||
requestID uuid.UUID
|
||||
suppliers []*model.Supplier
|
||||
}
|
||||
|
||||
// SupplierRepositoryMockBulkInsertTxParamPtrs contains pointers to parameters of the SupplierRepository.BulkInsertTx
|
||||
type SupplierRepositoryMockBulkInsertTxParamPtrs struct {
|
||||
ctx *context.Context
|
||||
tx *pgx.Tx
|
||||
requestID *uuid.UUID
|
||||
suppliers *[]*model.Supplier
|
||||
}
|
||||
|
||||
// SupplierRepositoryMockBulkInsertTxResults contains results of the SupplierRepository.BulkInsertTx
|
||||
type SupplierRepositoryMockBulkInsertTxResults struct {
|
||||
err error
|
||||
}
|
||||
|
||||
// SupplierRepositoryMockBulkInsertTxOrigins contains origins of expectations of the SupplierRepository.BulkInsertTx
|
||||
type SupplierRepositoryMockBulkInsertTxExpectationOrigins struct {
|
||||
origin string
|
||||
originCtx string
|
||||
originTx string
|
||||
originRequestID string
|
||||
originSuppliers string
|
||||
}
|
||||
|
||||
// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning
|
||||
// the test will fail minimock's automatic final call check if the mocked method was not called at least once.
|
||||
// Optional() makes method check to work in '0 or more' mode.
|
||||
// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to
|
||||
// catch the problems when the expected method call is totally skipped during test run.
|
||||
func (mmBulkInsertTx *mSupplierRepositoryMockBulkInsertTx) Optional() *mSupplierRepositoryMockBulkInsertTx {
|
||||
mmBulkInsertTx.optional = true
|
||||
return mmBulkInsertTx
|
||||
}
|
||||
|
||||
// Expect sets up expected params for SupplierRepository.BulkInsertTx
|
||||
func (mmBulkInsertTx *mSupplierRepositoryMockBulkInsertTx) Expect(ctx context.Context, tx pgx.Tx, requestID uuid.UUID, suppliers []*model.Supplier) *mSupplierRepositoryMockBulkInsertTx {
|
||||
if mmBulkInsertTx.mock.funcBulkInsertTx != nil {
|
||||
mmBulkInsertTx.mock.t.Fatalf("SupplierRepositoryMock.BulkInsertTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmBulkInsertTx.defaultExpectation == nil {
|
||||
mmBulkInsertTx.defaultExpectation = &SupplierRepositoryMockBulkInsertTxExpectation{}
|
||||
}
|
||||
|
||||
if mmBulkInsertTx.defaultExpectation.paramPtrs != nil {
|
||||
mmBulkInsertTx.mock.t.Fatalf("SupplierRepositoryMock.BulkInsertTx mock is already set by ExpectParams functions")
|
||||
}
|
||||
|
||||
mmBulkInsertTx.defaultExpectation.params = &SupplierRepositoryMockBulkInsertTxParams{ctx, tx, requestID, suppliers}
|
||||
mmBulkInsertTx.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1)
|
||||
for _, e := range mmBulkInsertTx.expectations {
|
||||
if minimock.Equal(e.params, mmBulkInsertTx.defaultExpectation.params) {
|
||||
mmBulkInsertTx.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmBulkInsertTx.defaultExpectation.params)
|
||||
}
|
||||
}
|
||||
|
||||
return mmBulkInsertTx
|
||||
}
|
||||
|
||||
// ExpectCtxParam1 sets up expected param ctx for SupplierRepository.BulkInsertTx
|
||||
func (mmBulkInsertTx *mSupplierRepositoryMockBulkInsertTx) ExpectCtxParam1(ctx context.Context) *mSupplierRepositoryMockBulkInsertTx {
|
||||
if mmBulkInsertTx.mock.funcBulkInsertTx != nil {
|
||||
mmBulkInsertTx.mock.t.Fatalf("SupplierRepositoryMock.BulkInsertTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmBulkInsertTx.defaultExpectation == nil {
|
||||
mmBulkInsertTx.defaultExpectation = &SupplierRepositoryMockBulkInsertTxExpectation{}
|
||||
}
|
||||
|
||||
if mmBulkInsertTx.defaultExpectation.params != nil {
|
||||
mmBulkInsertTx.mock.t.Fatalf("SupplierRepositoryMock.BulkInsertTx mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmBulkInsertTx.defaultExpectation.paramPtrs == nil {
|
||||
mmBulkInsertTx.defaultExpectation.paramPtrs = &SupplierRepositoryMockBulkInsertTxParamPtrs{}
|
||||
}
|
||||
mmBulkInsertTx.defaultExpectation.paramPtrs.ctx = &ctx
|
||||
mmBulkInsertTx.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1)
|
||||
|
||||
return mmBulkInsertTx
|
||||
}
|
||||
|
||||
// ExpectTxParam2 sets up expected param tx for SupplierRepository.BulkInsertTx
|
||||
func (mmBulkInsertTx *mSupplierRepositoryMockBulkInsertTx) ExpectTxParam2(tx pgx.Tx) *mSupplierRepositoryMockBulkInsertTx {
|
||||
if mmBulkInsertTx.mock.funcBulkInsertTx != nil {
|
||||
mmBulkInsertTx.mock.t.Fatalf("SupplierRepositoryMock.BulkInsertTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmBulkInsertTx.defaultExpectation == nil {
|
||||
mmBulkInsertTx.defaultExpectation = &SupplierRepositoryMockBulkInsertTxExpectation{}
|
||||
}
|
||||
|
||||
if mmBulkInsertTx.defaultExpectation.params != nil {
|
||||
mmBulkInsertTx.mock.t.Fatalf("SupplierRepositoryMock.BulkInsertTx mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmBulkInsertTx.defaultExpectation.paramPtrs == nil {
|
||||
mmBulkInsertTx.defaultExpectation.paramPtrs = &SupplierRepositoryMockBulkInsertTxParamPtrs{}
|
||||
}
|
||||
mmBulkInsertTx.defaultExpectation.paramPtrs.tx = &tx
|
||||
mmBulkInsertTx.defaultExpectation.expectationOrigins.originTx = minimock.CallerInfo(1)
|
||||
|
||||
return mmBulkInsertTx
|
||||
}
|
||||
|
||||
// ExpectRequestIDParam3 sets up expected param requestID for SupplierRepository.BulkInsertTx
|
||||
func (mmBulkInsertTx *mSupplierRepositoryMockBulkInsertTx) ExpectRequestIDParam3(requestID uuid.UUID) *mSupplierRepositoryMockBulkInsertTx {
|
||||
if mmBulkInsertTx.mock.funcBulkInsertTx != nil {
|
||||
mmBulkInsertTx.mock.t.Fatalf("SupplierRepositoryMock.BulkInsertTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmBulkInsertTx.defaultExpectation == nil {
|
||||
mmBulkInsertTx.defaultExpectation = &SupplierRepositoryMockBulkInsertTxExpectation{}
|
||||
}
|
||||
|
||||
if mmBulkInsertTx.defaultExpectation.params != nil {
|
||||
mmBulkInsertTx.mock.t.Fatalf("SupplierRepositoryMock.BulkInsertTx mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmBulkInsertTx.defaultExpectation.paramPtrs == nil {
|
||||
mmBulkInsertTx.defaultExpectation.paramPtrs = &SupplierRepositoryMockBulkInsertTxParamPtrs{}
|
||||
}
|
||||
mmBulkInsertTx.defaultExpectation.paramPtrs.requestID = &requestID
|
||||
mmBulkInsertTx.defaultExpectation.expectationOrigins.originRequestID = minimock.CallerInfo(1)
|
||||
|
||||
return mmBulkInsertTx
|
||||
}
|
||||
|
||||
// ExpectSuppliersParam4 sets up expected param suppliers for SupplierRepository.BulkInsertTx
|
||||
func (mmBulkInsertTx *mSupplierRepositoryMockBulkInsertTx) ExpectSuppliersParam4(suppliers []*model.Supplier) *mSupplierRepositoryMockBulkInsertTx {
|
||||
if mmBulkInsertTx.mock.funcBulkInsertTx != nil {
|
||||
mmBulkInsertTx.mock.t.Fatalf("SupplierRepositoryMock.BulkInsertTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmBulkInsertTx.defaultExpectation == nil {
|
||||
mmBulkInsertTx.defaultExpectation = &SupplierRepositoryMockBulkInsertTxExpectation{}
|
||||
}
|
||||
|
||||
if mmBulkInsertTx.defaultExpectation.params != nil {
|
||||
mmBulkInsertTx.mock.t.Fatalf("SupplierRepositoryMock.BulkInsertTx mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmBulkInsertTx.defaultExpectation.paramPtrs == nil {
|
||||
mmBulkInsertTx.defaultExpectation.paramPtrs = &SupplierRepositoryMockBulkInsertTxParamPtrs{}
|
||||
}
|
||||
mmBulkInsertTx.defaultExpectation.paramPtrs.suppliers = &suppliers
|
||||
mmBulkInsertTx.defaultExpectation.expectationOrigins.originSuppliers = minimock.CallerInfo(1)
|
||||
|
||||
return mmBulkInsertTx
|
||||
}
|
||||
|
||||
// Inspect accepts an inspector function that has same arguments as the SupplierRepository.BulkInsertTx
|
||||
func (mmBulkInsertTx *mSupplierRepositoryMockBulkInsertTx) Inspect(f func(ctx context.Context, tx pgx.Tx, requestID uuid.UUID, suppliers []*model.Supplier)) *mSupplierRepositoryMockBulkInsertTx {
|
||||
if mmBulkInsertTx.mock.inspectFuncBulkInsertTx != nil {
|
||||
mmBulkInsertTx.mock.t.Fatalf("Inspect function is already set for SupplierRepositoryMock.BulkInsertTx")
|
||||
}
|
||||
|
||||
mmBulkInsertTx.mock.inspectFuncBulkInsertTx = f
|
||||
|
||||
return mmBulkInsertTx
|
||||
}
|
||||
|
||||
// Return sets up results that will be returned by SupplierRepository.BulkInsertTx
|
||||
func (mmBulkInsertTx *mSupplierRepositoryMockBulkInsertTx) Return(err error) *SupplierRepositoryMock {
|
||||
if mmBulkInsertTx.mock.funcBulkInsertTx != nil {
|
||||
mmBulkInsertTx.mock.t.Fatalf("SupplierRepositoryMock.BulkInsertTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmBulkInsertTx.defaultExpectation == nil {
|
||||
mmBulkInsertTx.defaultExpectation = &SupplierRepositoryMockBulkInsertTxExpectation{mock: mmBulkInsertTx.mock}
|
||||
}
|
||||
mmBulkInsertTx.defaultExpectation.results = &SupplierRepositoryMockBulkInsertTxResults{err}
|
||||
mmBulkInsertTx.defaultExpectation.returnOrigin = minimock.CallerInfo(1)
|
||||
return mmBulkInsertTx.mock
|
||||
}
|
||||
|
||||
// Set uses given function f to mock the SupplierRepository.BulkInsertTx method
|
||||
func (mmBulkInsertTx *mSupplierRepositoryMockBulkInsertTx) Set(f func(ctx context.Context, tx pgx.Tx, requestID uuid.UUID, suppliers []*model.Supplier) (err error)) *SupplierRepositoryMock {
|
||||
if mmBulkInsertTx.defaultExpectation != nil {
|
||||
mmBulkInsertTx.mock.t.Fatalf("Default expectation is already set for the SupplierRepository.BulkInsertTx method")
|
||||
}
|
||||
|
||||
if len(mmBulkInsertTx.expectations) > 0 {
|
||||
mmBulkInsertTx.mock.t.Fatalf("Some expectations are already set for the SupplierRepository.BulkInsertTx method")
|
||||
}
|
||||
|
||||
mmBulkInsertTx.mock.funcBulkInsertTx = f
|
||||
mmBulkInsertTx.mock.funcBulkInsertTxOrigin = minimock.CallerInfo(1)
|
||||
return mmBulkInsertTx.mock
|
||||
}
|
||||
|
||||
// When sets expectation for the SupplierRepository.BulkInsertTx which will trigger the result defined by the following
|
||||
// Then helper
|
||||
func (mmBulkInsertTx *mSupplierRepositoryMockBulkInsertTx) When(ctx context.Context, tx pgx.Tx, requestID uuid.UUID, suppliers []*model.Supplier) *SupplierRepositoryMockBulkInsertTxExpectation {
|
||||
if mmBulkInsertTx.mock.funcBulkInsertTx != nil {
|
||||
mmBulkInsertTx.mock.t.Fatalf("SupplierRepositoryMock.BulkInsertTx mock is already set by Set")
|
||||
}
|
||||
|
||||
expectation := &SupplierRepositoryMockBulkInsertTxExpectation{
|
||||
mock: mmBulkInsertTx.mock,
|
||||
params: &SupplierRepositoryMockBulkInsertTxParams{ctx, tx, requestID, suppliers},
|
||||
expectationOrigins: SupplierRepositoryMockBulkInsertTxExpectationOrigins{origin: minimock.CallerInfo(1)},
|
||||
}
|
||||
mmBulkInsertTx.expectations = append(mmBulkInsertTx.expectations, expectation)
|
||||
return expectation
|
||||
}
|
||||
|
||||
// Then sets up SupplierRepository.BulkInsertTx return parameters for the expectation previously defined by the When method
|
||||
func (e *SupplierRepositoryMockBulkInsertTxExpectation) Then(err error) *SupplierRepositoryMock {
|
||||
e.results = &SupplierRepositoryMockBulkInsertTxResults{err}
|
||||
return e.mock
|
||||
}
|
||||
|
||||
// Times sets number of times SupplierRepository.BulkInsertTx should be invoked
|
||||
func (mmBulkInsertTx *mSupplierRepositoryMockBulkInsertTx) Times(n uint64) *mSupplierRepositoryMockBulkInsertTx {
|
||||
if n == 0 {
|
||||
mmBulkInsertTx.mock.t.Fatalf("Times of SupplierRepositoryMock.BulkInsertTx mock can not be zero")
|
||||
}
|
||||
mm_atomic.StoreUint64(&mmBulkInsertTx.expectedInvocations, n)
|
||||
mmBulkInsertTx.expectedInvocationsOrigin = minimock.CallerInfo(1)
|
||||
return mmBulkInsertTx
|
||||
}
|
||||
|
||||
func (mmBulkInsertTx *mSupplierRepositoryMockBulkInsertTx) invocationsDone() bool {
|
||||
if len(mmBulkInsertTx.expectations) == 0 && mmBulkInsertTx.defaultExpectation == nil && mmBulkInsertTx.mock.funcBulkInsertTx == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
totalInvocations := mm_atomic.LoadUint64(&mmBulkInsertTx.mock.afterBulkInsertTxCounter)
|
||||
expectedInvocations := mm_atomic.LoadUint64(&mmBulkInsertTx.expectedInvocations)
|
||||
|
||||
return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
|
||||
}
|
||||
|
||||
// BulkInsertTx implements mm_repository.SupplierRepository
|
||||
func (mmBulkInsertTx *SupplierRepositoryMock) BulkInsertTx(ctx context.Context, tx pgx.Tx, requestID uuid.UUID, suppliers []*model.Supplier) (err error) {
|
||||
mm_atomic.AddUint64(&mmBulkInsertTx.beforeBulkInsertTxCounter, 1)
|
||||
defer mm_atomic.AddUint64(&mmBulkInsertTx.afterBulkInsertTxCounter, 1)
|
||||
|
||||
mmBulkInsertTx.t.Helper()
|
||||
|
||||
if mmBulkInsertTx.inspectFuncBulkInsertTx != nil {
|
||||
mmBulkInsertTx.inspectFuncBulkInsertTx(ctx, tx, requestID, suppliers)
|
||||
}
|
||||
|
||||
mm_params := SupplierRepositoryMockBulkInsertTxParams{ctx, tx, requestID, suppliers}
|
||||
|
||||
// Record call args
|
||||
mmBulkInsertTx.BulkInsertTxMock.mutex.Lock()
|
||||
mmBulkInsertTx.BulkInsertTxMock.callArgs = append(mmBulkInsertTx.BulkInsertTxMock.callArgs, &mm_params)
|
||||
mmBulkInsertTx.BulkInsertTxMock.mutex.Unlock()
|
||||
|
||||
for _, e := range mmBulkInsertTx.BulkInsertTxMock.expectations {
|
||||
if minimock.Equal(*e.params, mm_params) {
|
||||
mm_atomic.AddUint64(&e.Counter, 1)
|
||||
return e.results.err
|
||||
}
|
||||
}
|
||||
|
||||
if mmBulkInsertTx.BulkInsertTxMock.defaultExpectation != nil {
|
||||
mm_atomic.AddUint64(&mmBulkInsertTx.BulkInsertTxMock.defaultExpectation.Counter, 1)
|
||||
mm_want := mmBulkInsertTx.BulkInsertTxMock.defaultExpectation.params
|
||||
mm_want_ptrs := mmBulkInsertTx.BulkInsertTxMock.defaultExpectation.paramPtrs
|
||||
|
||||
mm_got := SupplierRepositoryMockBulkInsertTxParams{ctx, tx, requestID, suppliers}
|
||||
|
||||
if mm_want_ptrs != nil {
|
||||
|
||||
if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) {
|
||||
mmBulkInsertTx.t.Errorf("SupplierRepositoryMock.BulkInsertTx got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmBulkInsertTx.BulkInsertTxMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
|
||||
}
|
||||
|
||||
if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
|
||||
mmBulkInsertTx.t.Errorf("SupplierRepositoryMock.BulkInsertTx got unexpected parameter tx, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmBulkInsertTx.BulkInsertTxMock.defaultExpectation.expectationOrigins.originTx, *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
|
||||
}
|
||||
|
||||
if mm_want_ptrs.requestID != nil && !minimock.Equal(*mm_want_ptrs.requestID, mm_got.requestID) {
|
||||
mmBulkInsertTx.t.Errorf("SupplierRepositoryMock.BulkInsertTx got unexpected parameter requestID, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmBulkInsertTx.BulkInsertTxMock.defaultExpectation.expectationOrigins.originRequestID, *mm_want_ptrs.requestID, mm_got.requestID, minimock.Diff(*mm_want_ptrs.requestID, mm_got.requestID))
|
||||
}
|
||||
|
||||
if mm_want_ptrs.suppliers != nil && !minimock.Equal(*mm_want_ptrs.suppliers, mm_got.suppliers) {
|
||||
mmBulkInsertTx.t.Errorf("SupplierRepositoryMock.BulkInsertTx got unexpected parameter suppliers, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmBulkInsertTx.BulkInsertTxMock.defaultExpectation.expectationOrigins.originSuppliers, *mm_want_ptrs.suppliers, mm_got.suppliers, minimock.Diff(*mm_want_ptrs.suppliers, mm_got.suppliers))
|
||||
}
|
||||
|
||||
} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
|
||||
mmBulkInsertTx.t.Errorf("SupplierRepositoryMock.BulkInsertTx got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmBulkInsertTx.BulkInsertTxMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
|
||||
}
|
||||
|
||||
mm_results := mmBulkInsertTx.BulkInsertTxMock.defaultExpectation.results
|
||||
if mm_results == nil {
|
||||
mmBulkInsertTx.t.Fatal("No results are set for the SupplierRepositoryMock.BulkInsertTx")
|
||||
}
|
||||
return (*mm_results).err
|
||||
}
|
||||
if mmBulkInsertTx.funcBulkInsertTx != nil {
|
||||
return mmBulkInsertTx.funcBulkInsertTx(ctx, tx, requestID, suppliers)
|
||||
}
|
||||
mmBulkInsertTx.t.Fatalf("Unexpected call to SupplierRepositoryMock.BulkInsertTx. %v %v %v %v", ctx, tx, requestID, suppliers)
|
||||
return
|
||||
}
|
||||
|
||||
// BulkInsertTxAfterCounter returns a count of finished SupplierRepositoryMock.BulkInsertTx invocations
|
||||
func (mmBulkInsertTx *SupplierRepositoryMock) BulkInsertTxAfterCounter() uint64 {
|
||||
return mm_atomic.LoadUint64(&mmBulkInsertTx.afterBulkInsertTxCounter)
|
||||
}
|
||||
|
||||
// BulkInsertTxBeforeCounter returns a count of SupplierRepositoryMock.BulkInsertTx invocations
|
||||
func (mmBulkInsertTx *SupplierRepositoryMock) BulkInsertTxBeforeCounter() uint64 {
|
||||
return mm_atomic.LoadUint64(&mmBulkInsertTx.beforeBulkInsertTxCounter)
|
||||
}
|
||||
|
||||
// Calls returns a list of arguments used in each call to SupplierRepositoryMock.BulkInsertTx.
|
||||
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
|
||||
func (mmBulkInsertTx *mSupplierRepositoryMockBulkInsertTx) Calls() []*SupplierRepositoryMockBulkInsertTxParams {
|
||||
mmBulkInsertTx.mutex.RLock()
|
||||
|
||||
argCopy := make([]*SupplierRepositoryMockBulkInsertTxParams, len(mmBulkInsertTx.callArgs))
|
||||
copy(argCopy, mmBulkInsertTx.callArgs)
|
||||
|
||||
mmBulkInsertTx.mutex.RUnlock()
|
||||
|
||||
return argCopy
|
||||
}
|
||||
|
||||
// MinimockBulkInsertTxDone returns true if the count of the BulkInsertTx invocations corresponds
|
||||
// the number of defined expectations
|
||||
func (m *SupplierRepositoryMock) MinimockBulkInsertTxDone() bool {
|
||||
if m.BulkInsertTxMock.optional {
|
||||
// Optional methods provide '0 or more' call count restriction.
|
||||
return true
|
||||
}
|
||||
|
||||
for _, e := range m.BulkInsertTxMock.expectations {
|
||||
if mm_atomic.LoadUint64(&e.Counter) < 1 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return m.BulkInsertTxMock.invocationsDone()
|
||||
}
|
||||
|
||||
// MinimockBulkInsertTxInspect logs each unmet expectation
|
||||
func (m *SupplierRepositoryMock) MinimockBulkInsertTxInspect() {
|
||||
for _, e := range m.BulkInsertTxMock.expectations {
|
||||
if mm_atomic.LoadUint64(&e.Counter) < 1 {
|
||||
m.t.Errorf("Expected call to SupplierRepositoryMock.BulkInsertTx at\n%s with params: %#v", e.expectationOrigins.origin, *e.params)
|
||||
}
|
||||
}
|
||||
|
||||
afterBulkInsertTxCounter := mm_atomic.LoadUint64(&m.afterBulkInsertTxCounter)
|
||||
// if default expectation was set then invocations count should be greater than zero
|
||||
if m.BulkInsertTxMock.defaultExpectation != nil && afterBulkInsertTxCounter < 1 {
|
||||
if m.BulkInsertTxMock.defaultExpectation.params == nil {
|
||||
m.t.Errorf("Expected call to SupplierRepositoryMock.BulkInsertTx at\n%s", m.BulkInsertTxMock.defaultExpectation.returnOrigin)
|
||||
} else {
|
||||
m.t.Errorf("Expected call to SupplierRepositoryMock.BulkInsertTx at\n%s with params: %#v", m.BulkInsertTxMock.defaultExpectation.expectationOrigins.origin, *m.BulkInsertTxMock.defaultExpectation.params)
|
||||
}
|
||||
}
|
||||
// if func was set then invocations count should be greater than zero
|
||||
if m.funcBulkInsertTx != nil && afterBulkInsertTxCounter < 1 {
|
||||
m.t.Errorf("Expected call to SupplierRepositoryMock.BulkInsertTx at\n%s", m.funcBulkInsertTxOrigin)
|
||||
}
|
||||
|
||||
if !m.BulkInsertTxMock.invocationsDone() && afterBulkInsertTxCounter > 0 {
|
||||
m.t.Errorf("Expected %d calls to SupplierRepositoryMock.BulkInsertTx at\n%s but found %d calls",
|
||||
mm_atomic.LoadUint64(&m.BulkInsertTxMock.expectedInvocations), m.BulkInsertTxMock.expectedInvocationsOrigin, afterBulkInsertTxCounter)
|
||||
}
|
||||
}
|
||||
|
||||
type mSupplierRepositoryMockDeleteByRequestID struct {
|
||||
optional bool
|
||||
mock *SupplierRepositoryMock
|
||||
@@ -1128,6 +1543,8 @@ func (m *SupplierRepositoryMock) MinimockFinish() {
|
||||
if !m.minimockDone() {
|
||||
m.MinimockBulkInsertInspect()
|
||||
|
||||
m.MinimockBulkInsertTxInspect()
|
||||
|
||||
m.MinimockDeleteByRequestIDInspect()
|
||||
|
||||
m.MinimockGetByRequestIDInspect()
|
||||
@@ -1155,6 +1572,7 @@ func (m *SupplierRepositoryMock) minimockDone() bool {
|
||||
done := true
|
||||
return done &&
|
||||
m.MinimockBulkInsertDone() &&
|
||||
m.MinimockBulkInsertTxDone() &&
|
||||
m.MinimockDeleteByRequestIDDone() &&
|
||||
m.MinimockGetByRequestIDDone()
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
package mocks
|
||||
|
||||
//go:generate minimock -i smart-search-back/internal/service.SupplierService -o supplier_service_mock.go -n SupplierServiceMock -p mocks
|
||||
//go:generate minimock -i git.techease.ru/Smart-search/smart-search-back/internal/service.SupplierService -o supplier_service_mock.go -n SupplierServiceMock -p mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
@@ -2,16 +2,17 @@
|
||||
|
||||
package mocks
|
||||
|
||||
//go:generate minimock -i smart-search-back/internal/repository.TokenUsageRepository -o token_usage_repository_mock.go -n TokenUsageRepositoryMock -p mocks
|
||||
//go:generate minimock -i git.techease.ru/Smart-search/smart-search-back/internal/repository.TokenUsageRepository -o token_usage_repository_mock.go -n TokenUsageRepositoryMock -p mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"smart-search-back/internal/model"
|
||||
"sync"
|
||||
mm_atomic "sync/atomic"
|
||||
mm_time "time"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
"github.com/gojuno/minimock/v3"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
// TokenUsageRepositoryMock implements mm_repository.TokenUsageRepository
|
||||
@@ -25,6 +26,13 @@ type TokenUsageRepositoryMock struct {
|
||||
afterCreateCounter uint64
|
||||
beforeCreateCounter uint64
|
||||
CreateMock mTokenUsageRepositoryMockCreate
|
||||
|
||||
funcCreateTx func(ctx context.Context, tx pgx.Tx, usage *model.TokenUsage) (err error)
|
||||
funcCreateTxOrigin string
|
||||
inspectFuncCreateTx func(ctx context.Context, tx pgx.Tx, usage *model.TokenUsage)
|
||||
afterCreateTxCounter uint64
|
||||
beforeCreateTxCounter uint64
|
||||
CreateTxMock mTokenUsageRepositoryMockCreateTx
|
||||
}
|
||||
|
||||
// NewTokenUsageRepositoryMock returns a mock for mm_repository.TokenUsageRepository
|
||||
@@ -38,6 +46,9 @@ func NewTokenUsageRepositoryMock(t minimock.Tester) *TokenUsageRepositoryMock {
|
||||
m.CreateMock = mTokenUsageRepositoryMockCreate{mock: m}
|
||||
m.CreateMock.callArgs = []*TokenUsageRepositoryMockCreateParams{}
|
||||
|
||||
m.CreateTxMock = mTokenUsageRepositoryMockCreateTx{mock: m}
|
||||
m.CreateTxMock.callArgs = []*TokenUsageRepositoryMockCreateTxParams{}
|
||||
|
||||
t.Cleanup(m.MinimockFinish)
|
||||
|
||||
return m
|
||||
@@ -385,11 +396,386 @@ func (m *TokenUsageRepositoryMock) MinimockCreateInspect() {
|
||||
}
|
||||
}
|
||||
|
||||
type mTokenUsageRepositoryMockCreateTx struct {
|
||||
optional bool
|
||||
mock *TokenUsageRepositoryMock
|
||||
defaultExpectation *TokenUsageRepositoryMockCreateTxExpectation
|
||||
expectations []*TokenUsageRepositoryMockCreateTxExpectation
|
||||
|
||||
callArgs []*TokenUsageRepositoryMockCreateTxParams
|
||||
mutex sync.RWMutex
|
||||
|
||||
expectedInvocations uint64
|
||||
expectedInvocationsOrigin string
|
||||
}
|
||||
|
||||
// TokenUsageRepositoryMockCreateTxExpectation specifies expectation struct of the TokenUsageRepository.CreateTx
|
||||
type TokenUsageRepositoryMockCreateTxExpectation struct {
|
||||
mock *TokenUsageRepositoryMock
|
||||
params *TokenUsageRepositoryMockCreateTxParams
|
||||
paramPtrs *TokenUsageRepositoryMockCreateTxParamPtrs
|
||||
expectationOrigins TokenUsageRepositoryMockCreateTxExpectationOrigins
|
||||
results *TokenUsageRepositoryMockCreateTxResults
|
||||
returnOrigin string
|
||||
Counter uint64
|
||||
}
|
||||
|
||||
// TokenUsageRepositoryMockCreateTxParams contains parameters of the TokenUsageRepository.CreateTx
|
||||
type TokenUsageRepositoryMockCreateTxParams struct {
|
||||
ctx context.Context
|
||||
tx pgx.Tx
|
||||
usage *model.TokenUsage
|
||||
}
|
||||
|
||||
// TokenUsageRepositoryMockCreateTxParamPtrs contains pointers to parameters of the TokenUsageRepository.CreateTx
|
||||
type TokenUsageRepositoryMockCreateTxParamPtrs struct {
|
||||
ctx *context.Context
|
||||
tx *pgx.Tx
|
||||
usage **model.TokenUsage
|
||||
}
|
||||
|
||||
// TokenUsageRepositoryMockCreateTxResults contains results of the TokenUsageRepository.CreateTx
|
||||
type TokenUsageRepositoryMockCreateTxResults struct {
|
||||
err error
|
||||
}
|
||||
|
||||
// TokenUsageRepositoryMockCreateTxOrigins contains origins of expectations of the TokenUsageRepository.CreateTx
|
||||
type TokenUsageRepositoryMockCreateTxExpectationOrigins struct {
|
||||
origin string
|
||||
originCtx string
|
||||
originTx string
|
||||
originUsage string
|
||||
}
|
||||
|
||||
// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning
|
||||
// the test will fail minimock's automatic final call check if the mocked method was not called at least once.
|
||||
// Optional() makes method check to work in '0 or more' mode.
|
||||
// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to
|
||||
// catch the problems when the expected method call is totally skipped during test run.
|
||||
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) Optional() *mTokenUsageRepositoryMockCreateTx {
|
||||
mmCreateTx.optional = true
|
||||
return mmCreateTx
|
||||
}
|
||||
|
||||
// Expect sets up expected params for TokenUsageRepository.CreateTx
|
||||
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) Expect(ctx context.Context, tx pgx.Tx, usage *model.TokenUsage) *mTokenUsageRepositoryMockCreateTx {
|
||||
if mmCreateTx.mock.funcCreateTx != nil {
|
||||
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation == nil {
|
||||
mmCreateTx.defaultExpectation = &TokenUsageRepositoryMockCreateTxExpectation{}
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation.paramPtrs != nil {
|
||||
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by ExpectParams functions")
|
||||
}
|
||||
|
||||
mmCreateTx.defaultExpectation.params = &TokenUsageRepositoryMockCreateTxParams{ctx, tx, usage}
|
||||
mmCreateTx.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1)
|
||||
for _, e := range mmCreateTx.expectations {
|
||||
if minimock.Equal(e.params, mmCreateTx.defaultExpectation.params) {
|
||||
mmCreateTx.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmCreateTx.defaultExpectation.params)
|
||||
}
|
||||
}
|
||||
|
||||
return mmCreateTx
|
||||
}
|
||||
|
||||
// ExpectCtxParam1 sets up expected param ctx for TokenUsageRepository.CreateTx
|
||||
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) ExpectCtxParam1(ctx context.Context) *mTokenUsageRepositoryMockCreateTx {
|
||||
if mmCreateTx.mock.funcCreateTx != nil {
|
||||
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation == nil {
|
||||
mmCreateTx.defaultExpectation = &TokenUsageRepositoryMockCreateTxExpectation{}
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation.params != nil {
|
||||
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation.paramPtrs == nil {
|
||||
mmCreateTx.defaultExpectation.paramPtrs = &TokenUsageRepositoryMockCreateTxParamPtrs{}
|
||||
}
|
||||
mmCreateTx.defaultExpectation.paramPtrs.ctx = &ctx
|
||||
mmCreateTx.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1)
|
||||
|
||||
return mmCreateTx
|
||||
}
|
||||
|
||||
// ExpectTxParam2 sets up expected param tx for TokenUsageRepository.CreateTx
|
||||
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) ExpectTxParam2(tx pgx.Tx) *mTokenUsageRepositoryMockCreateTx {
|
||||
if mmCreateTx.mock.funcCreateTx != nil {
|
||||
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation == nil {
|
||||
mmCreateTx.defaultExpectation = &TokenUsageRepositoryMockCreateTxExpectation{}
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation.params != nil {
|
||||
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation.paramPtrs == nil {
|
||||
mmCreateTx.defaultExpectation.paramPtrs = &TokenUsageRepositoryMockCreateTxParamPtrs{}
|
||||
}
|
||||
mmCreateTx.defaultExpectation.paramPtrs.tx = &tx
|
||||
mmCreateTx.defaultExpectation.expectationOrigins.originTx = minimock.CallerInfo(1)
|
||||
|
||||
return mmCreateTx
|
||||
}
|
||||
|
||||
// ExpectUsageParam3 sets up expected param usage for TokenUsageRepository.CreateTx
|
||||
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) ExpectUsageParam3(usage *model.TokenUsage) *mTokenUsageRepositoryMockCreateTx {
|
||||
if mmCreateTx.mock.funcCreateTx != nil {
|
||||
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation == nil {
|
||||
mmCreateTx.defaultExpectation = &TokenUsageRepositoryMockCreateTxExpectation{}
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation.params != nil {
|
||||
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Expect")
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation.paramPtrs == nil {
|
||||
mmCreateTx.defaultExpectation.paramPtrs = &TokenUsageRepositoryMockCreateTxParamPtrs{}
|
||||
}
|
||||
mmCreateTx.defaultExpectation.paramPtrs.usage = &usage
|
||||
mmCreateTx.defaultExpectation.expectationOrigins.originUsage = minimock.CallerInfo(1)
|
||||
|
||||
return mmCreateTx
|
||||
}
|
||||
|
||||
// Inspect accepts an inspector function that has same arguments as the TokenUsageRepository.CreateTx
|
||||
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) Inspect(f func(ctx context.Context, tx pgx.Tx, usage *model.TokenUsage)) *mTokenUsageRepositoryMockCreateTx {
|
||||
if mmCreateTx.mock.inspectFuncCreateTx != nil {
|
||||
mmCreateTx.mock.t.Fatalf("Inspect function is already set for TokenUsageRepositoryMock.CreateTx")
|
||||
}
|
||||
|
||||
mmCreateTx.mock.inspectFuncCreateTx = f
|
||||
|
||||
return mmCreateTx
|
||||
}
|
||||
|
||||
// Return sets up results that will be returned by TokenUsageRepository.CreateTx
|
||||
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) Return(err error) *TokenUsageRepositoryMock {
|
||||
if mmCreateTx.mock.funcCreateTx != nil {
|
||||
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Set")
|
||||
}
|
||||
|
||||
if mmCreateTx.defaultExpectation == nil {
|
||||
mmCreateTx.defaultExpectation = &TokenUsageRepositoryMockCreateTxExpectation{mock: mmCreateTx.mock}
|
||||
}
|
||||
mmCreateTx.defaultExpectation.results = &TokenUsageRepositoryMockCreateTxResults{err}
|
||||
mmCreateTx.defaultExpectation.returnOrigin = minimock.CallerInfo(1)
|
||||
return mmCreateTx.mock
|
||||
}
|
||||
|
||||
// Set uses given function f to mock the TokenUsageRepository.CreateTx method
|
||||
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) Set(f func(ctx context.Context, tx pgx.Tx, usage *model.TokenUsage) (err error)) *TokenUsageRepositoryMock {
|
||||
if mmCreateTx.defaultExpectation != nil {
|
||||
mmCreateTx.mock.t.Fatalf("Default expectation is already set for the TokenUsageRepository.CreateTx method")
|
||||
}
|
||||
|
||||
if len(mmCreateTx.expectations) > 0 {
|
||||
mmCreateTx.mock.t.Fatalf("Some expectations are already set for the TokenUsageRepository.CreateTx method")
|
||||
}
|
||||
|
||||
mmCreateTx.mock.funcCreateTx = f
|
||||
mmCreateTx.mock.funcCreateTxOrigin = minimock.CallerInfo(1)
|
||||
return mmCreateTx.mock
|
||||
}
|
||||
|
||||
// When sets expectation for the TokenUsageRepository.CreateTx which will trigger the result defined by the following
|
||||
// Then helper
|
||||
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) When(ctx context.Context, tx pgx.Tx, usage *model.TokenUsage) *TokenUsageRepositoryMockCreateTxExpectation {
|
||||
if mmCreateTx.mock.funcCreateTx != nil {
|
||||
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Set")
|
||||
}
|
||||
|
||||
expectation := &TokenUsageRepositoryMockCreateTxExpectation{
|
||||
mock: mmCreateTx.mock,
|
||||
params: &TokenUsageRepositoryMockCreateTxParams{ctx, tx, usage},
|
||||
expectationOrigins: TokenUsageRepositoryMockCreateTxExpectationOrigins{origin: minimock.CallerInfo(1)},
|
||||
}
|
||||
mmCreateTx.expectations = append(mmCreateTx.expectations, expectation)
|
||||
return expectation
|
||||
}
|
||||
|
||||
// Then sets up TokenUsageRepository.CreateTx return parameters for the expectation previously defined by the When method
|
||||
func (e *TokenUsageRepositoryMockCreateTxExpectation) Then(err error) *TokenUsageRepositoryMock {
|
||||
e.results = &TokenUsageRepositoryMockCreateTxResults{err}
|
||||
return e.mock
|
||||
}
|
||||
|
||||
// Times sets number of times TokenUsageRepository.CreateTx should be invoked
|
||||
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) Times(n uint64) *mTokenUsageRepositoryMockCreateTx {
|
||||
if n == 0 {
|
||||
mmCreateTx.mock.t.Fatalf("Times of TokenUsageRepositoryMock.CreateTx mock can not be zero")
|
||||
}
|
||||
mm_atomic.StoreUint64(&mmCreateTx.expectedInvocations, n)
|
||||
mmCreateTx.expectedInvocationsOrigin = minimock.CallerInfo(1)
|
||||
return mmCreateTx
|
||||
}
|
||||
|
||||
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) invocationsDone() bool {
|
||||
if len(mmCreateTx.expectations) == 0 && mmCreateTx.defaultExpectation == nil && mmCreateTx.mock.funcCreateTx == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
totalInvocations := mm_atomic.LoadUint64(&mmCreateTx.mock.afterCreateTxCounter)
|
||||
expectedInvocations := mm_atomic.LoadUint64(&mmCreateTx.expectedInvocations)
|
||||
|
||||
return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
|
||||
}
|
||||
|
||||
// CreateTx implements mm_repository.TokenUsageRepository
|
||||
func (mmCreateTx *TokenUsageRepositoryMock) CreateTx(ctx context.Context, tx pgx.Tx, usage *model.TokenUsage) (err error) {
|
||||
mm_atomic.AddUint64(&mmCreateTx.beforeCreateTxCounter, 1)
|
||||
defer mm_atomic.AddUint64(&mmCreateTx.afterCreateTxCounter, 1)
|
||||
|
||||
mmCreateTx.t.Helper()
|
||||
|
||||
if mmCreateTx.inspectFuncCreateTx != nil {
|
||||
mmCreateTx.inspectFuncCreateTx(ctx, tx, usage)
|
||||
}
|
||||
|
||||
mm_params := TokenUsageRepositoryMockCreateTxParams{ctx, tx, usage}
|
||||
|
||||
// Record call args
|
||||
mmCreateTx.CreateTxMock.mutex.Lock()
|
||||
mmCreateTx.CreateTxMock.callArgs = append(mmCreateTx.CreateTxMock.callArgs, &mm_params)
|
||||
mmCreateTx.CreateTxMock.mutex.Unlock()
|
||||
|
||||
for _, e := range mmCreateTx.CreateTxMock.expectations {
|
||||
if minimock.Equal(*e.params, mm_params) {
|
||||
mm_atomic.AddUint64(&e.Counter, 1)
|
||||
return e.results.err
|
||||
}
|
||||
}
|
||||
|
||||
if mmCreateTx.CreateTxMock.defaultExpectation != nil {
|
||||
mm_atomic.AddUint64(&mmCreateTx.CreateTxMock.defaultExpectation.Counter, 1)
|
||||
mm_want := mmCreateTx.CreateTxMock.defaultExpectation.params
|
||||
mm_want_ptrs := mmCreateTx.CreateTxMock.defaultExpectation.paramPtrs
|
||||
|
||||
mm_got := TokenUsageRepositoryMockCreateTxParams{ctx, tx, usage}
|
||||
|
||||
if mm_want_ptrs != nil {
|
||||
|
||||
if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) {
|
||||
mmCreateTx.t.Errorf("TokenUsageRepositoryMock.CreateTx got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmCreateTx.CreateTxMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
|
||||
}
|
||||
|
||||
if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
|
||||
mmCreateTx.t.Errorf("TokenUsageRepositoryMock.CreateTx got unexpected parameter tx, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmCreateTx.CreateTxMock.defaultExpectation.expectationOrigins.originTx, *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
|
||||
}
|
||||
|
||||
if mm_want_ptrs.usage != nil && !minimock.Equal(*mm_want_ptrs.usage, mm_got.usage) {
|
||||
mmCreateTx.t.Errorf("TokenUsageRepositoryMock.CreateTx got unexpected parameter usage, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmCreateTx.CreateTxMock.defaultExpectation.expectationOrigins.originUsage, *mm_want_ptrs.usage, mm_got.usage, minimock.Diff(*mm_want_ptrs.usage, mm_got.usage))
|
||||
}
|
||||
|
||||
} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
|
||||
mmCreateTx.t.Errorf("TokenUsageRepositoryMock.CreateTx got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
||||
mmCreateTx.CreateTxMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
|
||||
}
|
||||
|
||||
mm_results := mmCreateTx.CreateTxMock.defaultExpectation.results
|
||||
if mm_results == nil {
|
||||
mmCreateTx.t.Fatal("No results are set for the TokenUsageRepositoryMock.CreateTx")
|
||||
}
|
||||
return (*mm_results).err
|
||||
}
|
||||
if mmCreateTx.funcCreateTx != nil {
|
||||
return mmCreateTx.funcCreateTx(ctx, tx, usage)
|
||||
}
|
||||
mmCreateTx.t.Fatalf("Unexpected call to TokenUsageRepositoryMock.CreateTx. %v %v %v", ctx, tx, usage)
|
||||
return
|
||||
}
|
||||
|
||||
// CreateTxAfterCounter returns a count of finished TokenUsageRepositoryMock.CreateTx invocations
|
||||
func (mmCreateTx *TokenUsageRepositoryMock) CreateTxAfterCounter() uint64 {
|
||||
return mm_atomic.LoadUint64(&mmCreateTx.afterCreateTxCounter)
|
||||
}
|
||||
|
||||
// CreateTxBeforeCounter returns a count of TokenUsageRepositoryMock.CreateTx invocations
|
||||
func (mmCreateTx *TokenUsageRepositoryMock) CreateTxBeforeCounter() uint64 {
|
||||
return mm_atomic.LoadUint64(&mmCreateTx.beforeCreateTxCounter)
|
||||
}
|
||||
|
||||
// Calls returns a list of arguments used in each call to TokenUsageRepositoryMock.CreateTx.
|
||||
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
|
||||
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) Calls() []*TokenUsageRepositoryMockCreateTxParams {
|
||||
mmCreateTx.mutex.RLock()
|
||||
|
||||
argCopy := make([]*TokenUsageRepositoryMockCreateTxParams, len(mmCreateTx.callArgs))
|
||||
copy(argCopy, mmCreateTx.callArgs)
|
||||
|
||||
mmCreateTx.mutex.RUnlock()
|
||||
|
||||
return argCopy
|
||||
}
|
||||
|
||||
// MinimockCreateTxDone returns true if the count of the CreateTx invocations corresponds
|
||||
// the number of defined expectations
|
||||
func (m *TokenUsageRepositoryMock) MinimockCreateTxDone() bool {
|
||||
if m.CreateTxMock.optional {
|
||||
// Optional methods provide '0 or more' call count restriction.
|
||||
return true
|
||||
}
|
||||
|
||||
for _, e := range m.CreateTxMock.expectations {
|
||||
if mm_atomic.LoadUint64(&e.Counter) < 1 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return m.CreateTxMock.invocationsDone()
|
||||
}
|
||||
|
||||
// MinimockCreateTxInspect logs each unmet expectation
|
||||
func (m *TokenUsageRepositoryMock) MinimockCreateTxInspect() {
|
||||
for _, e := range m.CreateTxMock.expectations {
|
||||
if mm_atomic.LoadUint64(&e.Counter) < 1 {
|
||||
m.t.Errorf("Expected call to TokenUsageRepositoryMock.CreateTx at\n%s with params: %#v", e.expectationOrigins.origin, *e.params)
|
||||
}
|
||||
}
|
||||
|
||||
afterCreateTxCounter := mm_atomic.LoadUint64(&m.afterCreateTxCounter)
|
||||
// if default expectation was set then invocations count should be greater than zero
|
||||
if m.CreateTxMock.defaultExpectation != nil && afterCreateTxCounter < 1 {
|
||||
if m.CreateTxMock.defaultExpectation.params == nil {
|
||||
m.t.Errorf("Expected call to TokenUsageRepositoryMock.CreateTx at\n%s", m.CreateTxMock.defaultExpectation.returnOrigin)
|
||||
} else {
|
||||
m.t.Errorf("Expected call to TokenUsageRepositoryMock.CreateTx at\n%s with params: %#v", m.CreateTxMock.defaultExpectation.expectationOrigins.origin, *m.CreateTxMock.defaultExpectation.params)
|
||||
}
|
||||
}
|
||||
// if func was set then invocations count should be greater than zero
|
||||
if m.funcCreateTx != nil && afterCreateTxCounter < 1 {
|
||||
m.t.Errorf("Expected call to TokenUsageRepositoryMock.CreateTx at\n%s", m.funcCreateTxOrigin)
|
||||
}
|
||||
|
||||
if !m.CreateTxMock.invocationsDone() && afterCreateTxCounter > 0 {
|
||||
m.t.Errorf("Expected %d calls to TokenUsageRepositoryMock.CreateTx at\n%s but found %d calls",
|
||||
mm_atomic.LoadUint64(&m.CreateTxMock.expectedInvocations), m.CreateTxMock.expectedInvocationsOrigin, afterCreateTxCounter)
|
||||
}
|
||||
}
|
||||
|
||||
// MinimockFinish checks that all mocked methods have been called the expected number of times
|
||||
func (m *TokenUsageRepositoryMock) MinimockFinish() {
|
||||
m.finishOnce.Do(func() {
|
||||
if !m.minimockDone() {
|
||||
m.MinimockCreateInspect()
|
||||
|
||||
m.MinimockCreateTxInspect()
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -413,5 +799,6 @@ func (m *TokenUsageRepositoryMock) MinimockWait(timeout mm_time.Duration) {
|
||||
func (m *TokenUsageRepositoryMock) minimockDone() bool {
|
||||
done := true
|
||||
return done &&
|
||||
m.MinimockCreateDone()
|
||||
m.MinimockCreateDone() &&
|
||||
m.MinimockCreateTxDone()
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,15 +2,15 @@
|
||||
|
||||
package mocks
|
||||
|
||||
//go:generate minimock -i smart-search-back/internal/service.UserService -o user_service_mock.go -n UserServiceMock -p mocks
|
||||
//go:generate minimock -i git.techease.ru/Smart-search/smart-search-back/internal/service.UserService -o user_service_mock.go -n UserServiceMock -p mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
mm_service "smart-search-back/internal/service"
|
||||
"sync"
|
||||
mm_atomic "sync/atomic"
|
||||
mm_time "time"
|
||||
|
||||
mm_service "git.techease.ru/Smart-search/smart-search-back/internal/service"
|
||||
"github.com/gojuno/minimock/v3"
|
||||
)
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
"github.com/google/uuid"
|
||||
"smart-search-back/internal/model"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
type UserRepository interface {
|
||||
@@ -12,9 +13,12 @@ type UserRepository interface {
|
||||
FindByID(ctx context.Context, userID int) (*model.User, error)
|
||||
Create(ctx context.Context, user *model.User) error
|
||||
UpdateBalance(ctx context.Context, userID int, delta float64) error
|
||||
UpdateBalanceTx(ctx context.Context, tx pgx.Tx, userID int, delta float64) error
|
||||
GetBalance(ctx context.Context, userID int) (float64, error)
|
||||
IncrementInvitesIssued(ctx context.Context, userID int) error
|
||||
IncrementInvitesIssuedTx(ctx context.Context, tx pgx.Tx, userID int) error
|
||||
CheckInviteLimit(ctx context.Context, userID int) (bool, error)
|
||||
CheckInviteLimitTx(ctx context.Context, tx pgx.Tx, userID int) (bool, error)
|
||||
}
|
||||
|
||||
type SessionRepository interface {
|
||||
@@ -22,11 +26,14 @@ type SessionRepository interface {
|
||||
FindByRefreshToken(ctx context.Context, token string) (*model.Session, error)
|
||||
UpdateAccessToken(ctx context.Context, refreshToken, newAccessToken string) error
|
||||
Revoke(ctx context.Context, refreshToken string) error
|
||||
RevokeByAccessToken(ctx context.Context, accessToken string) error
|
||||
IsAccessTokenValid(ctx context.Context, accessToken string) (bool, error)
|
||||
DeleteExpired(ctx context.Context) (int, error)
|
||||
}
|
||||
|
||||
type InviteRepository interface {
|
||||
Create(ctx context.Context, invite *model.InviteCode) error
|
||||
CreateTx(ctx context.Context, tx pgx.Tx, invite *model.InviteCode) error
|
||||
FindByCode(ctx context.Context, code int64) (*model.InviteCode, error)
|
||||
IncrementUsedCount(ctx context.Context, code int64) error
|
||||
DeactivateExpired(ctx context.Context) (int, error)
|
||||
@@ -36,6 +43,7 @@ type InviteRepository interface {
|
||||
type RequestRepository interface {
|
||||
Create(ctx context.Context, req *model.Request) error
|
||||
UpdateWithTZ(ctx context.Context, id uuid.UUID, tz string, generated bool) error
|
||||
UpdateWithTZTx(ctx context.Context, tx pgx.Tx, id uuid.UUID, tz string, generated bool) error
|
||||
UpdateFinalTZ(ctx context.Context, id uuid.UUID, finalTZ string) error
|
||||
GetByUserID(ctx context.Context, userID int) ([]*model.Request, error)
|
||||
GetByID(ctx context.Context, id uuid.UUID) (*model.Request, error)
|
||||
@@ -45,10 +53,12 @@ type RequestRepository interface {
|
||||
|
||||
type SupplierRepository interface {
|
||||
BulkInsert(ctx context.Context, requestID uuid.UUID, suppliers []*model.Supplier) error
|
||||
BulkInsertTx(ctx context.Context, tx pgx.Tx, requestID uuid.UUID, suppliers []*model.Supplier) error
|
||||
GetByRequestID(ctx context.Context, requestID uuid.UUID) ([]*model.Supplier, error)
|
||||
DeleteByRequestID(ctx context.Context, requestID uuid.UUID) error
|
||||
}
|
||||
|
||||
type TokenUsageRepository interface {
|
||||
Create(ctx context.Context, usage *model.TokenUsage) error
|
||||
CreateTx(ctx context.Context, tx pgx.Tx, usage *model.TokenUsage) error
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"smart-search-back/internal/model"
|
||||
errs "smart-search-back/pkg/errors"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
errs "git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
@@ -25,6 +24,14 @@ func NewInviteRepository(pool *pgxpool.Pool) InviteRepository {
|
||||
}
|
||||
|
||||
func (r *inviteRepository) Create(ctx context.Context, invite *model.InviteCode) error {
|
||||
return r.createWithExecutor(ctx, r.pool, invite)
|
||||
}
|
||||
|
||||
func (r *inviteRepository) CreateTx(ctx context.Context, tx pgx.Tx, invite *model.InviteCode) error {
|
||||
return r.createWithExecutor(ctx, tx, invite)
|
||||
}
|
||||
|
||||
func (r *inviteRepository) createWithExecutor(ctx context.Context, exec DBTX, invite *model.InviteCode) error {
|
||||
query := r.qb.Insert("invite_codes").Columns(
|
||||
"user_id", "code", "can_be_used_count", "expires_at",
|
||||
).Values(
|
||||
@@ -36,7 +43,7 @@ func (r *inviteRepository) Create(ctx context.Context, invite *model.InviteCode)
|
||||
return errs.NewInternalError(errs.DatabaseError, "failed to build query", err)
|
||||
}
|
||||
|
||||
err = r.pool.QueryRow(ctx, sqlQuery, args...).Scan(&invite.ID, &invite.CreatedAt)
|
||||
err = exec.QueryRow(ctx, sqlQuery, args...).Scan(&invite.ID, &invite.CreatedAt)
|
||||
if err != nil {
|
||||
return errs.NewInternalError(errs.DatabaseError, "failed to create invite code", err)
|
||||
}
|
||||
|
||||
@@ -5,9 +5,8 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"smart-search-back/internal/model"
|
||||
errs "smart-search-back/pkg/errors"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
errs "git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
@@ -47,6 +46,14 @@ func (r *requestRepository) Create(ctx context.Context, req *model.Request) erro
|
||||
}
|
||||
|
||||
func (r *requestRepository) UpdateWithTZ(ctx context.Context, id uuid.UUID, tz string, generated bool) error {
|
||||
return r.updateWithTZExecutor(ctx, r.pool, id, tz, generated)
|
||||
}
|
||||
|
||||
func (r *requestRepository) UpdateWithTZTx(ctx context.Context, tx pgx.Tx, id uuid.UUID, tz string, generated bool) error {
|
||||
return r.updateWithTZExecutor(ctx, tx, id, tz, generated)
|
||||
}
|
||||
|
||||
func (r *requestRepository) updateWithTZExecutor(ctx context.Context, exec DBTX, id uuid.UUID, tz string, generated bool) error {
|
||||
query := r.qb.Update("requests_for_suppliers").
|
||||
Set("final_tz", tz).
|
||||
Set("generated_tz", generated).
|
||||
@@ -58,7 +65,7 @@ func (r *requestRepository) UpdateWithTZ(ctx context.Context, id uuid.UUID, tz s
|
||||
return errs.NewInternalError(errs.DatabaseError, "failed to build query", err)
|
||||
}
|
||||
|
||||
_, err = r.pool.Exec(ctx, sqlQuery, args...)
|
||||
_, err = exec.Exec(ctx, sqlQuery, args...)
|
||||
if err != nil {
|
||||
return errs.NewInternalError(errs.DatabaseError, "failed to update request", err)
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"smart-search-back/internal/model"
|
||||
errs "smart-search-back/pkg/errors"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
errs "git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/jackc/pgx/v5"
|
||||
@@ -114,6 +114,47 @@ func (r *sessionRepository) Revoke(ctx context.Context, refreshToken string) err
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *sessionRepository) RevokeByAccessToken(ctx context.Context, accessToken string) error {
|
||||
query := r.qb.Update("sessions").
|
||||
Set("revoked_at", time.Now()).
|
||||
Where(sq.Eq{"access_token": accessToken})
|
||||
|
||||
sqlQuery, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return errs.NewInternalError(errs.DatabaseError, "failed to build query", err)
|
||||
}
|
||||
|
||||
_, err = r.pool.Exec(ctx, sqlQuery, args...)
|
||||
if err != nil {
|
||||
return errs.NewInternalError(errs.DatabaseError, "failed to revoke session", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *sessionRepository) IsAccessTokenValid(ctx context.Context, accessToken string) (bool, error) {
|
||||
query := r.qb.Select("COUNT(*)").
|
||||
From("sessions").
|
||||
Where(sq.And{
|
||||
sq.Eq{"access_token": accessToken},
|
||||
sq.Expr("revoked_at IS NULL"),
|
||||
sq.Expr("expires_at > now()"),
|
||||
})
|
||||
|
||||
sqlQuery, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return false, errs.NewInternalError(errs.DatabaseError, "failed to build query", err)
|
||||
}
|
||||
|
||||
var count int
|
||||
err = r.pool.QueryRow(ctx, sqlQuery, args...).Scan(&count)
|
||||
if err != nil {
|
||||
return false, errs.NewInternalError(errs.DatabaseError, "failed to check token validity", err)
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func (r *sessionRepository) DeleteExpired(ctx context.Context) (int, error) {
|
||||
query := r.qb.Delete("sessions").Where(sq.Or{
|
||||
sq.Expr("expires_at < now()"),
|
||||
|
||||
@@ -3,11 +3,11 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
|
||||
"smart-search-back/internal/model"
|
||||
errs "smart-search-back/pkg/errors"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
errs "git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
@@ -24,6 +24,14 @@ func NewSupplierRepository(pool *pgxpool.Pool) SupplierRepository {
|
||||
}
|
||||
|
||||
func (r *supplierRepository) BulkInsert(ctx context.Context, requestID uuid.UUID, suppliers []*model.Supplier) error {
|
||||
return r.bulkInsertWithExecutor(ctx, r.pool, requestID, suppliers)
|
||||
}
|
||||
|
||||
func (r *supplierRepository) BulkInsertTx(ctx context.Context, tx pgx.Tx, requestID uuid.UUID, suppliers []*model.Supplier) error {
|
||||
return r.bulkInsertWithExecutor(ctx, tx, requestID, suppliers)
|
||||
}
|
||||
|
||||
func (r *supplierRepository) bulkInsertWithExecutor(ctx context.Context, exec DBTX, requestID uuid.UUID, suppliers []*model.Supplier) error {
|
||||
if len(suppliers) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -41,7 +49,7 @@ func (r *supplierRepository) BulkInsert(ctx context.Context, requestID uuid.UUID
|
||||
return errs.NewInternalError(errs.DatabaseError, "failed to build query", err)
|
||||
}
|
||||
|
||||
_, err = r.pool.Exec(ctx, sqlQuery, args...)
|
||||
_, err = exec.Exec(ctx, sqlQuery, args...)
|
||||
if err != nil {
|
||||
return errs.NewInternalError(errs.DatabaseError, "failed to bulk insert suppliers", err)
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
|
||||
"smart-search-back/internal/model"
|
||||
errs "smart-search-back/pkg/errors"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
errs "git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
@@ -23,6 +23,14 @@ func NewTokenUsageRepository(pool *pgxpool.Pool) TokenUsageRepository {
|
||||
}
|
||||
|
||||
func (r *tokenUsageRepository) Create(ctx context.Context, usage *model.TokenUsage) error {
|
||||
return r.createWithExecutor(ctx, r.pool, usage)
|
||||
}
|
||||
|
||||
func (r *tokenUsageRepository) CreateTx(ctx context.Context, tx pgx.Tx, usage *model.TokenUsage) error {
|
||||
return r.createWithExecutor(ctx, tx, usage)
|
||||
}
|
||||
|
||||
func (r *tokenUsageRepository) createWithExecutor(ctx context.Context, exec DBTX, usage *model.TokenUsage) error {
|
||||
query := r.qb.Insert("request_token_usage").Columns(
|
||||
"request_id", "request_token_count", "response_token_count", "token_cost", "type",
|
||||
).Values(
|
||||
@@ -34,7 +42,7 @@ func (r *tokenUsageRepository) Create(ctx context.Context, usage *model.TokenUsa
|
||||
return errs.NewInternalError(errs.DatabaseError, "failed to build query", err)
|
||||
}
|
||||
|
||||
err = r.pool.QueryRow(ctx, sqlQuery, args...).Scan(&usage.ID, &usage.CreatedAt)
|
||||
err = exec.QueryRow(ctx, sqlQuery, args...).Scan(&usage.ID, &usage.CreatedAt)
|
||||
if err != nil {
|
||||
return errs.NewInternalError(errs.DatabaseError, "failed to create token usage", err)
|
||||
}
|
||||
|
||||
48
internal/repository/tx.go
Normal file
48
internal/repository/tx.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
|
||||
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
|
||||
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
|
||||
}
|
||||
|
||||
type TxManager struct {
|
||||
pool *pgxpool.Pool
|
||||
}
|
||||
|
||||
func NewTxManager(pool *pgxpool.Pool) *TxManager {
|
||||
return &TxManager{pool: pool}
|
||||
}
|
||||
|
||||
func (tm *TxManager) WithTx(ctx context.Context, fn func(tx pgx.Tx) error) error {
|
||||
tx, err := tm.pool.Begin(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if p := recover(); p != nil {
|
||||
_ = tx.Rollback(ctx)
|
||||
panic(p)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := fn(tx); err != nil {
|
||||
_ = tx.Rollback(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit(ctx)
|
||||
}
|
||||
|
||||
func (tm *TxManager) Pool() *pgxpool.Pool {
|
||||
return tm.pool
|
||||
}
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"smart-search-back/internal/model"
|
||||
"smart-search-back/pkg/crypto"
|
||||
errs "smart-search-back/pkg/errors"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/crypto"
|
||||
errs "git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/jackc/pgx/v5"
|
||||
@@ -123,20 +123,35 @@ func (r *userRepository) Create(ctx context.Context, user *model.User) error {
|
||||
}
|
||||
|
||||
func (r *userRepository) UpdateBalance(ctx context.Context, userID int, delta float64) error {
|
||||
return r.updateBalanceWithExecutor(ctx, r.pool, userID, delta)
|
||||
}
|
||||
|
||||
func (r *userRepository) UpdateBalanceTx(ctx context.Context, tx pgx.Tx, userID int, delta float64) error {
|
||||
return r.updateBalanceWithExecutor(ctx, tx, userID, delta)
|
||||
}
|
||||
|
||||
func (r *userRepository) updateBalanceWithExecutor(ctx context.Context, exec DBTX, userID int, delta float64) error {
|
||||
query := r.qb.Update("users").
|
||||
Set("balance", sq.Expr("balance + ?", delta)).
|
||||
Where(sq.Eq{"id": userID})
|
||||
Where(sq.And{
|
||||
sq.Eq{"id": userID},
|
||||
sq.Expr("balance + ? >= 0", delta),
|
||||
})
|
||||
|
||||
sqlQuery, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return errs.NewInternalError(errs.DatabaseError, "failed to build query", err)
|
||||
}
|
||||
|
||||
_, err = r.pool.Exec(ctx, sqlQuery, args...)
|
||||
result, err := exec.Exec(ctx, sqlQuery, args...)
|
||||
if err != nil {
|
||||
return errs.NewInternalError(errs.DatabaseError, "failed to update balance", err)
|
||||
}
|
||||
|
||||
if result.RowsAffected() == 0 {
|
||||
return errs.NewBusinessError(errs.InsufficientBalance, "insufficient balance")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -161,24 +176,47 @@ func (r *userRepository) GetBalance(ctx context.Context, userID int) (float64, e
|
||||
}
|
||||
|
||||
func (r *userRepository) IncrementInvitesIssued(ctx context.Context, userID int) error {
|
||||
return r.incrementInvitesIssuedWithExecutor(ctx, r.pool, userID)
|
||||
}
|
||||
|
||||
func (r *userRepository) IncrementInvitesIssuedTx(ctx context.Context, tx pgx.Tx, userID int) error {
|
||||
return r.incrementInvitesIssuedWithExecutor(ctx, tx, userID)
|
||||
}
|
||||
|
||||
func (r *userRepository) incrementInvitesIssuedWithExecutor(ctx context.Context, exec DBTX, userID int) error {
|
||||
query := r.qb.Update("users").
|
||||
Set("invites_issued", sq.Expr("invites_issued + 1")).
|
||||
Where(sq.Eq{"id": userID})
|
||||
Where(sq.And{
|
||||
sq.Eq{"id": userID},
|
||||
sq.Expr("invites_issued < invites_limit"),
|
||||
})
|
||||
|
||||
sqlQuery, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return errs.NewInternalError(errs.DatabaseError, "failed to build query", err)
|
||||
}
|
||||
|
||||
_, err = r.pool.Exec(ctx, sqlQuery, args...)
|
||||
result, err := exec.Exec(ctx, sqlQuery, args...)
|
||||
if err != nil {
|
||||
return errs.NewInternalError(errs.DatabaseError, "failed to increment invites issued", err)
|
||||
}
|
||||
|
||||
if result.RowsAffected() == 0 {
|
||||
return errs.NewBusinessError(errs.InviteLimitReached, "invite limit reached")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *userRepository) CheckInviteLimit(ctx context.Context, userID int) (bool, error) {
|
||||
return r.checkInviteLimitWithExecutor(ctx, r.pool, userID)
|
||||
}
|
||||
|
||||
func (r *userRepository) CheckInviteLimitTx(ctx context.Context, tx pgx.Tx, userID int) (bool, error) {
|
||||
return r.checkInviteLimitWithExecutor(ctx, tx, userID)
|
||||
}
|
||||
|
||||
func (r *userRepository) checkInviteLimitWithExecutor(ctx context.Context, exec DBTX, userID int) (bool, error) {
|
||||
query := r.qb.Select("invites_issued", "invites_limit").
|
||||
From("users").
|
||||
Where(sq.Eq{"id": userID}).
|
||||
@@ -190,7 +228,7 @@ func (r *userRepository) CheckInviteLimit(ctx context.Context, userID int) (bool
|
||||
}
|
||||
|
||||
var issued, limit int
|
||||
err = r.pool.QueryRow(ctx, sqlQuery, args...).Scan(&issued, &limit)
|
||||
err = exec.QueryRow(ctx, sqlQuery, args...).Scan(&issued, &limit)
|
||||
if err != nil {
|
||||
return false, errs.NewInternalError(errs.DatabaseError, "failed to check invite limit", err)
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"smart-search-back/internal/model"
|
||||
"smart-search-back/internal/repository"
|
||||
"smart-search-back/pkg/crypto"
|
||||
"smart-search-back/pkg/errors"
|
||||
"smart-search-back/pkg/jwt"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/repository"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/crypto"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/jwt"
|
||||
)
|
||||
|
||||
type authService struct {
|
||||
@@ -99,9 +99,18 @@ func (s *authService) Validate(ctx context.Context, accessToken string) (int, er
|
||||
return 0, errors.NewBusinessError(errors.AuthInvalidToken, "Invalid user ID in token")
|
||||
}
|
||||
|
||||
isValid, err := s.sessionRepo.IsAccessTokenValid(ctx, accessToken)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if !isValid {
|
||||
return 0, errors.NewBusinessError(errors.AuthInvalidToken, "Token has been revoked or expired")
|
||||
}
|
||||
|
||||
return userID, nil
|
||||
}
|
||||
|
||||
func (s *authService) Logout(ctx context.Context, refreshToken string) error {
|
||||
return s.sessionRepo.Revoke(ctx, refreshToken)
|
||||
func (s *authService) Logout(ctx context.Context, accessToken string) error {
|
||||
return s.sessionRepo.RevokeByAccessToken(ctx, accessToken)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package service
|
||||
import (
|
||||
"context"
|
||||
|
||||
"smart-search-back/internal/model"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -12,7 +12,7 @@ type AuthService interface {
|
||||
Login(ctx context.Context, email, password, ip, userAgent string) (accessToken, refreshToken string, err error)
|
||||
Refresh(ctx context.Context, refreshToken string) (string, error)
|
||||
Validate(ctx context.Context, accessToken string) (int, error)
|
||||
Logout(ctx context.Context, refreshToken string) error
|
||||
Logout(ctx context.Context, accessToken string) error
|
||||
}
|
||||
|
||||
type UserService interface {
|
||||
|
||||
@@ -5,33 +5,27 @@ import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"smart-search-back/internal/model"
|
||||
"smart-search-back/internal/repository"
|
||||
"smart-search-back/pkg/errors"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/repository"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
type inviteService struct {
|
||||
inviteRepo repository.InviteRepository
|
||||
userRepo repository.UserRepository
|
||||
txManager *repository.TxManager
|
||||
}
|
||||
|
||||
func NewInviteService(inviteRepo repository.InviteRepository, userRepo repository.UserRepository) InviteService {
|
||||
func NewInviteService(inviteRepo repository.InviteRepository, userRepo repository.UserRepository, txManager *repository.TxManager) InviteService {
|
||||
return &inviteService{
|
||||
inviteRepo: inviteRepo,
|
||||
userRepo: userRepo,
|
||||
txManager: txManager,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *inviteService) Generate(ctx context.Context, userID, maxUses, ttlDays int) (*model.InviteCode, error) {
|
||||
canIssue, err := s.userRepo.CheckInviteLimit(ctx, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !canIssue {
|
||||
return nil, errors.NewBusinessError(errors.InviteLimitReached, "User reached maximum invite codes limit")
|
||||
}
|
||||
|
||||
code := rand.Int63n(90000000) + 10000000
|
||||
|
||||
invite := &model.InviteCode{
|
||||
@@ -41,11 +35,28 @@ func (s *inviteService) Generate(ctx context.Context, userID, maxUses, ttlDays i
|
||||
ExpiresAt: time.Now().Add(time.Duration(ttlDays) * 24 * time.Hour),
|
||||
}
|
||||
|
||||
if err := s.inviteRepo.Create(ctx, invite); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err := s.txManager.WithTx(ctx, func(tx pgx.Tx) error {
|
||||
canIssue, err := s.userRepo.CheckInviteLimitTx(ctx, tx, userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.userRepo.IncrementInvitesIssued(ctx, userID); err != nil {
|
||||
if !canIssue {
|
||||
return errors.NewBusinessError(errors.InviteLimitReached, "User reached maximum invite codes limit")
|
||||
}
|
||||
|
||||
if err := s.inviteRepo.CreateTx(ctx, tx, invite); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.userRepo.IncrementInvitesIssuedTx(ctx, tx, userID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,12 @@ import (
|
||||
"context"
|
||||
"math"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/ai"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/repository"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
"github.com/google/uuid"
|
||||
"smart-search-back/internal/ai"
|
||||
"smart-search-back/internal/model"
|
||||
"smart-search-back/internal/repository"
|
||||
"smart-search-back/pkg/errors"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
type requestService struct {
|
||||
@@ -18,6 +19,7 @@ type requestService struct {
|
||||
userRepo repository.UserRepository
|
||||
openAI *ai.OpenAIClient
|
||||
perplexity *ai.PerplexityClient
|
||||
txManager *repository.TxManager
|
||||
}
|
||||
|
||||
func NewRequestService(
|
||||
@@ -27,6 +29,7 @@ func NewRequestService(
|
||||
userRepo repository.UserRepository,
|
||||
openAI *ai.OpenAIClient,
|
||||
perplexity *ai.PerplexityClient,
|
||||
txManager *repository.TxManager,
|
||||
) RequestService {
|
||||
return &requestService{
|
||||
requestRepo: requestRepo,
|
||||
@@ -35,6 +38,7 @@ func NewRequestService(
|
||||
userRepo: userRepo,
|
||||
openAI: openAI,
|
||||
perplexity: perplexity,
|
||||
txManager: txManager,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,15 +83,23 @@ func (s *requestService) CreateTZ(ctx context.Context, userID int, requestTxt st
|
||||
Type: "tz",
|
||||
}
|
||||
|
||||
if err := s.tokenUsageRepo.Create(ctx, tokenUsage); err != nil {
|
||||
return req.ID, "", err
|
||||
}
|
||||
err = s.txManager.WithTx(ctx, func(tx pgx.Tx) error {
|
||||
if err := s.tokenUsageRepo.CreateTx(ctx, tx, tokenUsage); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.userRepo.UpdateBalance(ctx, userID, -cost); err != nil {
|
||||
return req.ID, "", err
|
||||
}
|
||||
if err := s.userRepo.UpdateBalanceTx(ctx, tx, userID, -cost); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.requestRepo.UpdateWithTZ(ctx, req.ID, tzText, true); err != nil {
|
||||
if err := s.requestRepo.UpdateWithTZTx(ctx, tx, req.ID, tzText, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return req.ID, "", err
|
||||
}
|
||||
|
||||
@@ -118,10 +130,6 @@ func (s *requestService) ApproveTZ(ctx context.Context, requestID uuid.UUID, tzT
|
||||
return nil, errors.NewInternalError(errors.AIAPIError, "no suppliers found", nil)
|
||||
}
|
||||
|
||||
if err := s.supplierRepo.BulkInsert(ctx, requestID, suppliers); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tokenPrice := 25000.0 / 1000000.0
|
||||
totalTokens := promptTokens + responseTokens
|
||||
cost := float64(totalTokens) * tokenPrice
|
||||
@@ -134,11 +142,23 @@ func (s *requestService) ApproveTZ(ctx context.Context, requestID uuid.UUID, tzT
|
||||
Type: "suppliers",
|
||||
}
|
||||
|
||||
if err := s.tokenUsageRepo.Create(ctx, tokenUsage); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = s.txManager.WithTx(ctx, func(tx pgx.Tx) error {
|
||||
if err := s.supplierRepo.BulkInsertTx(ctx, tx, requestID, suppliers); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.userRepo.UpdateBalance(ctx, userID, -cost); err != nil {
|
||||
if err := s.tokenUsageRepo.CreateTx(ctx, tx, tokenUsage); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.userRepo.UpdateBalanceTx(ctx, tx, userID, -cost); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/repository"
|
||||
"github.com/google/uuid"
|
||||
"github.com/xuri/excelize/v2"
|
||||
"smart-search-back/internal/repository"
|
||||
)
|
||||
|
||||
type supplierService struct {
|
||||
@@ -26,7 +26,7 @@ func (s *supplierService) ExportExcel(ctx context.Context, requestID uuid.UUID)
|
||||
}
|
||||
|
||||
f := excelize.NewFile()
|
||||
defer f.Close()
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
sheetName := "Suppliers"
|
||||
index, err := f.NewSheet(sheetName)
|
||||
@@ -37,7 +37,7 @@ func (s *supplierService) ExportExcel(ctx context.Context, requestID uuid.UUID)
|
||||
headers := []string{"Company ID", "Email", "Phone", "Company Name", "URL"}
|
||||
for i, header := range headers {
|
||||
cell := fmt.Sprintf("%c1", 'A'+i)
|
||||
f.SetCellValue(sheetName, cell, header)
|
||||
_ = f.SetCellValue(sheetName, cell, header)
|
||||
}
|
||||
|
||||
style, err := f.NewStyle(&excelize.Style{
|
||||
@@ -45,26 +45,26 @@ func (s *supplierService) ExportExcel(ctx context.Context, requestID uuid.UUID)
|
||||
Fill: excelize.Fill{Type: "pattern", Color: []string{"#E0E0E0"}, Pattern: 1},
|
||||
})
|
||||
if err == nil {
|
||||
f.SetCellStyle(sheetName, "A1", fmt.Sprintf("%c1", 'A'+len(headers)-1), style)
|
||||
_ = f.SetCellStyle(sheetName, "A1", fmt.Sprintf("%c1", 'A'+len(headers)-1), style)
|
||||
}
|
||||
|
||||
for i, supplier := range suppliers {
|
||||
row := i + 2
|
||||
f.SetCellValue(sheetName, fmt.Sprintf("A%d", row), supplier.ID)
|
||||
f.SetCellValue(sheetName, fmt.Sprintf("B%d", row), supplier.Email)
|
||||
f.SetCellValue(sheetName, fmt.Sprintf("C%d", row), supplier.Phone)
|
||||
f.SetCellValue(sheetName, fmt.Sprintf("D%d", row), supplier.Name)
|
||||
f.SetCellValue(sheetName, fmt.Sprintf("E%d", row), supplier.URL)
|
||||
_ = f.SetCellValue(sheetName, fmt.Sprintf("A%d", row), supplier.ID)
|
||||
_ = f.SetCellValue(sheetName, fmt.Sprintf("B%d", row), supplier.Email)
|
||||
_ = f.SetCellValue(sheetName, fmt.Sprintf("C%d", row), supplier.Phone)
|
||||
_ = f.SetCellValue(sheetName, fmt.Sprintf("D%d", row), supplier.Name)
|
||||
_ = f.SetCellValue(sheetName, fmt.Sprintf("E%d", row), supplier.URL)
|
||||
}
|
||||
|
||||
f.SetColWidth(sheetName, "A", "A", 12)
|
||||
f.SetColWidth(sheetName, "B", "B", 30)
|
||||
f.SetColWidth(sheetName, "C", "C", 20)
|
||||
f.SetColWidth(sheetName, "D", "D", 40)
|
||||
f.SetColWidth(sheetName, "E", "E", 40)
|
||||
_ = f.SetColWidth(sheetName, "A", "A", 12)
|
||||
_ = f.SetColWidth(sheetName, "B", "B", 30)
|
||||
_ = f.SetColWidth(sheetName, "C", "C", 20)
|
||||
_ = f.SetColWidth(sheetName, "D", "D", 40)
|
||||
_ = f.SetColWidth(sheetName, "E", "E", 40)
|
||||
|
||||
f.SetActiveSheet(index)
|
||||
f.DeleteSheet("Sheet1")
|
||||
_ = f.DeleteSheet("Sheet1")
|
||||
|
||||
buffer, err := f.WriteToBuffer()
|
||||
if err != nil {
|
||||
|
||||
@@ -9,12 +9,17 @@ import (
|
||||
"github.com/gojuno/minimock/v3"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"smart-search-back/internal/mocks"
|
||||
"smart-search-back/internal/model"
|
||||
"smart-search-back/internal/service"
|
||||
"smart-search-back/pkg/crypto"
|
||||
apperrors "smart-search-back/pkg/errors"
|
||||
"smart-search-back/pkg/jwt"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/mocks"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/service"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/crypto"
|
||||
apperrors "git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/jwt"
|
||||
)
|
||||
|
||||
const (
|
||||
testJWTSecret = "test-jwt-secret-key"
|
||||
testCryptoSecret = "test-crypto-secret-key"
|
||||
)
|
||||
|
||||
type Suite struct {
|
||||
@@ -24,6 +29,7 @@ type Suite struct {
|
||||
authService service.AuthService
|
||||
userRepo *mocks.UserRepositoryMock
|
||||
sessionRepo *mocks.SessionRepositoryMock
|
||||
crypto *crypto.Crypto
|
||||
}
|
||||
|
||||
func newSuite(ctx context.Context) *Suite {
|
||||
@@ -46,15 +52,17 @@ func (s *Suite) SetupTest() {
|
||||
|
||||
s.userRepo = mocks.NewUserRepositoryMock(ctrl)
|
||||
s.sessionRepo = mocks.NewSessionRepositoryMock(ctrl)
|
||||
s.crypto = crypto.NewCrypto(testCryptoSecret)
|
||||
|
||||
s.authService = service.NewAuthService(s.userRepo, s.sessionRepo)
|
||||
s.authService = service.NewAuthService(s.userRepo, s.sessionRepo, testJWTSecret, testCryptoSecret)
|
||||
}
|
||||
|
||||
func createTestUser(password string) *model.User {
|
||||
c := crypto.NewCrypto(testCryptoSecret)
|
||||
return &model.User{
|
||||
ID: 1,
|
||||
Email: "test@example.com",
|
||||
EmailHash: crypto.EmailHash("test@example.com"),
|
||||
EmailHash: c.EmailHash("test@example.com"),
|
||||
PasswordHash: crypto.PasswordHash(password),
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
@@ -180,7 +188,7 @@ func (s *Suite) TestAuthService_Login_EmailWithSpacesAndCase() {
|
||||
password := "testpassword"
|
||||
normalizedEmail := "test@example.com"
|
||||
user := createTestUser(password)
|
||||
user.EmailHash = crypto.EmailHash(normalizedEmail)
|
||||
user.EmailHash = s.crypto.EmailHash(normalizedEmail)
|
||||
s.userRepo.FindByEmailHashMock.Return(user, nil)
|
||||
s.sessionRepo.CreateMock.Return(nil)
|
||||
|
||||
@@ -328,12 +336,12 @@ func (s *Suite) TestAuthService_Refresh_UserIDZero() {
|
||||
}
|
||||
|
||||
func (s *Suite) TestAuthService_Validate_Success() {
|
||||
s.T().Parallel()
|
||||
|
||||
userID := 1
|
||||
accessToken, err := jwt.GenerateAccessToken(userID)
|
||||
accessToken, err := jwt.GenerateAccessToken(userID, testJWTSecret)
|
||||
s.NoError(err)
|
||||
|
||||
s.sessionRepo.IsAccessTokenValidMock.Return(true, nil)
|
||||
|
||||
validatedUserID, validateErr := s.authService.Validate(s.ctx, accessToken)
|
||||
|
||||
s.NoError(validateErr)
|
||||
@@ -370,7 +378,7 @@ func (s *Suite) TestAuthService_Validate_RefreshTokenInsteadOfAccess() {
|
||||
s.T().Parallel()
|
||||
|
||||
userID := 1
|
||||
refreshToken, err := jwt.GenerateRefreshToken(userID)
|
||||
refreshToken, err := jwt.GenerateRefreshToken(userID, testJWTSecret)
|
||||
s.NoError(err)
|
||||
|
||||
validatedUserID, validateErr := s.authService.Validate(s.ctx, refreshToken)
|
||||
@@ -385,11 +393,11 @@ func (s *Suite) TestAuthService_Validate_RefreshTokenInsteadOfAccess() {
|
||||
}
|
||||
|
||||
func (s *Suite) TestAuthService_Validate_UserIDZero() {
|
||||
s.T().Parallel()
|
||||
|
||||
accessToken, err := jwt.GenerateAccessToken(0)
|
||||
accessToken, err := jwt.GenerateAccessToken(0, testJWTSecret)
|
||||
s.NoError(err)
|
||||
|
||||
s.sessionRepo.IsAccessTokenValidMock.Return(true, nil)
|
||||
|
||||
validatedUserID, validateErr := s.authService.Validate(s.ctx, accessToken)
|
||||
|
||||
s.NoError(validateErr)
|
||||
@@ -412,18 +420,18 @@ func (s *Suite) TestAuthService_Validate_InvalidSignature() {
|
||||
}
|
||||
|
||||
func (s *Suite) TestAuthService_Logout_Success() {
|
||||
s.sessionRepo.RevokeMock.Return(nil)
|
||||
s.sessionRepo.RevokeByAccessTokenMock.Return(nil)
|
||||
|
||||
err := s.authService.Logout(s.ctx, "test-refresh-token")
|
||||
err := s.authService.Logout(s.ctx, "test-access-token")
|
||||
|
||||
s.NoError(err)
|
||||
}
|
||||
|
||||
func (s *Suite) TestAuthService_Logout_DatabaseError() {
|
||||
dbErr := apperrors.NewInternalError(apperrors.DatabaseError, "failed to revoke session", nil)
|
||||
s.sessionRepo.RevokeMock.Return(dbErr)
|
||||
s.sessionRepo.RevokeByAccessTokenMock.Return(dbErr)
|
||||
|
||||
err := s.authService.Logout(s.ctx, "test-refresh-token")
|
||||
err := s.authService.Logout(s.ctx, "test-access-token")
|
||||
|
||||
s.Error(err)
|
||||
|
||||
@@ -433,7 +441,7 @@ func (s *Suite) TestAuthService_Logout_DatabaseError() {
|
||||
}
|
||||
|
||||
func (s *Suite) TestAuthService_Logout_EmptyToken() {
|
||||
s.sessionRepo.RevokeMock.Return(nil)
|
||||
s.sessionRepo.RevokeByAccessTokenMock.Return(nil)
|
||||
|
||||
err := s.authService.Logout(s.ctx, "")
|
||||
|
||||
@@ -441,7 +449,7 @@ func (s *Suite) TestAuthService_Logout_EmptyToken() {
|
||||
}
|
||||
|
||||
func (s *Suite) TestAuthService_Logout_NonExistentToken() {
|
||||
s.sessionRepo.RevokeMock.Return(nil)
|
||||
s.sessionRepo.RevokeByAccessTokenMock.Return(nil)
|
||||
|
||||
err := s.authService.Logout(s.ctx, "non-existent-token")
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ package service
|
||||
import (
|
||||
"context"
|
||||
|
||||
"smart-search-back/internal/repository"
|
||||
"smart-search-back/pkg/crypto"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/repository"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/crypto"
|
||||
)
|
||||
|
||||
type userService struct {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"smart-search-back/internal/repository"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/repository"
|
||||
)
|
||||
|
||||
type InviteCleaner struct {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"smart-search-back/internal/repository"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/repository"
|
||||
)
|
||||
|
||||
type SessionCleaner struct {
|
||||
|
||||
213
internal/worker/worker_test.go
Normal file
213
internal/worker/worker_test.go
Normal file
@@ -0,0 +1,213 @@
|
||||
package worker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gojuno/minimock/v3"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/mocks"
|
||||
)
|
||||
|
||||
type WorkerSuite struct {
|
||||
suite.Suite
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
ctrl *minimock.Controller
|
||||
}
|
||||
|
||||
func TestWorkerSuite(t *testing.T) {
|
||||
suite.Run(t, new(WorkerSuite))
|
||||
}
|
||||
|
||||
func (s *WorkerSuite) SetupTest() {
|
||||
s.ctx, s.cancel = context.WithCancel(context.Background())
|
||||
s.ctrl = minimock.NewController(s.T())
|
||||
}
|
||||
|
||||
func (s *WorkerSuite) TearDownTest() {
|
||||
if s.cancel != nil {
|
||||
s.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *WorkerSuite) TestSessionCleaner_StartStop() {
|
||||
var callCount int32
|
||||
sessionRepo := mocks.NewSessionRepositoryMock(s.ctrl)
|
||||
sessionRepo.DeleteExpiredMock.Set(func(_ context.Context) (int, error) {
|
||||
atomic.AddInt32(&callCount, 1)
|
||||
return 5, nil
|
||||
})
|
||||
|
||||
cleaner := NewSessionCleaner(s.ctx, sessionRepo)
|
||||
|
||||
cleaner.Start()
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
cleaner.Stop()
|
||||
|
||||
s.GreaterOrEqual(int(atomic.LoadInt32(&callCount)), 1,
|
||||
"DeleteExpired должен быть вызван хотя бы раз при старте")
|
||||
}
|
||||
|
||||
func (s *WorkerSuite) TestSessionCleaner_ContextCancellation() {
|
||||
var callCount int32
|
||||
sessionRepo := mocks.NewSessionRepositoryMock(s.ctrl)
|
||||
sessionRepo.DeleteExpiredMock.Set(func(_ context.Context) (int, error) {
|
||||
atomic.AddInt32(&callCount, 1)
|
||||
return 0, nil
|
||||
})
|
||||
|
||||
cleaner := NewSessionCleaner(s.ctx, sessionRepo)
|
||||
|
||||
cleaner.Start()
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
s.cancel()
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
s.GreaterOrEqual(int(atomic.LoadInt32(&callCount)), 1,
|
||||
"DeleteExpired должен быть вызван хотя бы раз")
|
||||
}
|
||||
|
||||
func (s *WorkerSuite) TestInviteCleaner_StartStop() {
|
||||
var callCount int32
|
||||
inviteRepo := mocks.NewInviteRepositoryMock(s.ctrl)
|
||||
inviteRepo.DeactivateExpiredMock.Set(func(_ context.Context) (int, error) {
|
||||
atomic.AddInt32(&callCount, 1)
|
||||
return 3, nil
|
||||
})
|
||||
|
||||
cleaner := NewInviteCleaner(s.ctx, inviteRepo)
|
||||
|
||||
cleaner.Start()
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
cleaner.Stop()
|
||||
|
||||
s.GreaterOrEqual(int(atomic.LoadInt32(&callCount)), 1,
|
||||
"DeactivateExpired должен быть вызван хотя бы раз при старте")
|
||||
}
|
||||
|
||||
func (s *WorkerSuite) TestInviteCleaner_ContextCancellation() {
|
||||
var callCount int32
|
||||
inviteRepo := mocks.NewInviteRepositoryMock(s.ctrl)
|
||||
inviteRepo.DeactivateExpiredMock.Set(func(_ context.Context) (int, error) {
|
||||
atomic.AddInt32(&callCount, 1)
|
||||
return 0, nil
|
||||
})
|
||||
|
||||
cleaner := NewInviteCleaner(s.ctx, inviteRepo)
|
||||
|
||||
cleaner.Start()
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
s.cancel()
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
s.GreaterOrEqual(int(atomic.LoadInt32(&callCount)), 1,
|
||||
"DeactivateExpired должен быть вызван хотя бы раз")
|
||||
}
|
||||
|
||||
func (s *WorkerSuite) TestSessionCleaner_ConcurrentStops() {
|
||||
sessionRepo := mocks.NewSessionRepositoryMock(s.ctrl)
|
||||
sessionRepo.DeleteExpiredMock.Set(func(_ context.Context) (int, error) {
|
||||
return 0, nil
|
||||
})
|
||||
|
||||
cleaner := NewSessionCleaner(s.ctx, sessionRepo)
|
||||
|
||||
cleaner.Start()
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
done := make(chan struct{})
|
||||
for i := 0; i < 5; i++ {
|
||||
go func() {
|
||||
cleaner.Stop()
|
||||
}()
|
||||
}
|
||||
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
close(done)
|
||||
}()
|
||||
|
||||
<-done
|
||||
}
|
||||
|
||||
func (s *WorkerSuite) TestInviteCleaner_ConcurrentStops() {
|
||||
inviteRepo := mocks.NewInviteRepositoryMock(s.ctrl)
|
||||
inviteRepo.DeactivateExpiredMock.Set(func(_ context.Context) (int, error) {
|
||||
return 0, nil
|
||||
})
|
||||
|
||||
cleaner := NewInviteCleaner(s.ctx, inviteRepo)
|
||||
|
||||
cleaner.Start()
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
done := make(chan struct{})
|
||||
for i := 0; i < 5; i++ {
|
||||
go func() {
|
||||
cleaner.Stop()
|
||||
}()
|
||||
}
|
||||
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
close(done)
|
||||
}()
|
||||
|
||||
<-done
|
||||
}
|
||||
|
||||
func (s *WorkerSuite) TestSessionCleaner_MultipleStartStop() {
|
||||
var callCount int32
|
||||
sessionRepo := mocks.NewSessionRepositoryMock(s.ctrl)
|
||||
sessionRepo.DeleteExpiredMock.Set(func(_ context.Context) (int, error) {
|
||||
atomic.AddInt32(&callCount, 1)
|
||||
return 2, nil
|
||||
})
|
||||
|
||||
cleaner := NewSessionCleaner(s.ctx, sessionRepo)
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
cleaner.Start()
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
cleaner.Stop()
|
||||
}
|
||||
|
||||
s.GreaterOrEqual(int(atomic.LoadInt32(&callCount)), 3,
|
||||
"DeleteExpired должен быть вызван минимум 3 раза")
|
||||
}
|
||||
|
||||
func (s *WorkerSuite) TestInviteCleaner_MultipleStartStop() {
|
||||
var callCount int32
|
||||
inviteRepo := mocks.NewInviteRepositoryMock(s.ctrl)
|
||||
inviteRepo.DeactivateExpiredMock.Set(func(_ context.Context) (int, error) {
|
||||
atomic.AddInt32(&callCount, 1)
|
||||
return 1, nil
|
||||
})
|
||||
|
||||
cleaner := NewInviteCleaner(s.ctx, inviteRepo)
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
cleaner.Start()
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
cleaner.Stop()
|
||||
}
|
||||
|
||||
s.GreaterOrEqual(int(atomic.LoadInt32(&callCount)), 3,
|
||||
"DeactivateExpired должен быть вызван минимум 3 раза")
|
||||
}
|
||||
Reference in New Issue
Block a user