@@ -28,6 +28,7 @@ import (
2828 "testing"
2929
3030 "google.golang.org/api/iterator"
31+ "google.golang.org/genai"
3132)
3233
3334const defaultModel = "gemini-1.0-pro"
@@ -739,3 +740,49 @@ func printResponse(resp *GenerateContentResponse) {
739740 }
740741 fmt .Println ("---" )
741742}
743+
744+ func TestNewGenAIClient (t * testing.T ) {
745+ ctx := context .Background ()
746+ key := "SECRET_TOKEN"
747+ originalValue , exists := os .LookupEnv (key )
748+ os .Unsetenv (key )
749+ // Restore later
750+ t .Cleanup (func () {
751+ if exists {
752+ os .Setenv (key , originalValue )
753+ }
754+ })
755+ for _ , test := range []struct {
756+ name string
757+ cc * genai.ClientConfig
758+ }{
759+ {name : "nil config" , cc : nil },
760+ {name : "empty config" , cc : & genai.ClientConfig {}},
761+ } {
762+ t .Run (test .name , func (t * testing.T ) {
763+ client , err := NewGenAIClient (ctx , test .cc )
764+ if err != nil {
765+ t .Fatalf ("NewGenAIClient() failed unexpectedly, err: %v" , err )
766+ }
767+ if client == nil {
768+ t .Error ("client must not be nil" )
769+ }
770+ })
771+ }
772+ }
773+
774+ func TestNewGenAIClientErrors (t * testing.T ) {
775+ ctx := context .Background ()
776+ for _ , test := range []struct {
777+ name string
778+ cc * genai.ClientConfig
779+ }{
780+ {name : "gemini backend" , cc : & genai.ClientConfig {Backend : genai .BackendGeminiAPI }},
781+ } {
782+ t .Run (test .name , func (t * testing.T ) {
783+ if _ , err := NewGenAIClient (ctx , test .cc ); err == nil {
784+ t .Error ("wants error, but got nil" )
785+ }
786+ })
787+ }
788+ }
0 commit comments