generated from VLADIMIR/template
37 lines
1.4 KiB
Go
37 lines
1.4 KiB
Go
package app
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
"evening_detective_server/internal/services/participation_service"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
func TestParticipationErrorStatus(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name string
|
|
err error
|
|
code codes.Code
|
|
want string
|
|
}{
|
|
{"invalid link", participation_service.ErrParticipationLink, codes.NotFound, "ссылка недействительна"},
|
|
{"invalid answer", participation_service.ErrInvalidAnswer, codes.InvalidArgument, "выберите подтверждение или отмену участия"},
|
|
{"closed", participation_service.ErrParticipationClosed, codes.FailedPrecondition, "приём ответов закрыт"},
|
|
{"final", participation_service.ErrParticipationFinal, codes.FailedPrecondition, "решение уже принято и не может быть изменено"},
|
|
{"internal", errors.New("private database detail"), codes.Internal, "participation failed"},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := participationErrorStatus(tc.err, "participation failed")
|
|
if status.Code(got) != tc.code || status.Convert(got).Message() != tc.want {
|
|
t.Fatalf("status=%v, want %s %q", got, tc.code, tc.want)
|
|
}
|
|
if tc.code == codes.Internal && strings.Contains(status.Convert(got).Message(), "private database detail") {
|
|
t.Fatal("private error exposed")
|
|
}
|
|
})
|
|
}
|
|
}
|