From d7a0495000e35d06993605a9a31a5f9823292f8a Mon Sep 17 00:00:00 2001 From: Carlos Martín Nieto Date: Tue, 19 May 2015 14:56:01 +0200 Subject: Index: Add OpenIndex This lets you persist an index at an arbitrary location. --- index_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'index_test.go') diff --git a/index_test.go b/index_test.go index a1f0c9c..9b54945 100644 --- a/index_test.go +++ b/index_test.go @@ -2,6 +2,7 @@ package git import ( "io/ioutil" + "os" "runtime" "testing" ) @@ -148,6 +149,29 @@ func TestIndexAddAllCallback(t *testing.T) { } } +func TestIndexOpen(t *testing.T) { + repo := createTestRepo(t) + defer cleanupTestRepo(t, repo) + + path := repo.Workdir() + "/heyindex" + + _, err := os.Stat(path) + if !os.IsNotExist(err) { + t.Fatal("new index file already exists") + } + + idx, err := OpenIndex(path) + checkFatal(t, err) + + err = idx.Write() + checkFatal(t, err) + + _, err = os.Stat(path) + if os.IsNotExist(err) { + t.Fatal("new index file did not get written") + } +} + func checkFatal(t *testing.T, err error) { if err == nil { return -- cgit v1.2.3