From fdfca50eb7ea4d551b6c5098dcc87796b25949a5 Mon Sep 17 00:00:00 2001 From: Mehmet Dogan <mehmet@dogan.io> Date: Wed, 31 Jan 2024 12:30:51 +0300 Subject: [PATCH] Automatically load credentials from .env file for testing --- .gitignore | 1 + go.mod | 5 ++++- go.sum | 2 ++ index_test.go | 10 ++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 450a649..3b2501d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .vscode tmp/ go.work.sum +.env diff --git a/go.mod b/go.mod index 41919f6..b77810e 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,10 @@ module github.com/upstash/vector-go go 1.20 -require github.com/stretchr/testify v1.8.4 +require ( + github.com/joho/godotenv v1.5.1 + github.com/stretchr/testify v1.8.4 +) require ( github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index fa4b6e6..26059cd 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= diff --git a/index_test.go b/index_test.go index 58612c7..2cc6174 100644 --- a/index_test.go +++ b/index_test.go @@ -1,13 +1,23 @@ package vector import ( + "errors" + "io/fs" "net/http" "os" "testing" + "github.com/joho/godotenv" "github.com/stretchr/testify/require" ) +func init() { + err := godotenv.Load() + if err != nil && !errors.Is(err, fs.ErrNotExist) { + panic(err) + } +} + func newTestClient() (*Index, error) { client := NewIndex( os.Getenv(UrlEnvProperty),