From 1a7956379497387111191f7f7017167569ef0387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 6 Mar 2013 19:18:41 +0100 Subject: [PATCH] Factor out creating the test repo --- index_test.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/index_test.go b/index_test.go index cbcdaa5..c86c322 100644 --- a/index_test.go +++ b/index_test.go @@ -7,7 +7,7 @@ import ( "io/ioutil" ) -func TestCreateRepoAndStage(t *testing.T) { +func createTestRepo(t *testing.T) *Repository { // figure out where we can create the test repo path, err := ioutil.TempDir("", "git2go") checkFatal(t, err) @@ -17,11 +17,17 @@ func TestCreateRepoAndStage(t *testing.T) { tmpfile := "README" err = ioutil.WriteFile(path + "/" + tmpfile, []byte("foo\n"), 0644) checkFatal(t, err) - defer os.RemoveAll(path) + + return repo +} + +func TestCreateRepoAndStage(t *testing.T) { + repo := createTestRepo(t) + defer os.RemoveAll(repo.Path()) idx, err := repo.Index() checkFatal(t, err) - err = idx.AddByPath(tmpfile) + err = idx.AddByPath("README") checkFatal(t, err) treeId, err := idx.WriteTree() checkFatal(t, err) @@ -42,5 +48,5 @@ func checkFatal(t *testing.T, err error) { t.Fatal() } - t.Fatalf("Fail at %v:%v", file, line) + t.Fatalf("Fail at %v:%v; %v", file, line, err) }