| 112 | } |
| 113 | |
| 114 | func 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 | |
| 147 | func TestExecGHContext(t *testing.T) { |
| 148 | tests := []struct { |