diff --git a/commands_test.go b/commands_test.go index c263c00..e0c3a17 100644 --- a/commands_test.go +++ b/commands_test.go @@ -217,13 +217,10 @@ func TestDoRoot(t *testing.T) { setup: func() func() { orig := os.Getenv(ghqrootEnv) os.Setenv(ghqrootEnv, "") - teardown, err := WithGitconfigFile(`[ghq] + teardown := withGitConfig(t, `[ghq] root = /path/to/ghqroot11 root = /path/to/ghqroot12 `) - if err != nil { - panic(err) - } return func() { os.Setenv(ghqrootEnv, orig) teardown() diff --git a/git_test.go b/git_test.go index b0d8af0..094243d 100644 --- a/git_test.go +++ b/git_test.go @@ -18,16 +18,11 @@ func TestGitConfigURL(t *testing.T) { t.Skip("Git does not have config --get-urlmatch feature") } - reset, err := WithGitconfigFile(` -[ghq "https://ghe.example.com/"] + defer withGitConfig(t, `[ghq "https://ghe.example.com/"] vcs = github [ghq "https://ghe.example.com/hg/"] vcs = hg -`) - if err != nil { - t.Fatal(err) - } - defer reset() +`)() testCases := []struct { name string diff --git a/helpers_test.go b/helpers_test.go index ab992c6..03b3659 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -9,10 +9,10 @@ import ( "testing" ) -func WithGitconfigFile(configContent string) (func(), error) { +func withGitConfig(t *testing.T, configContent string) func() { tmpdir, err := ioutil.TempDir("", "ghq-test") if err != nil { - return nil, err + t.Fatal(err) } tmpGitconfigFile := filepath.Join(tmpdir, "gitconfig") @@ -29,7 +29,7 @@ func WithGitconfigFile(configContent string) (func(), error) { return func() { os.Setenv("GIT_CONFIG", prevGitConfigEnv) os.RemoveAll(tmpdir) - }, nil + } } func mustParseURL(urlString string) *url.URL { diff --git a/url_test.go b/url_test.go index df4bfbf..4fec807 100644 --- a/url_test.go +++ b/url_test.go @@ -63,12 +63,8 @@ func TestNewURL(t *testing.T) { }, { name: "same name repository", setup: func() func() { - teardown, err := WithGitconfigFile(`[ghq] + return withGitConfig(t, `[ghq] completeUser = false`) - if err != nil { - panic(err) - } - return func() { teardown() } }, url: "peco", expect: "https://github.com/peco/peco", @@ -132,12 +128,7 @@ func TestNewURL_err(t *testing.T) { if got := fmt.Sprint(err); !strings.Contains(got, wantSub) { t.Errorf("newURL(%q) error = %q; want substring %q", invalidURL, got, wantSub) } - - reset, err := WithGitconfigFile(`[[[`) - if err != nil { - t.Fatal(err) - } - defer reset() + defer withGitConfig(t, `[[[`)() var exitError *exec.ExitError _, err = newURL("peco")