mirror of
https://github.com/x-motemen/ghq.git
synced 2026-09-10 07:26:27 -04:00
s/WithGitconfigFile/withGitConfig/ and fine adjustment
This commit is contained in:
parent
85a1380bed
commit
f1fa3955d7
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
13
url_test.go
13
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")
|
||||
|
|
|
|||
Loading…
Reference in a new issue