From c42efe06d42db98286bfb76b85013c10dc9d3c66 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 27 Mar 2019 13:46:09 +0800 Subject: [PATCH] fix tests --- modules/git/commit_info_test.go | 3 ++- modules/git/commit_test.go | 18 ++++++++++++------ modules/git/repo_pull_test.go | 14 ++++++++++---- modules/git/repo_tag_test.go | 10 ++++++++-- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/modules/git/commit_info_test.go b/modules/git/commit_info_test.go index f3f72890f733c..120a9a737cb99 100644 --- a/modules/git/commit_info_test.go +++ b/modules/git/commit_info_test.go @@ -72,8 +72,9 @@ func TestEntries_GetCommitsInfo(t *testing.T) { assert.NoError(t, err) testGetCommitsInfo(t, bareRepo1) - clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1") + clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestEntries_GetCommitsInfo") assert.NoError(t, err) + defer os.RemoveAll(clonedPath) clonedRepo1, err := OpenRepository(clonedPath) assert.NoError(t, err) testGetCommitsInfo(t, clonedRepo1) diff --git a/modules/git/commit_test.go b/modules/git/commit_test.go index 9744053c15883..bbe12b5aec760 100644 --- a/modules/git/commit_test.go +++ b/modules/git/commit_test.go @@ -5,26 +5,32 @@ package git import ( + "path/filepath" "testing" "github.com/stretchr/testify/assert" ) func TestCommitsCount(t *testing.T) { - // FIXME: since drone will only git clone -depth=50, this should be moved to recent commit id - /*commitsCount, err := CommitsCount("", "22d3d029e6f7e6359f3a6fbe8b7827b579ac7445") + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + + commitsCount, err := CommitsCount(bareRepo1Path, "8006ff9adbf0cb94da7dad9e537e53817f9fa5c0") assert.NoError(t, err) - assert.Equal(t, int64(7287), commitsCount)*/ + assert.Equal(t, int64(3), commitsCount) } func TestGetFullCommitID(t *testing.T) { - id, err := GetFullCommitID("", "22d3d029") + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + + id, err := GetFullCommitID(bareRepo1Path, "8006ff9a") assert.NoError(t, err) - assert.Equal(t, "22d3d029e6f7e6359f3a6fbe8b7827b579ac7445", id) + assert.Equal(t, "8006ff9adbf0cb94da7dad9e537e53817f9fa5c0", id) } func TestGetFullCommitIDError(t *testing.T) { - id, err := GetFullCommitID("", "unknown") + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + + id, err := GetFullCommitID(bareRepo1Path, "unknown") assert.Empty(t, id) if assert.Error(t, err) { assert.EqualError(t, err, "object does not exist [id: unknown, rel_path: ]") diff --git a/modules/git/repo_pull_test.go b/modules/git/repo_pull_test.go index 48285ec22c0f2..e19478877341f 100644 --- a/modules/git/repo_pull_test.go +++ b/modules/git/repo_pull_test.go @@ -6,19 +6,25 @@ package git import ( "io/ioutil" + "os" + "path/filepath" "testing" "github.com/stretchr/testify/assert" ) func TestGetFormatPatch(t *testing.T) { - repo, err := OpenRepository(".") + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestGetFormatPatch") assert.NoError(t, err) - rd, err := repo.GetFormatPatch("cdb43f0e^", "cdb43f0e") + defer os.RemoveAll(clonedPath) + repo, err := OpenRepository(clonedPath) + assert.NoError(t, err) + rd, err := repo.GetFormatPatch("8d92fc95^", "8d92fc95") assert.NoError(t, err) patchb, err := ioutil.ReadAll(rd) assert.NoError(t, err) patch := string(patchb) - assert.Regexp(t, "^From cdb43f0e", patch) - assert.Regexp(t, "Subject: .PATCH. add @daviian as maintainer", patch) + assert.Regexp(t, "^From 8d92fc95", patch) + assert.Contains(t, patch, "Subject: [PATCH] Add file2.txt") } diff --git a/modules/git/repo_tag_test.go b/modules/git/repo_tag_test.go index aadbefb02327e..ccb2d57ac2401 100644 --- a/modules/git/repo_tag_test.go +++ b/modules/git/repo_tag_test.go @@ -5,6 +5,7 @@ package git import ( + "os" "path/filepath" "testing" @@ -25,8 +26,13 @@ func TestRepository_GetTags(t *testing.T) { } func TestRepository_GetTag(t *testing.T) { - bareRepo1Path := filepath.Join(testReposDir, "repo1") - bareRepo1, err := OpenRepository(bareRepo1Path) + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + + clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestRepository_GetTag") + assert.NoError(t, err) + defer os.RemoveAll(clonedPath) + + bareRepo1, err := OpenRepository(clonedPath) assert.NoError(t, err) tag, err := bareRepo1.GetTag("test")