summaryrefslogtreecommitdiff
path: root/index_test.go
diff options
context:
space:
mode:
authorVicent Martí <[email protected]>2013-03-06 07:48:16 -0800
committerVicent Martí <[email protected]>2013-03-06 07:48:16 -0800
commitbdfd8736bc8c119c4a841fd8b1c8202f5d5ceb9a (patch)
tree287985309c887abb33b921239247e70420d40145 /index_test.go
parent9b6d570748ae51bf38e3192f9a5de45bc68b23c6 (diff)
parent23ba0f1e6dbfa75c71958f016b3e212d65143b60 (diff)
Merge pull request #4 from carlosmn/index
Wrap the index and test it a bit
Diffstat (limited to 'index_test.go')
-rw-r--r--index_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/index_test.go b/index_test.go
new file mode 100644
index 0000000..b853ebf
--- /dev/null
+++ b/index_test.go
@@ -0,0 +1,46 @@
+package git
+
+import (
+ "os"
+ "runtime"
+ "testing"
+ "io/ioutil"
+)
+
+func TestCreateRepoAndStage(t *testing.T) {
+ // figure out where we can create the test repo
+ path, err := ioutil.TempDir("", "git2go")
+ checkFatal(t, err)
+ repo, err := Init(path, false)
+ checkFatal(t, err)
+
+ tmpfile := "README"
+ err = ioutil.WriteFile(path + "/" + tmpfile, []byte("foo\n"), 0644)
+ checkFatal(t, err)
+ defer os.RemoveAll(path)
+
+ idx, err := repo.Index()
+ checkFatal(t, err)
+ err = idx.AddByPath(tmpfile)
+ checkFatal(t, err)
+ treeId, err := idx.WriteTree()
+ checkFatal(t, err)
+
+ if treeId.String() != "b7119b11e8ef7a1a5a34d3ac87f5b075228ac81e" {
+ t.Fatalf("%v", treeId.String())
+ }
+}
+
+func checkFatal(t *testing.T, err error) {
+ if err == nil {
+ return
+ }
+
+ // The failure happens at wherever we were called, not here
+ _, file, line, ok := runtime.Caller(1)
+ if !ok {
+ t.Fatal()
+ }
+
+ t.Fatalf("Fail at %v:%v", file, line)
+}