提交 01f54d69 作者: Brian Tiger Chow

refactor(fsrepo.test) use TempDir

@jbenet
上级 3eafb3e5
package fsrepo package fsrepo
import ( import (
"os" "io/ioutil"
"path"
"testing" "testing"
"github.com/jbenet/go-ipfs/repo/config" "github.com/jbenet/go-ipfs/repo/config"
) )
// NB: These tests cannot be run in parallel func testRepoPath(p string, t *testing.T) string {
name, err := ioutil.TempDir("", p)
func init() { if err != nil {
// ensure tests begin in clean state t.Fatal(err)
os.RemoveAll(testRepoDir) }
} return name
const testRepoDir = "./fsrepo_test/repos"
func testRepoPath(p string) string {
return path.Join(testRepoDir, p)
} }
func TestCannotRemoveIfOpen(t *testing.T) { func TestCannotRemoveIfOpen(t *testing.T) {
path := testRepoPath("TestCannotRemoveIfOpen") path := testRepoPath("TestCannotRemoveIfOpen", t)
AssertNil(Init(path, &config.Config{}), t, "should initialize successfully") AssertNil(Init(path, &config.Config{}), t, "should initialize successfully")
r := At(path) r := At(path)
AssertNil(r.Open(), t) AssertNil(r.Open(), t)
...@@ -32,8 +26,8 @@ func TestCannotRemoveIfOpen(t *testing.T) { ...@@ -32,8 +26,8 @@ func TestCannotRemoveIfOpen(t *testing.T) {
} }
func TestCanManageReposIndependently(t *testing.T) { func TestCanManageReposIndependently(t *testing.T) {
pathA := testRepoPath("a") pathA := testRepoPath("a", t)
pathB := testRepoPath("b") pathB := testRepoPath("b", t)
t.Log("initialize two repos") t.Log("initialize two repos")
AssertNil(Init(pathA, &config.Config{}), t, "should initialize successfully") AssertNil(Init(pathA, &config.Config{}), t, "should initialize successfully")
......
This directory is used to store FSRepos generated during go tests.
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论