Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'internal/gitaly/service/commit/find_commits_test.go')
-rw-r--r--internal/gitaly/service/commit/find_commits_test.go157
1 files changed, 156 insertions, 1 deletions
diff --git a/internal/gitaly/service/commit/find_commits_test.go b/internal/gitaly/service/commit/find_commits_test.go
index 21a92e71a..a7accd162 100644
--- a/internal/gitaly/service/commit/find_commits_test.go
+++ b/internal/gitaly/service/commit/find_commits_test.go
@@ -17,6 +17,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage/storagemgr"
"gitlab.com/gitlab-org/gitaly/v16/internal/structerr"
"gitlab.com/gitlab-org/gitaly/v16/internal/testhelper"
+ "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper/testserver"
"gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
"golang.org/x/text/encoding/charmap"
"google.golang.org/grpc/codes"
@@ -651,16 +652,28 @@ func TestFindCommits_quarantine(t *testing.T) {
desc string
altDirs []string
expectedCount int
+ expectedErr error
}{
{
desc: "present GIT_ALTERNATE_OBJECT_DIRECTORIES",
altDirs: []string{altObjectsDir},
expectedCount: 1,
+ expectedErr: nil,
},
{
desc: "empty GIT_ALTERNATE_OBJECT_DIRECTORIES",
altDirs: []string{},
expectedCount: 0,
+ expectedErr: testhelper.ToInterceptedMetadata(
+ structerr.NewNotFound("commits not found").WithMetadata("error", "exit status 128").WithMetadata("stderr",
+ fmt.Sprintf("fatal: bad object %s\n", commitID.String()))).WithDetail(
+ &gitalypb.FindCommitsError{
+ Error: &gitalypb.FindCommitsError_BadObject{
+ BadObject: &gitalypb.BadObjectError{
+ ObjectId: []byte(commitID.String()),
+ },
+ },
+ }),
},
} {
t.Run(tc.desc, func(t *testing.T) {
@@ -681,12 +694,154 @@ func TestFindCommits_quarantine(t *testing.T) {
Revision: []byte(commitID.String()),
Limit: 1,
})
- require.NoError(t, err)
+ testhelper.RequireGrpcError(t, tc.expectedErr, err)
+ require.Len(t, commits, tc.expectedCount)
+ })
+ }
+}
+
+func TestFindCommits_simulateGitLogWaitError(t *testing.T) {
+ t.Parallel()
+
+ ctx := testhelper.Context(t)
+ logger := testhelper.NewLogger(t)
+ cfg, client := setupCommitService(t, ctx, testserver.WithLogger(logger))
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
+ // altObjectsDir is used to trigger git log wait error
+ // we will set this to empty string to trigger the error
+ altObjectsDir := "./alt-objects"
+ commitID := gittest.WriteCommit(t, cfg, repoPath,
+ gittest.WithAlternateObjectDirectory(filepath.Join(repoPath, altObjectsDir)),
+ )
+
+ for _, tc := range []struct {
+ desc string
+ altDirs []string
+ expectedCount int
+ expectedErr error
+ limit int32
+ }{
+ {
+ desc: "git log exit with error, with limit 0",
+ altDirs: []string{},
+ limit: 0,
+ expectedCount: 0,
+ expectedErr: nil,
+ },
+ {
+ desc: "limit 1, git log exit with error",
+ altDirs: []string{},
+ limit: 1,
+ expectedCount: 0,
+ expectedErr: testhelper.ToInterceptedMetadata(
+ structerr.NewNotFound("commits not found").
+ WithMetadata("error", "exit status 128").
+ WithMetadata("stderr", fmt.Sprintf("fatal: bad object %s\n", commitID.String()))).WithDetail(
+ &gitalypb.FindCommitsError{
+ Error: &gitalypb.FindCommitsError_BadObject{
+ BadObject: &gitalypb.BadObjectError{
+ ObjectId: []byte(commitID.String()),
+ },
+ },
+ }),
+ },
+ } {
+ tc := tc
+ t.Run(tc.desc, func(t *testing.T) {
+ repo.GitAlternateObjectDirectories = tc.altDirs
+ commits, err := getCommits(t, ctx, client, &gitalypb.FindCommitsRequest{
+ Repository: repo,
+ Revision: []byte(commitID.String()),
+ Limit: tc.limit,
+ })
+ testhelper.RequireGrpcError(t, tc.expectedErr, err)
require.Len(t, commits, tc.expectedCount)
})
}
}
+func TestWrapGitLogCmdError(t *testing.T) {
+ t.Parallel()
+ for _, tc := range []struct {
+ desc string
+ commitCounter int32
+ gitLogCmdArg string
+ gitLogCmdStdErr string
+ expectedErr error
+ }{
+ {
+ desc: "no commits found due to ambiguous argument",
+ commitCounter: 0,
+ gitLogCmdArg: "non-existing-ref",
+ gitLogCmdStdErr: "fatal: ambiguous argument 'non-existing-ref': unknown revision or path not in the working tree.",
+ expectedErr: structerr.NewNotFound("commits not found").WithDetail(
+ &gitalypb.FindCommitsError{
+ Error: &gitalypb.FindCommitsError_AmbiguousArgument{
+ AmbiguousArgument: &gitalypb.AmbiguousArgumentError{
+ Argument: []byte("non-existing-ref"),
+ },
+ },
+ }),
+ },
+ {
+ desc: "no commits found due to bad object id",
+ commitCounter: 0,
+ gitLogCmdArg: "37811987837aacbd3b1d8ceb8de669b33f7c7c0a",
+ gitLogCmdStdErr: "fatal: bad object 37811987837aacbd3b1d8ceb8de669b33f7c7c0a",
+ expectedErr: structerr.NewNotFound("commits not found").WithDetail(
+ &gitalypb.FindCommitsError{
+ Error: &gitalypb.FindCommitsError_BadObject{
+ BadObject: &gitalypb.BadObjectError{
+ ObjectId: []byte("37811987837aacbd3b1d8ceb8de669b33f7c7c0a"),
+ },
+ },
+ }),
+ },
+ {
+ desc: "no commits found due to invalid range",
+ commitCounter: 0,
+ gitLogCmdArg: "37811987837aacbd3b1d8ceb8de669b33f7c7c0a..37811987837aacbd3b1d8ceb8de669b33f7c7c0b",
+ gitLogCmdStdErr: "fatal: Invalid revision range 37811987837aacbd3b1d8ceb8de669b33f7c7c0a..37811987837aacbd3b1d8ceb8de669b33f7c7c0b\n",
+ expectedErr: structerr.NewNotFound("commits not found").WithDetail(
+ &gitalypb.FindCommitsError{
+ Error: &gitalypb.FindCommitsError_InvalidRange{
+ InvalidRange: &gitalypb.InvalidRevisionRange{
+ Range: []byte("37811987837aacbd3b1d8ceb8de669b33f7c7c0a..37811987837aacbd3b1d8ceb8de669b33f7c7c0b"),
+ },
+ },
+ }),
+ },
+ {
+ desc: "uncategorized error that causes empty commits",
+ commitCounter: 0,
+ gitLogCmdArg: "",
+ gitLogCmdStdErr: "fatal: some other cause can't be foreseen right now",
+ expectedErr: structerr.NewNotFound("commits not found").WithDetail(
+ &gitalypb.FindCommitsError{
+ Error: &gitalypb.FindCommitsError_UncategorizedError{
+ UncategorizedError: &gitalypb.UncategorizedGitLogError{
+ Cause: "fatal: some other cause can't be foreseen right now",
+ },
+ },
+ }),
+ },
+ {
+ desc: "mock terminated by user error",
+ commitCounter: 10,
+ gitLogCmdArg: "main",
+ gitLogCmdStdErr: "terminated by user",
+ expectedErr: structerr.NewInternal("listing commits failed"),
+ },
+ } {
+ tc := tc
+ t.Run(tc.desc, func(t *testing.T) {
+ actualErr := wrapGitLogCmdError([]byte(tc.gitLogCmdArg), tc.commitCounter, nil, tc.gitLogCmdStdErr)
+ testhelper.RequireGrpcError(t, tc.expectedErr, actualErr)
+ })
+ }
+}
+
func TestFindCommits_followWithOffset(t *testing.T) {
t.Parallel()