google / generative-ai-go

Go SDK for Google Generative AI
Apache License 2.0
488 stars 47 forks source link

genai: fix live test to not require flags #110

Closed eliben closed 2 months ago

eliben commented 2 months ago

Requiring flags precludes us from running go test ./... in this repository. The model name is open now so we can just place it as a constant in the file - it's no longer the only model used by the tests either, so it's less confusing. The API key can be provided with an env var like in the examples.

With this change, go test ./... now succeeds (the live test skip if the env var key is not set).

Also fix some test expectations to be more resilient.

eliben commented 2 months ago

Good stuff. One request: skip the live tests if testing.Short() is true. I sometimes use go test as a quick way to see if my code is basically ok. With this PR as it is, to make that work I'd have to clear my GEMINI_API_KEY env var, then restore it after. I'd prefer if I can just type go test -short.

Done