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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-05-03 15:35:58 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-05-04 13:22:20 +0300
commit81f71c9c5b5cb6bc5182b528f1ebbab0ba303aae (patch)
treebf4313c5476aad99f1014efb969058c509987ec2
parentdcff87fb715ca0ab3da686cffe68b5e6b00767bf (diff)
commit: Rewrite `ListLastCommitsForTree` test to not use worktree
Rewrite a `ListLastCommitsForTree()` test to not use a worktree. Tests should instead use `gittest.WriteCommit()` and `gittest.WriteTree()` to set up the repository state, which both don't require a worktree.
-rw-r--r--internal/gitaly/service/commit/list_last_commits_for_tree_test.go81
1 files changed, 44 insertions, 37 deletions
diff --git a/internal/gitaly/service/commit/list_last_commits_for_tree_test.go b/internal/gitaly/service/commit/list_last_commits_for_tree_test.go
index f848e48e6..81b681948 100644
--- a/internal/gitaly/service/commit/list_last_commits_for_tree_test.go
+++ b/internal/gitaly/service/commit/list_last_commits_for_tree_test.go
@@ -1,17 +1,13 @@
package commit
import (
- "bytes"
"io"
- "os"
- "path/filepath"
"testing"
"unicode/utf8"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest"
- "gitlab.com/gitlab-org/gitaly/v14/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -354,55 +350,66 @@ func TestSuccessfulListLastCommitsForTreeRequestWithGlobCharacters(t *testing.T)
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repo, repoPath, client := setupCommitServiceWithRepo(ctx, t, false)
+ cfg, repo, repoPath, client := setupCommitServiceWithRepo(ctx, t, true)
- path := ":wq"
- err := os.Mkdir(filepath.Join(repoPath, path), 0o755)
- require.NoError(t, err)
+ commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries(gittest.TreeEntry{
+ Path: ":wq", Mode: "040000", OID: gittest.WriteTree(t, cfg, repoPath, []gittest.TreeEntry{
+ {Path: "README.md", Mode: "100644", Content: "something"},
+ }),
+ }), gittest.WithParents())
+
+ t.Run("with literal pathspecs", func(t *testing.T) {
+ stream, err := client.ListLastCommitsForTree(ctx, &gitalypb.ListLastCommitsForTreeRequest{
+ Repository: repo,
+ Revision: commitID.String(),
+ Path: []byte(":wq"),
+ GlobalOptions: &gitalypb.GlobalOptions{LiteralPathspecs: true},
+ Limit: 100,
+ })
+ require.NoError(t, err)
+ require.Equal(t, []string{":wq"}, fetchCommitPaths(t, stream))
+ })
+
+ t.Run("without literal pathspecs", func(t *testing.T) {
+ stream, err := client.ListLastCommitsForTree(ctx, &gitalypb.ListLastCommitsForTreeRequest{
+ Repository: repo,
+ Revision: commitID.String(),
+ Path: []byte(":wq"),
+ GlobalOptions: &gitalypb.GlobalOptions{LiteralPathspecs: false},
+ Limit: 100,
+ })
+ require.NoError(t, err)
+ require.Nil(t, fetchCommitPaths(t, stream))
+ })
+}
- gittest.Exec(t, cfg, "-C", repoPath, "mv", "README.md", path)
- gittest.Exec(t, cfg, "-C", repoPath, "commit", "-a", "-m", "renamed test file")
- commitID := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "HEAD"))
+func fileExistsInCommits(t *testing.T, stream gitalypb.CommitService_ListLastCommitsForTreeClient, path string) bool {
+ t.Helper()
- request := &gitalypb.ListLastCommitsForTreeRequest{
- Repository: repo,
- Revision: commitID,
- Path: []byte(path),
- GlobalOptions: &gitalypb.GlobalOptions{LiteralPathspecs: true},
- Limit: 100,
- Offset: 0,
+ for _, commitPath := range fetchCommitPaths(t, stream) {
+ if commitPath == path {
+ return true
+ }
}
- stream, err := client.ListLastCommitsForTree(ctx, request)
- require.NoError(t, err)
-
- assert.True(t, fileExistsInCommits(t, stream, path))
- request.GlobalOptions = &gitalypb.GlobalOptions{LiteralPathspecs: false}
- stream, err = client.ListLastCommitsForTree(ctx, request)
- require.NoError(t, err)
- assert.False(t, fileExistsInCommits(t, stream, path))
+ return false
}
-func fileExistsInCommits(t *testing.T, stream gitalypb.CommitService_ListLastCommitsForTreeClient, path string) bool {
+func fetchCommitPaths(t *testing.T, stream gitalypb.CommitService_ListLastCommitsForTreeClient) []string {
t.Helper()
- var filenameFound bool
+ var files []string
for {
- fetchedCommits, err := stream.Recv()
+ response, err := stream.Recv()
if err == io.EOF {
break
}
-
require.NoError(t, err)
- commits := fetchedCommits.GetCommits()
-
- for _, fetchedCommit := range commits {
- if bytes.Equal(fetchedCommit.PathBytes, []byte(path)) {
- filenameFound = true
- }
+ for _, commit := range response.GetCommits() {
+ files = append(files, string(commit.PathBytes))
}
}
- return filenameFound
+ return files
}