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

Function setupAddIntegrationTest

pkg/cli/add_integration_test.go:32–82  ·  view source on GitHub ↗

setupAddIntegrationTest creates a minimal test environment for add command: - temporary directory - git init (required by add command) - pre-built gh-aw binary Does NOT create .github/workflows - the add command should create it

(t *testing.T)

Source from the content-addressed store, hash-verified

30// - pre-built gh-aw binary
31// Does NOT create .github/workflows - the add command should create it
32func setupAddIntegrationTest(t *testing.T) *addIntegrationTestSetup {
33 t.Helper()
34
35 // Create a temporary directory for the test
36 tempDir, err := os.MkdirTemp("", "gh-aw-add-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 add command)
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 (required for some operations)
53 gitConfigName := exec.Command("git", "config", "user.name", "Test User")
54 gitConfigName.Dir = tempDir
55 _ = gitConfigName.Run() // Ignore errors - may already be configured globally
56
57 gitConfigEmail := exec.Command("git", "config", "user.email", "test@example.com")
58 gitConfigEmail.Dir = tempDir
59 _ = gitConfigEmail.Run() // Ignore errors - may already be configured globally
60
61 // Copy the pre-built binary to this test's temp directory
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 // Make the binary executable
67 err = os.Chmod(binaryPath, 0755)
68 require.NoError(t, err, "Failed to make binary executable")
69
70 // Setup cleanup function
71 cleanup := func() {
72 _ = os.Chdir(originalWd)
73 _ = os.RemoveAll(tempDir)
74 }
75
76 return &addIntegrationTestSetup{
77 tempDir: tempDir,
78 originalWd: originalWd,
79 binaryPath: binaryPath,
80 cleanup: cleanup,
81 }
82}
83
84// TestAddRemoteWorkflowFromURL tests adding a remote workflow via GitHub URL
85// This test requires GitHub authentication

Calls 2

CopyFileFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected