Make tests less fragile by introducing a test git repo
This commit is contained in:
Jingwen Owen Ou 2014-02-10 08:36:27 -08:00
Родитель 498789a999
Коммит 6e590438d6
3 изменённых файлов: 74 добавлений и 11 удалений

1
fixtures/test.git Submodule

@ -0,0 +1 @@
Subproject commit 5196494806847d5233d877517a79b6ce8b33f5f7

Просмотреть файл

@ -1,12 +1,37 @@
package git
import (
"github.com/bmizerany/assert"
"os"
"strings"
"testing"
"github.com/bmizerany/assert"
)
type TestRepo struct {
Pwd string
}
func (g *TestRepo) Setup() {
g.Pwd, _ = os.Getwd()
os.Chdir("../fixtures/test.git")
}
func (g *TestRepo) TearDown() {
os.Chdir(g.Pwd)
}
func setupRepo() *TestRepo {
repo := &TestRepo{}
repo.Setup()
return repo
}
func TestGitDir(t *testing.T) {
repo := setupRepo()
defer repo.TearDown()
gitDir, _ := Dir()
assert.T(t, strings.Contains(gitDir, ".git"))
}
@ -19,29 +44,42 @@ func TestGitEditor(t *testing.T) {
}
func TestGitLog(t *testing.T) {
log, err := Log("e357a98a1a580b09d4f1d9bf613a6a51e131ef6e", "49e984e2fe86f68c386aeb133b390d39e4264ec1")
repo := setupRepo()
defer repo.TearDown()
log, err := Log("1dbff497d642562805323c5c2cccd4adc4a83b36", "5196494806847d5233d877517a79b6ce8b33f5f7")
assert.Equal(t, nil, err)
assert.NotEqual(t, "", log)
}
func TestGitRef(t *testing.T) {
gitRef, err := Ref("1c1077c052d32a83aa13a8afaa4a9630d2f28ef6")
repo := setupRepo()
defer repo.TearDown()
ref := "1dbff497d642562805323c5c2cccd4adc4a83b36"
gitRef, err := Ref(ref)
assert.Equal(t, nil, err)
assert.Equal(t, "1c1077c052d32a83aa13a8afaa4a9630d2f28ef6", gitRef)
assert.Equal(t, ref, gitRef)
}
func TestGitRefList(t *testing.T) {
refList, err := RefList("e357a98a1a580b09d4f1d9bf613a6a51e131ef6e", "49e984e2fe86f68c386aeb133b390d39e4264ec1")
repo := setupRepo()
defer repo.TearDown()
refList, err := RefList("1dbff497d642562805323c5c2cccd4adc4a83b36", "5196494806847d5233d877517a79b6ce8b33f5f7")
assert.Equal(t, nil, err)
assert.Equal(t, 1, len(refList))
assert.Equal(t, "49e984e2fe86f68c386aeb133b390d39e4264ec1", refList[0])
assert.Equal(t, "5196494806847d5233d877517a79b6ce8b33f5f7", refList[0])
}
func TestGitShow(t *testing.T) {
output, err := Show("f6ba909952aea75d69a9b6e1563a84ec3220ab9c")
repo := setupRepo()
defer repo.TearDown()
output, err := Show("5196494806847d5233d877517a79b6ce8b33f5f7")
assert.Equal(t, nil, err)
assert.Equal(t, "Fix typo in git show format\n\nIt's possible that comments are multiple lines", output)
assert.Equal(t, "Test comment\n\nMore comment", output)
}
func TestGitConfig(t *testing.T) {

Просмотреть файл

@ -1,13 +1,37 @@
package github
import (
"github.com/bmizerany/assert"
"strings"
"os"
"testing"
"github.com/bmizerany/assert"
)
type TestRepo struct {
Pwd string
}
func (g *TestRepo) Setup() {
g.Pwd, _ = os.Getwd()
os.Chdir("../fixtures/test.git")
}
func (g *TestRepo) TearDown() {
os.Chdir(g.Pwd)
}
func setupRepo() *TestRepo {
repo := &TestRepo{}
repo.Setup()
return repo
}
func TestOriginRemote(t *testing.T) {
repo := setupRepo()
defer repo.TearDown()
gitRemote, _ := OriginRemote()
assert.Equal(t, "origin", gitRemote.Name)
assert.T(t, strings.Contains(gitRemote.URL.String(), "gh"))
assert.Equal(t, "https://github.com/test/test.git.git", gitRemote.URL.String())
}