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

Function setupUpdateIntegrationTest

pkg/cli/update_integration_test.go:32–85  ·  view source on GitHub ↗

setupUpdateIntegrationTest creates a minimal test environment for update command: - temporary directory - git init (required by update command) - pre-built gh-aw binary - .github/workflows directory

(t *testing.T)

Source from the content-addressed store, hash-verified

30// - pre-built gh-aw binary
31// - .github/workflows directory
32func setupUpdateIntegrationTest(t *testing.T) *updateIntegrationTestSetup {
33 t.Helper()
34
35 // Create a temporary directory for the test
36 tempDir, err := os.MkdirTemp("", "gh-aw-update-integration-*")
37 require.NoError(t, err, "Failed to create temp directory")
38
39 // Save current working directory and change to temp directory
40 originalWd, err := os.Getwd()
41 require.NoError(t, err, "Failed to get current working directory")
42
43 err = os.Chdir(tempDir)
44 require.NoError(t, err, "Failed to change to temp directory")
45
46 // Initialize git repository (required by update command for merge detection)
47 gitInitCmd := exec.Command("git", "init")
48 gitInitCmd.Dir = tempDir
49 output, err := gitInitCmd.CombinedOutput()
50 require.NoError(t, err, "Failed to run git init: %s", string(output))
51
52 // Configure git user for commits
53 gitConfigName := exec.Command("git", "config", "user.name", "Test User")
54 gitConfigName.Dir = tempDir
55 _ = gitConfigName.Run()
56
57 gitConfigEmail := exec.Command("git", "config", "user.email", "test@example.com")
58 gitConfigEmail.Dir = tempDir
59 _ = gitConfigEmail.Run()
60
61 // Copy the pre-built binary
62 binaryPath := filepath.Join(tempDir, "gh-aw")
63 err = fileutil.CopyFile(globalBinaryPath, binaryPath)
64 require.NoError(t, err, "Failed to copy gh-aw binary to temp directory")
65
66 err = os.Chmod(binaryPath, 0755)
67 require.NoError(t, err, "Failed to make binary executable")
68
69 // Create .github/workflows directory
70 workflowsDir := filepath.Join(tempDir, ".github", "workflows")
71 require.NoError(t, os.MkdirAll(workflowsDir, 0755), "Failed to create workflows directory")
72
73 cleanup := func() {
74 _ = os.Chdir(originalWd)
75 _ = os.RemoveAll(tempDir)
76 }
77
78 return &updateIntegrationTestSetup{
79 tempDir: tempDir,
80 originalWd: originalWd,
81 binaryPath: binaryPath,
82 workflowsDir: workflowsDir,
83 cleanup: cleanup,
84 }
85}
86
87// skipWithoutGitHubAuth skips the test if GitHub authentication is not available
88func skipWithoutGitHubAuth(t *testing.T) {

Calls 2

CopyFileFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected