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

Function initTestGitRepo

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

Source from the content-addressed store, hash-verified

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

Calls

no outgoing calls

Tested by

no test coverage detected