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

Function initTestGitRepo

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

Source from the content-addressed store, hash-verified

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

Calls

no outgoing calls

Tested by

no test coverage detected