generated from VLADIMIR/template
up
This commit is contained in:
@@ -16,5 +16,8 @@ func gameplayErrorStatus(err error, internalMessage string) error {
|
||||
if errors.Is(err, gameplay_service.ErrGameNotFound) {
|
||||
return status.Error(codes.NotFound, gameplay_service.ErrGameNotFound.Error())
|
||||
}
|
||||
if errors.Is(err, gameplay_service.ErrMovesNotAllowed) {
|
||||
return status.Error(codes.FailedPrecondition, gameplay_service.ErrMovesNotAllowed.Error())
|
||||
}
|
||||
return status.Error(codes.Internal, internalMessage)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"evening_detective_server/internal/services/gameplay_service"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func TestGameplayMoveErrorIsSafe(t *testing.T) {
|
||||
mapped := gameplayErrorStatus(fmt.Errorf("private detail: %w", gameplay_service.ErrMovesNotAllowed), "не удалось сделать ход")
|
||||
if status.Code(mapped) != codes.FailedPrecondition || status.Convert(mapped).Message() != gameplay_service.ErrMovesNotAllowed.Error() {
|
||||
t.Fatalf("unexpected move error: %v", mapped)
|
||||
}
|
||||
mapped = gameplayErrorStatus(errors.New("private database detail"), "не удалось сделать ход")
|
||||
if status.Code(mapped) != codes.Internal || status.Convert(mapped).Message() != "не удалось сделать ход" {
|
||||
t.Fatalf("unsafe internal error: %v", mapped)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user