Skip to content

Commit

Permalink
Merge pull request #37 from kripsy/implement-unit-test-09112023
Browse files Browse the repository at this point in the history
add tests
  • Loading branch information
kripsy authored Nov 10, 2023
2 parents 5bacc23 + 848c10c commit 2a74016
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
55 changes: 55 additions & 0 deletions internal/server/controller/grpc_secret_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ func TestGrpcServerMultipartUploadFile(t *testing.T) {
},
expectedError: status.Error(codes.Internal, ""),
},
{
name: "Error get bucket",
setupMocks: func(mockStream *mocks.MockGophKeeperService_MultipartUploadFileServer,
mockSecretUseCase *mocks.MockSecretUseCase,
mockSyncStatus *mocks.MockSyncStatus) {
//nolint:staticcheck
newCtx := context.WithValue(context.Background(), utils.USERNAMECONTEXTKEY, "")
//nolint:staticcheck
newCtx = context.WithValue(newCtx, utils.USERIDCONTEXTKEY, 1)
mockStream.EXPECT().Context().Return(newCtx).AnyTimes()
},
expectedError: status.Error(codes.Internal, ""),
},
{
name: "Couldn't parse GUID",
setupMocks: func(mockStream *mocks.MockGophKeeperService_MultipartUploadFileServer,
Expand Down Expand Up @@ -468,6 +481,48 @@ func TestApplyChanges(t *testing.T) {
utils.USERNAMECONTEXTKEY, "user"), utils.USERIDCONTEXTKEY, 1),
errCode: codes.InvalidArgument,
},
{
name: "Cannot get userID",
req: &pb.ApplyChangesRequest{
Guid: "",
},
setup: func(ctx context.Context) {

},
wantErr: true,
ctx: context.WithValue(context.WithValue(context.Background(),
//nolint:staticcheck
utils.USERNAMECONTEXTKEY, "user"), utils.USERIDCONTEXTKEY+"fake", 1),
errCode: codes.InvalidArgument,
},
{
name: "Cannot get userName",
req: &pb.ApplyChangesRequest{
Guid: "",
},
setup: func(ctx context.Context) {

},
wantErr: true,
ctx: context.WithValue(context.WithValue(context.Background(),
//nolint:staticcheck
utils.USERNAMECONTEXTKEY+"fake", "user"), utils.USERIDCONTEXTKEY, 1),
errCode: codes.InvalidArgument,
},
{
name: "Cannot get bucketname",
req: &pb.ApplyChangesRequest{
Guid: "",
},
setup: func(ctx context.Context) {

},
wantErr: true,
ctx: context.WithValue(context.WithValue(context.Background(),
//nolint:staticcheck
utils.USERNAMECONTEXTKEY, ""), utils.USERIDCONTEXTKEY, 1),
errCode: codes.InvalidArgument,
},
}

for _, tt := range tests {
Expand Down
4 changes: 0 additions & 4 deletions internal/utils/minioutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ func FromUser2BucketName(_ context.Context, username string, userID int) (string
if username == "" {
return "", fmt.Errorf("%w", ErrIncorrectUserName)
}
bucketName := username + str
if bucketName == "" {
return "", fmt.Errorf("%w", ErrIncorrectBucket)
}

return (prefix + username + str), nil
}

0 comments on commit 2a74016

Please sign in to comment.