summaryrefslogtreecommitdiff
path: root/internal/handler/exec_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/handler/exec_test.go')
-rw-r--r--internal/handler/exec_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/handler/exec_test.go b/internal/handler/exec_test.go
index 6404b7a..ecc4435 100644
--- a/internal/handler/exec_test.go
+++ b/internal/handler/exec_test.go
@@ -16,6 +16,9 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/gitlabnet/accessverifier"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/sshenv"
+ "google.golang.org/protobuf/proto"
+ "google.golang.org/protobuf/types/known/anypb"
+ "google.golang.org/protobuf/types/known/durationpb"
)
func makeHandler(t *testing.T, err error) func(context.Context, *grpc.ClientConn) (int32, error) {
@@ -88,6 +91,21 @@ func TestUnavailableGitalyErr(t *testing.T) {
require.Equal(t, err, grpcstatus.Error(grpccodes.Unavailable, "The git server, Gitaly, is not available at this time. Please contact your administrator."))
}
+func TestGitalyLimitErr(t *testing.T) {
+ cmd := NewGitalyCommand(
+ newConfig(),
+ string(commandargs.UploadPack),
+ &accessverifier.Response{
+ Gitaly: accessverifier.Gitaly{Address: "tcp://localhost:9999"},
+ },
+ )
+ limitErr := errWithDetail(t, &pb.LimitError{
+ ErrorMessage: "concurrency queue wait time reached",
+ RetryAfter: durationpb.New(0)})
+ err := cmd.RunGitalyCommand(context.Background(), makeHandler(t, limitErr))
+ require.Equal(t, err, grpcstatus.Error(grpccodes.Unavailable, "GitLab is currently unable to handle this request due to load."))
+}
+
func TestRunGitalyCommandMetadata(t *testing.T) {
tests := []struct {
name string
@@ -211,3 +229,16 @@ func newConfig() *config.Config {
cfg.GitalyClient.InitSidechannelRegistry(context.Background())
return cfg
}
+
+// errWithDetail adds the given details to the error if it is a gRPC status whose code is not OK.
+func errWithDetail(t *testing.T, detail proto.Message) error {
+ st := grpcstatus.New(grpccodes.Unavailable, "too busy")
+
+ proto := st.Proto()
+ marshaled, err := anypb.New(detail)
+ require.NoError(t, err)
+
+ proto.Details = append(proto.Details, marshaled)
+
+ return grpcstatus.ErrorProto(proto)
+}