MCPcopy Create free account
hub / github.com/github/gh-aw / TestMain

Function TestMain

pkg/cli/compile_integration_test.go:28–97  ·  view source on GitHub ↗

TestMain builds the gh-aw binary once before running tests

(m *testing.M)

Source from the content-addressed store, hash-verified

26
27// TestMain builds the gh-aw binary once before running tests
28func TestMain(m *testing.M) {
29 // Get project root
30 wd, err := os.Getwd()
31 if err != nil {
32 panic("Failed to get current working directory: " + err.Error())
33 }
34 projectRoot = filepath.Join(wd, "..", "..")
35
36 // Prefer a pre-built binary when provided by CI to avoid rebuilding.
37 prebuiltBinaryPath := os.Getenv("GH_AW_INTEGRATION_BINARY")
38 if prebuiltBinaryPath != "" {
39 if _, err := os.Stat(prebuiltBinaryPath); err != nil {
40 panic("GH_AW_INTEGRATION_BINARY does not exist: " + err.Error())
41 }
42 globalBinaryPath = prebuiltBinaryPath
43 } else {
44 // Create temp directory for the shared binary
45 tempDir, err := os.MkdirTemp("", "gh-aw-integration-binary-*")
46 if err != nil {
47 panic("Failed to create temp directory for binary: " + err.Error())
48 }
49 binaryTempDir = tempDir
50
51 binaryName := "gh-aw"
52 if runtime.GOOS == "windows" {
53 binaryName = "gh-aw.exe"
54 }
55 globalBinaryPath = filepath.Join(tempDir, binaryName)
56
57 // Build the gh-aw binary
58 buildCmd := exec.Command("make", "build")
59 buildCmd.Dir = projectRoot
60 buildCmd.Stderr = os.Stderr
61 if err := buildCmd.Run(); err != nil {
62 panic("Failed to build gh-aw binary: " + err.Error())
63 }
64
65 // Copy binary to temp directory
66 srcBinary := filepath.Join(projectRoot, binaryName)
67 if err := fileutil.CopyFile(srcBinary, globalBinaryPath); err != nil {
68 panic("Failed to copy gh-aw binary to temp directory: " + err.Error())
69 }
70 }
71
72 if globalBinaryPath == "" {
73 panic("global binary path is empty")
74 }
75
76 // Make the binary executable
77 if err := os.Chmod(globalBinaryPath, 0755); err != nil {
78 panic("Failed to make binary executable: " + err.Error())
79 }
80
81 // Run the tests
82 code := m.Run()
83
84 // Clean up the shared binary directory
85 if binaryTempDir != "" {

Callers

nothing calls this directly

Calls 4

CopyFileFunction · 0.92
GetenvMethod · 0.80
ErrorMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected