| 410 | } |
| 411 | |
| 412 | func TestClient_AuthOptions(t *testing.T) { |
| 413 | t.Run("should accept GitHubToken option", func(t *testing.T) { |
| 414 | client := NewClient(&ClientOptions{ |
| 415 | GitHubToken: "gho_test_token", |
| 416 | }) |
| 417 | |
| 418 | if client.options.GitHubToken != "gho_test_token" { |
| 419 | t.Errorf("Expected GitHubToken to be 'gho_test_token', got %q", client.options.GitHubToken) |
| 420 | } |
| 421 | }) |
| 422 | |
| 423 | t.Run("should default UseLoggedInUser to nil when no GitHubToken", func(t *testing.T) { |
| 424 | client := NewClient(&ClientOptions{}) |
| 425 | |
| 426 | if client.options.UseLoggedInUser != nil { |
| 427 | t.Errorf("Expected UseLoggedInUser to be nil, got %v", client.options.UseLoggedInUser) |
| 428 | } |
| 429 | }) |
| 430 | |
| 431 | t.Run("should allow explicit UseLoggedInUser false", func(t *testing.T) { |
| 432 | client := NewClient(&ClientOptions{ |
| 433 | UseLoggedInUser: Bool(false), |
| 434 | }) |
| 435 | |
| 436 | if client.options.UseLoggedInUser == nil || *client.options.UseLoggedInUser != false { |
| 437 | t.Error("Expected UseLoggedInUser to be false") |
| 438 | } |
| 439 | }) |
| 440 | |
| 441 | t.Run("should allow explicit UseLoggedInUser true with GitHubToken", func(t *testing.T) { |
| 442 | client := NewClient(&ClientOptions{ |
| 443 | GitHubToken: "gho_test_token", |
| 444 | UseLoggedInUser: Bool(true), |
| 445 | }) |
| 446 | |
| 447 | if client.options.UseLoggedInUser == nil || *client.options.UseLoggedInUser != true { |
| 448 | t.Error("Expected UseLoggedInUser to be true") |
| 449 | } |
| 450 | }) |
| 451 | |
| 452 | t.Run("should panic when GitHubToken is used with URIConnection", func(t *testing.T) { |
| 453 | defer func() { |
| 454 | if r := recover(); r == nil { |
| 455 | t.Error("Expected panic for auth options with URIConnection") |
| 456 | } else { |
| 457 | matched, _ := regexp.MatchString("GitHubToken and UseLoggedInUser cannot be used with URIConnection", r.(string)) |
| 458 | if !matched { |
| 459 | t.Errorf("Expected panic message about auth options, got: %v", r) |
| 460 | } |
| 461 | } |
| 462 | }() |
| 463 | |
| 464 | NewClient(&ClientOptions{ |
| 465 | Connection: URIConnection{URL: "localhost:8080"}, |
| 466 | GitHubToken: "gho_test_token", |
| 467 | }) |
| 468 | }) |
| 469 | |