setupIntegrationTest creates a temporary directory and uses the pre-built gh-aw binary This is the equivalent of @Before in Java - common setup for all integration tests
(t *testing.T)
| 108 | // setupIntegrationTest creates a temporary directory and uses the pre-built gh-aw binary |
| 109 | // This is the equivalent of @Before in Java - common setup for all integration tests |
| 110 | func setupIntegrationTest(t *testing.T) *integrationTestSetup { |
| 111 | t.Helper() |
| 112 | |
| 113 | // Create a temporary directory for the test |
| 114 | tempDir, err := os.MkdirTemp("", "gh-aw-compile-integration-*") |
| 115 | if err != nil { |
| 116 | t.Fatalf("Failed to create temp directory: %v", err) |
| 117 | } |
| 118 | |
| 119 | // Save current working directory and change to temp directory |
| 120 | originalWd, err := os.Getwd() |
| 121 | if err != nil { |
| 122 | t.Fatalf("Failed to get current working directory: %v", err) |
| 123 | } |
| 124 | if err := os.Chdir(tempDir); err != nil { |
| 125 | t.Fatalf("Failed to change to temp directory: %v", err) |
| 126 | } |
| 127 | |
| 128 | // Copy the pre-built binary to this test's temp directory, preserving the |
| 129 | // executable extension (e.g. ".exe" on Windows) so the OS can execute it. |
| 130 | binaryName := "gh-aw" + filepath.Ext(globalBinaryPath) |
| 131 | binaryPath := filepath.Join(tempDir, binaryName) |
| 132 | if err := fileutil.CopyFile(globalBinaryPath, binaryPath); err != nil { |
| 133 | t.Fatalf("Failed to copy gh-aw binary to temp directory: %v", err) |
| 134 | } |
| 135 | |
| 136 | // Make the binary executable |
| 137 | if err := os.Chmod(binaryPath, 0755); err != nil { |
| 138 | t.Fatalf("Failed to make binary executable: %v", err) |
| 139 | } |
| 140 | |
| 141 | // Create .github/workflows directory |
| 142 | workflowsDir := ".github/workflows" |
| 143 | if err := os.MkdirAll(workflowsDir, 0755); err != nil { |
| 144 | t.Fatalf("Failed to create workflows directory: %v", err) |
| 145 | } |
| 146 | |
| 147 | // Setup cleanup function |
| 148 | cleanup := func() { |
| 149 | err := os.Chdir(originalWd) |
| 150 | if err != nil { |
| 151 | t.Fatalf("Failed to change back to original working directory: %v", err) |
| 152 | } |
| 153 | err = os.RemoveAll(tempDir) |
| 154 | if err != nil { |
| 155 | t.Fatalf("Failed to remove temp directory: %v", err) |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | return &integrationTestSetup{ |
| 160 | tempDir: tempDir, |
| 161 | originalWd: originalWd, |
| 162 | binaryPath: binaryPath, |
| 163 | workflowsDir: workflowsDir, |
| 164 | cleanup: cleanup, |
| 165 | } |
| 166 | } |
| 167 |
no test coverage detected