diff options
Diffstat (limited to 'git_test.go')
| -rw-r--r-- | git_test.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/git_test.go b/git_test.go index 6542ca0..56adeed 100644 --- a/git_test.go +++ b/git_test.go @@ -2,6 +2,7 @@ package git import ( "io/ioutil" + "path" "testing" "time" ) @@ -15,6 +16,7 @@ func createTestRepo(t *testing.T) *Repository { tmpfile := "README" err = ioutil.WriteFile(path+"/"+tmpfile, []byte("foo\n"), 0644) + checkFatal(t, err) return repo @@ -55,6 +57,40 @@ func seedTestRepo(t *testing.T, repo *Repository) (*Oid, *Oid) { return commitId, treeId } +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: "[email protected]", + When: time.Date(2013, 03, 06, 14, 30, 0, 0, loc), + } + + tmpfile := "README" + err = ioutil.WriteFile(path.Join(path.Dir(path.Dir(repo.Path())), tmpfile), []byte(content), 0644) + checkFatal(t, err) + + idx, err := repo.Index() + checkFatal(t, err) + err = idx.AddByPath("README") + checkFatal(t, err) + treeId, err := idx.WriteTree() + checkFatal(t, err) + + currentBranch, err := repo.Head() + checkFatal(t, err) + currentTip, err := repo.LookupCommit(currentBranch.Target()) + 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, currentTip) + checkFatal(t, err) + + return commitId, treeId +} + func TestOidZero(t *testing.T) { var zeroId Oid @@ -62,3 +98,10 @@ func TestOidZero(t *testing.T) { t.Error("Zero Oid is not zero") } } + +func TestEmptyOid(t *testing.T) { + _, err := NewOid("") + if err == nil || !IsErrorCode(err, ErrGeneric) { + t.Fatal("Should have returned invalid error") + } +} |
