diff options
Diffstat (limited to 'workhorse/internal/git/info-refs_test.go')
-rw-r--r-- | workhorse/internal/git/info-refs_test.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/workhorse/internal/git/info-refs_test.go b/workhorse/internal/git/info-refs_test.go new file mode 100644 index 00000000000..4f23d1ac174 --- /dev/null +++ b/workhorse/internal/git/info-refs_test.go @@ -0,0 +1,42 @@ +package git + +import ( + "net/http/httptest" + "testing" + + "github.com/stretchr/testify/require" + grpccodes "google.golang.org/grpc/codes" + grpcstatus "google.golang.org/grpc/status" + + "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" + + "gitlab.com/gitlab-org/gitlab/workhorse/internal/api" + "gitlab.com/gitlab-org/gitlab/workhorse/internal/gitaly" +) + +type smartHTTPServiceServerWithInfoRefs struct { + gitalypb.UnimplementedSmartHTTPServiceServer + InfoRefsUploadPackFunc func(*gitalypb.InfoRefsRequest, gitalypb.SmartHTTPService_InfoRefsUploadPackServer) error +} + +func (srv *smartHTTPServiceServerWithInfoRefs) InfoRefsUploadPack(r *gitalypb.InfoRefsRequest, s gitalypb.SmartHTTPService_InfoRefsUploadPackServer) error { + return srv.InfoRefsUploadPackFunc(r, s) +} + +func TestGetInfoRefsHandler(t *testing.T) { + addr := startSmartHTTPServer(t, &smartHTTPServiceServerWithInfoRefs{ + InfoRefsUploadPackFunc: func(r *gitalypb.InfoRefsRequest, s gitalypb.SmartHTTPService_InfoRefsUploadPackServer) error { + return grpcstatus.Error(grpccodes.Unavailable, "error") + }, + }) + + w := httptest.NewRecorder() + r := httptest.NewRequest("GET", "/?service=git-upload-pack", nil) + a := &api.Response{GitalyServer: gitaly.Server{Address: addr}} + + handleGetInfoRefs(NewHttpResponseWriter(w), r, a) + require.Equal(t, 503, w.Code) + + msg := "The git server, Gitaly, is not available at this time. Please contact your administrator.\n" + require.Equal(t, msg, w.Body.String()) +} |