MCPcopy Index your code
hub / github.com/cli/cli / createMockExecutable

Function createMockExecutable

git/command_test.go:68–91  ·  view source on GitHub ↗
(t *testing.T, stdout string, stderr string, exitCode int)

Source from the content-addressed store, hash-verified

66}
67
68func createMockExecutable(t *testing.T, stdout string, stderr string, exitCode int) string {
69 tmpDir := t.TempDir()
70 sourcePath := filepath.Join(tmpDir, "main.go")
71 binaryPath := filepath.Join(tmpDir, "mockexec")
72 if runtime.GOOS == "windows" {
73 binaryPath += ".exe"
74 }
75
76 // Create Go source
77 source := buildCommandSourceCode(exitCode, stdout, stderr)
78
79 // Write source file
80 if err := os.WriteFile(sourcePath, []byte(source), 0600); err != nil {
81 t.Fatal(err)
82 }
83
84 // Compile
85 cmd := exec.Command("go", "build", "-o", binaryPath, sourcePath)
86 if out, err := cmd.CombinedOutput(); err != nil {
87 t.Fatalf("failed to compile: %v\n%s", err, out)
88 }
89 return binaryPath
90
91}
92
93func buildCommandSourceCode(exitCode int, stdout, stderr string) string {
94 return fmt.Sprintf(`package main

Callers 1

TestOutputFunction · 0.85

Calls 3

buildCommandSourceCodeFunction · 0.85
JoinMethod · 0.80
CommandMethod · 0.80

Tested by

no test coverage detected