Skip to content

Commit c42efe0

Browse files
committed
fix tests
1 parent e120e7f commit c42efe0

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

modules/git/commit_info_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ func TestEntries_GetCommitsInfo(t *testing.T) {
7272
assert.NoError(t, err)
7373
testGetCommitsInfo(t, bareRepo1)
7474

75-
clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1")
75+
clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestEntries_GetCommitsInfo")
7676
assert.NoError(t, err)
77+
defer os.RemoveAll(clonedPath)
7778
clonedRepo1, err := OpenRepository(clonedPath)
7879
assert.NoError(t, err)
7980
testGetCommitsInfo(t, clonedRepo1)

modules/git/commit_test.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,32 @@
55
package git
66

77
import (
8+
"path/filepath"
89
"testing"
910

1011
"github.com/stretchr/testify/assert"
1112
)
1213

1314
func TestCommitsCount(t *testing.T) {
14-
// FIXME: since drone will only git clone -depth=50, this should be moved to recent commit id
15-
/*commitsCount, err := CommitsCount("", "22d3d029e6f7e6359f3a6fbe8b7827b579ac7445")
15+
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
16+
17+
commitsCount, err := CommitsCount(bareRepo1Path, "8006ff9adbf0cb94da7dad9e537e53817f9fa5c0")
1618
assert.NoError(t, err)
17-
assert.Equal(t, int64(7287), commitsCount)*/
19+
assert.Equal(t, int64(3), commitsCount)
1820
}
1921

2022
func TestGetFullCommitID(t *testing.T) {
21-
id, err := GetFullCommitID("", "22d3d029")
23+
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
24+
25+
id, err := GetFullCommitID(bareRepo1Path, "8006ff9a")
2226
assert.NoError(t, err)
23-
assert.Equal(t, "22d3d029e6f7e6359f3a6fbe8b7827b579ac7445", id)
27+
assert.Equal(t, "8006ff9adbf0cb94da7dad9e537e53817f9fa5c0", id)
2428
}
2529

2630
func TestGetFullCommitIDError(t *testing.T) {
27-
id, err := GetFullCommitID("", "unknown")
31+
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
32+
33+
id, err := GetFullCommitID(bareRepo1Path, "unknown")
2834
assert.Empty(t, id)
2935
if assert.Error(t, err) {
3036
assert.EqualError(t, err, "object does not exist [id: unknown, rel_path: ]")

modules/git/repo_pull_test.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@ package git
66

77
import (
88
"io/ioutil"
9+
"os"
10+
"path/filepath"
911
"testing"
1012

1113
"github.com/stretchr/testify/assert"
1214
)
1315

1416
func TestGetFormatPatch(t *testing.T) {
15-
repo, err := OpenRepository(".")
17+
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
18+
clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestGetFormatPatch")
1619
assert.NoError(t, err)
17-
rd, err := repo.GetFormatPatch("cdb43f0e^", "cdb43f0e")
20+
defer os.RemoveAll(clonedPath)
21+
repo, err := OpenRepository(clonedPath)
22+
assert.NoError(t, err)
23+
rd, err := repo.GetFormatPatch("8d92fc95^", "8d92fc95")
1824
assert.NoError(t, err)
1925
patchb, err := ioutil.ReadAll(rd)
2026
assert.NoError(t, err)
2127
patch := string(patchb)
22-
assert.Regexp(t, "^From cdb43f0e", patch)
23-
assert.Regexp(t, "Subject: .PATCH. add @daviian as maintainer", patch)
28+
assert.Regexp(t, "^From 8d92fc95", patch)
29+
assert.Contains(t, patch, "Subject: [PATCH] Add file2.txt")
2430
}

modules/git/repo_tag_test.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package git
66

77
import (
8+
"os"
89
"path/filepath"
910
"testing"
1011

@@ -25,8 +26,13 @@ func TestRepository_GetTags(t *testing.T) {
2526
}
2627

2728
func TestRepository_GetTag(t *testing.T) {
28-
bareRepo1Path := filepath.Join(testReposDir, "repo1")
29-
bareRepo1, err := OpenRepository(bareRepo1Path)
29+
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
30+
31+
clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestRepository_GetTag")
32+
assert.NoError(t, err)
33+
defer os.RemoveAll(clonedPath)
34+
35+
bareRepo1, err := OpenRepository(clonedPath)
3036
assert.NoError(t, err)
3137

3238
tag, err := bareRepo1.GetTag("test")

0 commit comments

Comments
 (0)