MCPcopy Create free account
hub / github.com/alibaba/open-code-review / initTestGitRepo

Function initTestGitRepo

cmd/opencodereview/git_test.go:11–38  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func initTestGitRepo(t *testing.T) string {
12 t.Helper()
13 dir := t.TempDir()
14 cmds := [][]string{
15 {"git", "-C", dir, "init"},
16 {"git", "-C", dir, "config", "user.email", "test@test.com"},
17 {"git", "-C", dir, "config", "user.name", "Test"},
18 }
19 for _, args := range cmds {
20 cmd := exec.Command(args[0], args[1:]...)
21 if out, err := cmd.CombinedOutput(); err != nil {
22 t.Fatalf("git init: %v: %s", err, out)
23 }
24 }
25 f := filepath.Join(dir, "README.md")
26 if err := os.WriteFile(f, []byte("hello"), 0o644); err != nil {
27 t.Fatalf("write README: %v", err)
28 }
29 cmd := exec.Command("git", "-C", dir, "add", ".")
30 if out, err := cmd.CombinedOutput(); err != nil {
31 t.Fatalf("git add: %v: %s", err, out)
32 }
33 cmd = exec.Command("git", "-C", dir, "commit", "-m", "initial commit")
34 if out, err := cmd.CombinedOutput(); err != nil {
35 t.Fatalf("git commit: %v: %s", err, out)
36 }
37 return dir
38}
39
40func TestRunGitCmd_Success(t *testing.T) {
41 dir := initTestGitRepo(t)

Calls

no outgoing calls

Tested by

no test coverage detected