git2go/git_test.go

96 lines
2.1 KiB
Go
Raw Normal View History

2013-04-16 16:18:35 -05:00
package git
import (
"io/ioutil"
2014-03-21 00:54:18 -05:00
"path"
2014-03-20 23:56:41 -05:00
"testing"
2013-04-16 16:18:35 -05:00
"time"
)
func createTestRepo(t *testing.T) *Repository {
// figure out where we can create the test repo
path, err := ioutil.TempDir("", "git2go")
checkFatal(t, err)
repo, err := InitRepository(path, false)
checkFatal(t, err)
tmpfile := "README"
2014-03-20 23:56:41 -05:00
err = ioutil.WriteFile(path+"/"+tmpfile, []byte("foo\n"), 0644)
2014-03-21 00:02:19 -05:00
2014-02-27 18:36:44 -06:00
checkFatal(t, err)
return repo
}
func createBareTestRepo(t *testing.T) *Repository {
// figure out where we can create the test repo
path, err := ioutil.TempDir("", "git2go")
checkFatal(t, err)
repo, err := InitRepository(path, true)
2013-04-16 16:18:35 -05:00
checkFatal(t, err)
return repo
}
func seedTestRepo(t *testing.T, repo *Repository) (*Oid, *Oid) {
loc, err := time.LoadLocation("Europe/Berlin")
checkFatal(t, err)
sig := &Signature{
Name: "Rand Om Hacker",
Email: "random@hacker.com",
When: time.Date(2013, 03, 06, 14, 30, 0, 0, loc),
}
idx, err := repo.Index()
checkFatal(t, err)
err = idx.AddByPath("README")
checkFatal(t, err)
treeId, err := idx.WriteTree()
checkFatal(t, err)
message := "This is a commit\n"
tree, err := repo.LookupTree(treeId)
checkFatal(t, err)
commitId, err := repo.CreateCommit("HEAD", sig, sig, message, tree)
checkFatal(t, err)
return commitId, treeId
}
2014-03-20 23:56:41 -05:00
func updateReadme(t *testing.T, repo *Repository, content string) (*Oid, *Oid) {
loc, err := time.LoadLocation("Europe/Berlin")
checkFatal(t, err)
sig := &Signature{
Name: "Rand Om Hacker",
Email: "random@hacker.com",
When: time.Date(2013, 03, 06, 14, 30, 0, 0, loc),
}
tmpfile := "README"
2014-03-21 00:54:18 -05:00
err = ioutil.WriteFile(path.Join(path.Dir(path.Dir(repo.Path())), tmpfile), []byte(content), 0644)
2014-03-20 23:56:41 -05:00
checkFatal(t, err)
idx, err := repo.Index()
checkFatal(t, err)
err = idx.AddByPath("README")
checkFatal(t, err)
treeId, err := idx.WriteTree()
checkFatal(t, err)
message := "This is a commit\n"
tree, err := repo.LookupTree(treeId)
checkFatal(t, err)
commitId, err := repo.CreateCommit("HEAD", sig, sig, message, tree)
checkFatal(t, err)
return commitId, treeId
}
2014-03-21 00:02:19 -05:00
func TestOidZero(t *testing.T) {
var zeroId Oid
if !zeroId.IsZero() {
t.Error("Zero Oid is not zero")
}
}