diff options
author | Paul Okstad <pokstad@gitlab.com> | 2019-08-13 21:05:03 +0300 |
---|---|---|
committer | Paul Okstad <pokstad@gitlab.com> | 2019-08-13 21:05:03 +0300 |
commit | b48d2e04d639898be2505e8a4b4449918b796680 (patch) | |
tree | f67e6677903c6cc36c5fd15b7da6aafce10fa731 | |
parent | 127278a0046768f5f0a1aac0e14bcdcae7f6a668 (diff) | |
parent | 0d9a47102c28dabe306e359a9f314d7b034802cd (diff) |
Merge branch 'jv-rewrite-test-without-worktree' into 'master'
Rewrite UserSquash tests without worktree
See merge request gitlab-org/gitaly!1407
-rw-r--r-- | _support/gitlab-test.git-packed-refs | 1 | ||||
-rw-r--r-- | doc/test_repos.md | 18 | ||||
-rw-r--r-- | internal/service/operations/squash_test.go | 46 |
3 files changed, 25 insertions, 40 deletions
diff --git a/_support/gitlab-test.git-packed-refs b/_support/gitlab-test.git-packed-refs index 42df2144a..daf53eba6 100644 --- a/_support/gitlab-test.git-packed-refs +++ b/_support/gitlab-test.git-packed-refs @@ -50,6 +50,7 @@ ab2c9622c02288a2bbaaf35d96088cfdff31d9d9 refs/heads/gitaly-diff-stuff cb19058ecc02d01f8e4290b7e79cafd16a8839b6 refs/heads/gitaly-stuff e63f41fe459e62e1228fcef60d7189127aeba95a refs/heads/gitaly-test-ref c809470461118b7bcab850f6e9a7ca97ac42f8ea refs/heads/gitaly-windows-1251 +3d05a143ac193c1a6fe4d046a6e3fe71e825258a refs/heads/gitaly/squash-test 5937ac0a7beb003549fc5fd26fc247adbce4a52e refs/heads/improve/awesome 7df99c9ad5b8c9bfc5ae4fb7a91cc87adcce02ef refs/heads/jv-conflict-1 bd493d44ae3c4dd84ce89cb75be78c4708cbd548 refs/heads/jv-conflict-2 diff --git a/doc/test_repos.md b/doc/test_repos.md index 96ad9f06d..1d81762cd 100644 --- a/doc/test_repos.md +++ b/doc/test_repos.md @@ -15,4 +15,20 @@ from files in `_support`. To update `packed-refs` run `git gc` in your test repo and copy the new `packed-refs` to the right location in `_support`. -**TODO** define workflow "for dummies" to update packed-refs. +## Example: + +Let's add a new branch to gitlab-test. + +``` +git clone internal/testhelper/testdata/data/gitlab-test.git _build/gitlab-test + +cd _build/gitlab-test +# make new branch etc. +git push origin my-new-branch # push to local copy of gitlab-test + +cd ../.. + +git -C internal/testhelper/testdata/data/gitlab-test.git push origin refs/heads/my-new-branch # push to public, official copy of gitlab-test +git -C internal/testhelper/testdata/data/gitlab-test.git gc +cp internal/testhelper/testdata/data/gitlab-test.git/packed-refs _support/gitlab-test.git-packed-refs +```
\ No newline at end of file diff --git a/internal/service/operations/squash_test.go b/internal/service/operations/squash_test.go index 18b6afd39..dfaaf4a43 100644 --- a/internal/service/operations/squash_test.go +++ b/internal/service/operations/squash_test.go @@ -3,7 +3,6 @@ package operations import ( "fmt" "io/ioutil" - "os" "path/filepath" "strings" "testing" @@ -68,7 +67,7 @@ func TestSuccessfulUserSquashRequest(t *testing.T) { func ensureSplitIndexExists(t *testing.T, repoDir string) bool { testhelper.MustRunCommand(t, nil, "git", "-C", repoDir, "update-index", "--add") - fis, err := ioutil.ReadDir(filepath.Join(repoDir, ".git")) + fis, err := ioutil.ReadDir(repoDir) require.NoError(t, err) for _, fi := range fis { if strings.HasPrefix(fi.Name(), "sharedindex") { @@ -88,45 +87,14 @@ func TestSuccessfulUserSquashRequestWith3wayMerge(t *testing.T) { client, conn := NewOperationClient(t, serverSocketPath) defer conn.Close() - testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t) + testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() - // The following patch inserts a single line so that we create a - // file that is slightly different from a branched version of this - // file. A 3-way merge must be used in order to merge a branch that - // alters lines involved in this diff. - patch := ` -diff --git a/files/ruby/popen.rb b/files/ruby/popen.rb -index 5b812ff..ff85394 100644 ---- a/files/ruby/popen.rb -+++ b/files/ruby/popen.rb -@@ -19,6 +19,7 @@ module Popen - - @cmd_output = "" - @cmd_status = 0 -+ - Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr| - @cmd_output << stdout.read - @cmd_output << stderr.read -` - tmpFile, err := ioutil.TempFile(os.TempDir(), "squash-test") - require.NoError(t, err) - - tmpFile.Write([]byte(patch)) - tmpFile.Close() - - defer os.Remove(tmpFile.Name()) - - testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "checkout", "-b", "3way-test", "v1.0.0") - testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "apply", tmpFile.Name()) - testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "commit", "-m", "test", "-a") - baseSha := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "rev-parse", "HEAD")) - request := &gitalypb.UserSquashRequest{ Repository: testRepo, User: user, SquashId: "1", - Branch: []byte("3way-test"), + Branch: []byte("gitaly/squash-test"), Author: author, CommitMessage: commitMessage, // The diff between two of these commits results in some changes to files/ruby/popen.rb @@ -140,7 +108,7 @@ index 5b812ff..ff85394 100644 commit, err := log.GetCommit(ctx, testRepo, response.SquashSha) require.NoError(t, err) - require.Equal(t, []string{baseSha}, commit.ParentIds) + require.Equal(t, []string{"3d05a143ac193c1a6fe4d046a6e3fe71e825258a"}, commit.ParentIds) require.Equal(t, author.Name, commit.Author.Name) require.Equal(t, author.Email, commit.Author.Email) require.Equal(t, user.Name, commit.Committer.Name) @@ -149,11 +117,11 @@ index 5b812ff..ff85394 100644 // Ensure Git metadata is cleaned up worktreeList := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "worktree", "list", "--porcelain")) - expectedOut := fmt.Sprintf("worktree %s\nHEAD %s\nbranch refs/heads/3way-test\n", testRepoPath, baseSha) + expectedOut := fmt.Sprintf("worktree %s\nbare\n", testRepoPath) require.Equal(t, expectedOut, worktreeList) // Ensure actual worktree is removed - files, err := ioutil.ReadDir(filepath.Join(testRepoPath, ".git", "gitlab-worktree")) + files, err := ioutil.ReadDir(filepath.Join(testRepoPath, "gitlab-worktree")) require.NoError(t, err) require.Equal(t, 0, len(files)) } @@ -168,7 +136,7 @@ func TestSplitIndex(t *testing.T) { client, conn := NewOperationClient(t, serverSocketPath) defer conn.Close() - testRepo, testRepoPath, cleanup := testhelper.NewTestRepoWithWorktree(t) + testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t) defer cleanup() require.False(t, ensureSplitIndexExists(t, testRepoPath)) |