@@ -433,6 +433,82 @@ func TestNewClient(t *testing.T) {
433433
434434}
435435
436+ func TestCustomCredentialsWithGeminiAPI (t * testing.T ) {
437+ // This test verifies that custom credentials are properly used when creating a client
438+ // with the Gemini API backend.
439+ ctx := context .Background ()
440+
441+ // Create mock credentials
442+ mockCreds := & auth.Credentials {}
443+
444+ // Test case: Gemini API with custom credentials
445+ t .Run ("GeminiAPI with custom credentials" , func (t * testing.T ) {
446+ client , err := NewClient (ctx , & ClientConfig {
447+ Backend : BackendGeminiAPI ,
448+ APIKey : "test-api-key" ,
449+ Credentials : mockCreds ,
450+ })
451+ if err != nil {
452+ t .Fatalf ("Expected no error, got %v" , err )
453+ }
454+
455+ // Verify the credentials were correctly passed to the client config
456+ if client .clientConfig .Credentials != mockCreds {
457+ t .Errorf ("Credentials were not properly set in client config" )
458+ }
459+
460+ // Verify that HTTPClient is not nil (it should have been created)
461+ if client .clientConfig .HTTPClient == nil {
462+ t .Errorf ("Expected HTTPClient to be created, got nil" )
463+ }
464+ })
465+
466+ // Test case: Custom HTTP options with Gemini API
467+ t .Run ("GeminiAPI with custom HTTP options" , func (t * testing.T ) {
468+ customOptions := HTTPOptions {
469+ APIVersion : "custom-version" ,
470+ BaseURL : "https://custom-url.example.com/" ,
471+ }
472+
473+ client , err := NewClient (ctx , & ClientConfig {
474+ Backend : BackendGeminiAPI ,
475+ APIKey : "test-api-key" ,
476+ HTTPOptions : customOptions ,
477+ })
478+ if err != nil {
479+ t .Fatalf ("Expected no error, got %v" , err )
480+ }
481+
482+ // Verify HTTP options were correctly passed to the client config
483+ if client .clientConfig .HTTPOptions .APIVersion != customOptions .APIVersion {
484+ t .Errorf ("Expected APIVersion %q, got %q" , customOptions .APIVersion , client .clientConfig .HTTPOptions .APIVersion )
485+ }
486+ if client .clientConfig .HTTPOptions .BaseURL != customOptions .BaseURL {
487+ t .Errorf ("Expected BaseURL %q, got %q" , customOptions .BaseURL , client .clientConfig .HTTPOptions .BaseURL )
488+ }
489+ })
490+
491+ // Test case: Gemini API with custom credentials and HTTP client
492+ t .Run ("GeminiAPI with custom credentials and HTTP client" , func (t * testing.T ) {
493+ customHTTPClient := & http.Client {Timeout : 10 * time .Second }
494+
495+ client , err := NewClient (ctx , & ClientConfig {
496+ Backend : BackendGeminiAPI ,
497+ APIKey : "test-api-key" ,
498+ Credentials : mockCreds ,
499+ HTTPClient : customHTTPClient ,
500+ })
501+ if err != nil {
502+ t .Fatalf ("Expected no error, got %v" , err )
503+ }
504+
505+ // Verify custom HTTP client was used
506+ if client .clientConfig .HTTPClient != customHTTPClient {
507+ t .Errorf ("Expected custom HTTP client to be used" )
508+ }
509+ })
510+ }
511+
436512func TestClientConfigHTTPOptions (t * testing.T ) {
437513 tests := []struct {
438514 name string
0 commit comments