diff options
author | zeripath <art27@cantab.net> | 2022-01-29 12:41:44 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-29 12:41:44 +0000 |
commit | f7b152f1262e5bec4f6aec061e2ded65d0b53893 (patch) | |
tree | c88d9dfd9a216db2e430419eef26f8fed8e47ce2 /modules/git/repo_compare_test.go | |
parent | 92b715e0f2c655169e82fb76f7b109b8de21a095 (diff) | |
download | gitea-f7b152f1262e5bec4f6aec061e2ded65d0b53893.tar.gz gitea-f7b152f1262e5bec4f6aec061e2ded65d0b53893.zip |
Ensure git tag tests and others create test repos in tmpdir (#18447)
* Ensure git tag tests and other create test repos in tmpdir
There are a few places where tests appear to reuse testing repos which
causes random CI failures.
This PR simply changes these tests to ensure that cloning always happens
into new temporary directories.
Fix #18444
* Change log root for integration tests to use the REPO_TEST_DIR
There is a potential race in the drone integration tests whereby test-mysql etc
will start writing to log files causing make test-check fail.
Fix #18077
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/git/repo_compare_test.go')
-rw-r--r-- | modules/git/repo_compare_test.go | 76 |
1 files changed, 61 insertions, 15 deletions
diff --git a/modules/git/repo_compare_test.go b/modules/git/repo_compare_test.go index 301e085aae..82d3257c0f 100644 --- a/modules/git/repo_compare_test.go +++ b/modules/git/repo_compare_test.go @@ -17,17 +17,33 @@ import ( func TestGetFormatPatch(t *testing.T) { bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestGetFormatPatch") + clonedPath, err := cloneRepo(bareRepo1Path, "repo1_TestGetFormatPatch") + if err != nil { + assert.NoError(t, err) + return + } defer util.RemoveAll(clonedPath) - assert.NoError(t, err) + repo, err := OpenRepository(clonedPath) + if err != nil { + assert.NoError(t, err) + return + } defer repo.Close() - assert.NoError(t, err) + rd := &bytes.Buffer{} err = repo.GetPatch("8d92fc95^", "8d92fc95", rd) - assert.NoError(t, err) + if err != nil { + assert.NoError(t, err) + return + } + patchb, err := io.ReadAll(rd) - assert.NoError(t, err) + if err != nil { + assert.NoError(t, err) + return + } + patch := string(patchb) assert.Regexp(t, "^From 8d92fc95", patch) assert.Contains(t, patch, "Subject: [PATCH] Add file2.txt") @@ -37,17 +53,25 @@ func TestReadPatch(t *testing.T) { // Ensure we can read the patch files bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") repo, err := OpenRepository(bareRepo1Path) + if err != nil { + assert.NoError(t, err) + return + } defer repo.Close() - assert.NoError(t, err) // This patch doesn't exist noFile, err := repo.ReadPatchCommit(0) assert.Error(t, err) + // This patch is an empty one (sometimes it's a 404) noCommit, err := repo.ReadPatchCommit(1) assert.Error(t, err) + // This patch is legit and should return a commit oldCommit, err := repo.ReadPatchCommit(2) - assert.NoError(t, err) + if err != nil { + assert.NoError(t, err) + return + } assert.Empty(t, noFile) assert.Empty(t, noCommit) @@ -58,23 +82,45 @@ func TestReadPatch(t *testing.T) { func TestReadWritePullHead(t *testing.T) { // Ensure we can write SHA1 head corresponding to PR and open them bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") - repo, err := OpenRepository(bareRepo1Path) - assert.NoError(t, err) + + // As we are writing we should clone the repository first + clonedPath, err := cloneRepo(bareRepo1Path, "TestReadWritePullHead") + if err != nil { + assert.NoError(t, err) + return + } + defer util.RemoveAll(clonedPath) + + repo, err := OpenRepository(clonedPath) + if err != nil { + assert.NoError(t, err) + return + } defer repo.Close() + // Try to open non-existing Pull _, err = repo.GetRefCommitID(PullPrefix + "0/head") assert.Error(t, err) + // Write a fake sha1 with only 40 zeros newCommit := "feaf4ba6bc635fec442f46ddd4512416ec43c2c2" err = repo.SetReference(PullPrefix+"1/head", newCommit) - assert.NoError(t, err) - // Remove file after the test - defer func() { - _ = repo.RemoveReference(PullPrefix + "1/head") - }() + if err != nil { + assert.NoError(t, err) + return + } + // Read the file created headContents, err := repo.GetRefCommitID(PullPrefix + "1/head") - assert.NoError(t, err) + if err != nil { + assert.NoError(t, err) + return + } + assert.Len(t, string(headContents), 40) assert.True(t, string(headContents) == newCommit) + + // Remove file after the test + err = repo.RemoveReference(PullPrefix + "1/head") + assert.NoError(t, err) } |