Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Mar 27, 2019
1 parent e120e7f commit c42efe0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
3 changes: 2 additions & 1 deletion modules/git/commit_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 12 additions & 6 deletions modules/git/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: ]")
Expand Down
14 changes: 10 additions & 4 deletions modules/git/repo_pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
10 changes: 8 additions & 2 deletions modules/git/repo_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package git

import (
"os"
"path/filepath"
"testing"

Expand All @@ -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")
Expand Down

0 comments on commit c42efe0

Please sign in to comment.