Skip to content

Commit

Permalink
Modify getEnv for getMeilisearchHost
Browse files Browse the repository at this point in the history
  • Loading branch information
alallema authored and brunoocasali committed Jul 28, 2022
1 parent 02321b8 commit 3204cfc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ func TestClient_GenerateTenantToken(t *testing.T) {
args: args{
IndexUID: "TestGenerateTenantTokenWithoutApiKey",
client: NewClient(ClientConfig{
Host: meilisearchHost,
Host: getMeilisearchHost(),
APIKey: "",
}),
APIKeyUID: GetPrivateUIDKey(),
Expand Down Expand Up @@ -1173,7 +1173,7 @@ func TestClient_GenerateTenantToken(t *testing.T) {
}

client := NewClient(ClientConfig{
Host: meilisearchHost,
Host: getMeilisearchHost(),
APIKey: token,
})

Expand Down
24 changes: 11 additions & 13 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/valyala/fasthttp"
)

var meilisearchHost = getenv("MEILISEARCH_HOST", "http://localhost:7700")

type docTest struct {
ID string `json:"id"`
Name string `json:"name"`
Expand All @@ -25,10 +23,10 @@ type docTestBooks struct {
Year int `json:"year"`
}

func getenv(key, fallback string) string {
value := os.Getenv(key)
func getMeilisearchHost() string {
value := os.Getenv("MEILISEARCH_HOST")
if len(value) == 0 {
return fallback
return "http://localhost:7700"
}
return value
}
Expand Down Expand Up @@ -115,7 +113,7 @@ func GetPrivateUIDKey() (key string) {

func SetUpEmptyIndex(index *IndexConfig) (resp *Index, err error) {
client := NewClient(ClientConfig{
Host: meilisearchHost,
Host: getMeilisearchHost(),
APIKey: masterKey,
})
task, err := client.CreateIndex(index)
Expand All @@ -132,7 +130,7 @@ func SetUpEmptyIndex(index *IndexConfig) (resp *Index, err error) {

func SetUpBasicIndex(indexUID string) {
client := NewClient(ClientConfig{
Host: meilisearchHost,
Host: getMeilisearchHost(),
APIKey: masterKey,
})
index := client.Index(indexUID)
Expand All @@ -158,7 +156,7 @@ func SetUpBasicIndex(indexUID string) {

func SetUpIndexWithNestedFields(indexUID string) {
client := NewClient(ClientConfig{
Host: meilisearchHost,
Host: getMeilisearchHost(),
APIKey: masterKey,
})
index := client.Index(indexUID)
Expand All @@ -185,7 +183,7 @@ func SetUpIndexWithNestedFields(indexUID string) {

func SetUpIndexForFaceting() {
client := NewClient(ClientConfig{
Host: meilisearchHost,
Host: getMeilisearchHost(),
APIKey: masterKey,
})
index := client.Index("indexUID")
Expand Down Expand Up @@ -226,7 +224,7 @@ func SetUpIndexForFaceting() {
var (
masterKey = "masterKey"
defaultClient = NewClient(ClientConfig{
Host: meilisearchHost,
Host: getMeilisearchHost(),
APIKey: masterKey,
})
defaultRankingRules = []string{
Expand All @@ -250,7 +248,7 @@ var (
)

var customClient = NewFastHTTPCustomClient(ClientConfig{
Host: meilisearchHost,
Host: getMeilisearchHost(),
APIKey: masterKey,
},
&fasthttp.Client{
Expand All @@ -259,13 +257,13 @@ var customClient = NewFastHTTPCustomClient(ClientConfig{
})

var timeoutClient = NewClient(ClientConfig{
Host: meilisearchHost,
Host: getMeilisearchHost(),
APIKey: masterKey,
Timeout: 1,
})

var privateClient = NewClient(ClientConfig{
Host: meilisearchHost,
Host: getMeilisearchHost(),
APIKey: GetPrivateKey(),
})

Expand Down

0 comments on commit 3204cfc

Please sign in to comment.