MCPcopy Index your code
hub / github.com/github/gh-aw / TestExecGHWithMultipleArgs

Function TestExecGHWithMultipleArgs

pkg/workflow/github_cli_test.go:114–145  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

112}
113
114func TestExecGHWithMultipleArgs(t *testing.T) {
115 // Save original environment
116 originalGHToken := os.Getenv("GH_TOKEN")
117 originalGitHubToken := os.Getenv("GITHUB_TOKEN")
118 defer func() {
119 os.Setenv("GH_TOKEN", originalGHToken)
120 os.Setenv("GITHUB_TOKEN", originalGitHubToken)
121 }()
122
123 // Set up test environment
124 os.Unsetenv("GH_TOKEN")
125 os.Setenv("GITHUB_TOKEN", "test-token")
126
127 // Test with multiple arguments
128 cmd := ExecGH("api", "repos/owner/repo/git/ref/tags/v1.0", "--jq", ".object.sha")
129
130 // Verify command
131 require.NotNil(t, cmd, "Command should not be nil")
132 assert.True(t, cmd.Path == "gh" || strings.HasSuffix(cmd.Path, "/gh"), "Expected command path to be 'gh', got: %s", cmd.Path)
133
134 // Verify all arguments are preserved
135 expectedArgs := []string{"gh", "api", "repos/owner/repo/git/ref/tags/v1.0", "--jq", ".object.sha"}
136 require.Len(t, cmd.Args, len(expectedArgs), "Expected %d args, got %d: %v", len(expectedArgs), len(cmd.Args), cmd.Args)
137
138 for i, expected := range expectedArgs {
139 assert.Equal(t, expected, cmd.Args[i], "Arg %d: expected %s, got %s", i, expected, cmd.Args[i])
140 }
141
142 // Verify environment contains GH_TOKEN
143 found := slices.Contains(cmd.Env, "GH_TOKEN=test-token")
144 assert.True(t, found, "Expected environment to contain GH_TOKEN=test-token")
145}
146
147func TestExecGHContext(t *testing.T) {
148 tests := []struct {

Callers

nothing calls this directly

Calls 3

GetenvMethod · 0.80
SetenvMethod · 0.80
ExecGHFunction · 0.70

Tested by

no test coverage detected