TestSetupGHCommand tests the core setupGHCommand function directly
(t *testing.T)
| 235 | |
| 236 | // TestSetupGHCommand tests the core setupGHCommand function directly |
| 237 | func TestSetupGHCommand(t *testing.T) { |
| 238 | tests := []struct { |
| 239 | name string |
| 240 | ghToken string |
| 241 | githubToken string |
| 242 | useContext bool |
| 243 | expectGHToken bool |
| 244 | expectValue string |
| 245 | }{ |
| 246 | { |
| 247 | name: "Without context, no tokens", |
| 248 | ghToken: "", |
| 249 | githubToken: "", |
| 250 | useContext: false, |
| 251 | expectGHToken: false, |
| 252 | expectValue: "", |
| 253 | }, |
| 254 | { |
| 255 | name: "With context, no tokens", |
| 256 | ghToken: "", |
| 257 | githubToken: "", |
| 258 | useContext: true, |
| 259 | expectGHToken: false, |
| 260 | expectValue: "", |
| 261 | }, |
| 262 | { |
| 263 | name: "Without context, GITHUB_TOKEN only", |
| 264 | ghToken: "", |
| 265 | githubToken: "github-token-123", |
| 266 | useContext: false, |
| 267 | expectGHToken: true, |
| 268 | expectValue: "github-token-123", |
| 269 | }, |
| 270 | { |
| 271 | name: "With context, GITHUB_TOKEN only", |
| 272 | ghToken: "", |
| 273 | githubToken: "github-token-456", |
| 274 | useContext: true, |
| 275 | expectGHToken: true, |
| 276 | expectValue: "github-token-456", |
| 277 | }, |
| 278 | } |
| 279 | |
| 280 | for _, tt := range tests { |
| 281 | t.Run(tt.name, func(t *testing.T) { |
| 282 | // Save original environment |
| 283 | originalGHToken, ghTokenWasSet := os.LookupEnv("GH_TOKEN") |
| 284 | originalGitHubToken, githubTokenWasSet := os.LookupEnv("GITHUB_TOKEN") |
| 285 | defer func() { |
| 286 | if ghTokenWasSet { |
| 287 | os.Setenv("GH_TOKEN", originalGHToken) |
| 288 | } else { |
| 289 | os.Unsetenv("GH_TOKEN") |
| 290 | } |
| 291 | if githubTokenWasSet { |
| 292 | os.Setenv("GITHUB_TOKEN", originalGitHubToken) |
| 293 | } else { |
| 294 | os.Unsetenv("GITHUB_TOKEN") |
nothing calls this directly
no test coverage detected