gitannex: reduce subprocess launches in end to end test setup
Write the git configuration for each test's fake home directory as a file instead of running three "git config --global" commands, and drop the "git annex version" invocation from repository setup. This removes four subprocess launches from each of the fifteen test cases.
This commit is contained in:
@@ -169,14 +169,17 @@ func (e *e2eTestingContext) runInRepo(t *testing.T, command string, args ...stri
|
|||||||
require.NoError(t, err, fmt.Sprintf("+ %s %v failed:\n%s\n", command, args, buf))
|
require.NoError(t, err, fmt.Sprintf("+ %s %v failed:\n%s\n", command, args, buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
// createGitRepo creates an empty git repository in the ephemeral repo
|
// createGitRepo creates an empty git-annex repository in the ephemeral repo
|
||||||
// directory. It makes "global" config changes that are ultimately scoped to the
|
// directory. The "global" git config it writes is ultimately scoped to the
|
||||||
// calling test thanks to runInRepo() overriding the HOME environment variable.
|
// calling test thanks to runInRepo() overriding the HOME environment variable.
|
||||||
func (e *e2eTestingContext) createGitRepo(t *testing.T) {
|
func (e *e2eTestingContext) createGitRepo(t *testing.T) {
|
||||||
e.runInRepo(t, "git", "annex", "version")
|
gitConfig := "[user]\n" +
|
||||||
e.runInRepo(t, "git", "config", "--global", "user.name", "User Name")
|
"\tname = User Name\n" +
|
||||||
e.runInRepo(t, "git", "config", "--global", "user.email", "user@example.com")
|
"\temail = user@example.com\n" +
|
||||||
e.runInRepo(t, "git", "config", "--global", "init.defaultBranch", "main")
|
"[init]\n" +
|
||||||
|
"\tdefaultBranch = main\n"
|
||||||
|
require.NoError(t, os.WriteFile(
|
||||||
|
filepath.Join(e.homeDir, ".gitconfig"), []byte(gitConfig), 0600))
|
||||||
e.runInRepo(t, "git", "init")
|
e.runInRepo(t, "git", "init")
|
||||||
e.runInRepo(t, "git", "annex", "init")
|
e.runInRepo(t, "git", "annex", "init")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user