From 12686644bbfc6e70d9c83a5e137adcaac50251a1 Mon Sep 17 00:00:00 2001 From: alallema Date: Thu, 9 Jun 2022 15:44:01 +0200 Subject: [PATCH] Modify dockerfile --- CONTRIBUTING.md | 2 +- Dockerfile | 1 - client_test.go | 4 ++-- main_test.go | 22 +++++++++++----------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d44859a4..9bbb0ad2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,7 +32,7 @@ You can set up your local environment natively or using `docker`, check out the Example of running all the checks with docker: ```bash -docker-compose run --rm package bash -c "golangci-lint run -v && go test -v ./..." +docker-compose run --rm package bash -c "golangci-lint run -v && go test -v" ``` To install dependencies: diff --git a/Dockerfile b/Dockerfile index 393cc21a..74b84a16 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,5 @@ COPY go.sum . COPY --from=golangci/golangci-lint:v1.42.0 /usr/bin/golangci-lint /usr/local/bin/golangci-lint -RUN go clean -cache RUN go mod download RUN go mod verify diff --git a/client_test.go b/client_test.go index a490091b..feef744a 100644 --- a/client_test.go +++ b/client_test.go @@ -1090,7 +1090,7 @@ func TestClient_GenerateTenantToken(t *testing.T) { args: args{ IndexUID: "TestGenerateTenantTokenWithoutApiKey", client: NewClient(ClientConfig{ - Host: getMeilisearchHost(), + Host: getenv("MEILISEARCH_HOST", "http://localhost:7700"), APIKey: "", }), APIKeyUID: GetPrivateUIDKey(), @@ -1173,7 +1173,7 @@ func TestClient_GenerateTenantToken(t *testing.T) { } client := NewClient(ClientConfig{ - Host: getMeilisearchHost(), + Host: getenv("MEILISEARCH_HOST", "http://localhost:7700"), APIKey: token, }) diff --git a/main_test.go b/main_test.go index 0fe1b5a7..c4f3e7cb 100644 --- a/main_test.go +++ b/main_test.go @@ -23,10 +23,10 @@ type docTestBooks struct { Year int `json:"year"` } -func getMeilisearchHost() string { - value := os.Getenv("MEILISEARCH_HOST") +func getenv(key, fallback string) string { + value := os.Getenv(key) if len(value) == 0 { - return "http://localhost:7700" + return fallback } return value } @@ -113,7 +113,7 @@ func GetPrivateUIDKey() (key string) { func SetUpEmptyIndex(index *IndexConfig) (resp *Index, err error) { client := NewClient(ClientConfig{ - Host: getMeilisearchHost(), + Host: getenv("MEILISEARCH_HOST", "http://localhost:7700"), APIKey: masterKey, }) task, err := client.CreateIndex(index) @@ -130,7 +130,7 @@ func SetUpEmptyIndex(index *IndexConfig) (resp *Index, err error) { func SetUpBasicIndex(indexUID string) { client := NewClient(ClientConfig{ - Host: getMeilisearchHost(), + Host: getenv("MEILISEARCH_HOST", "http://localhost:7700"), APIKey: masterKey, }) index := client.Index(indexUID) @@ -156,7 +156,7 @@ func SetUpBasicIndex(indexUID string) { func SetUpIndexWithNestedFields(indexUID string) { client := NewClient(ClientConfig{ - Host: getMeilisearchHost(), + Host: getenv("MEILISEARCH_HOST", "http://localhost:7700"), APIKey: masterKey, }) index := client.Index(indexUID) @@ -183,7 +183,7 @@ func SetUpIndexWithNestedFields(indexUID string) { func SetUpIndexForFaceting() { client := NewClient(ClientConfig{ - Host: getMeilisearchHost(), + Host: getenv("MEILISEARCH_HOST", "http://localhost:7700"), APIKey: masterKey, }) index := client.Index("indexUID") @@ -224,7 +224,7 @@ func SetUpIndexForFaceting() { var ( masterKey = "masterKey" defaultClient = NewClient(ClientConfig{ - Host: getMeilisearchHost(), + Host: getenv("MEILISEARCH_HOST", "http://localhost:7700"), APIKey: masterKey, }) defaultRankingRules = []string{ @@ -248,7 +248,7 @@ var ( ) var customClient = NewFastHTTPCustomClient(ClientConfig{ - Host: getMeilisearchHost(), + Host: getenv("MEILISEARCH_HOST", "http://localhost:7700"), APIKey: masterKey, }, &fasthttp.Client{ @@ -257,13 +257,13 @@ var customClient = NewFastHTTPCustomClient(ClientConfig{ }) var timeoutClient = NewClient(ClientConfig{ - Host: getMeilisearchHost(), + Host: getenv("MEILISEARCH_HOST", "http://localhost:7700"), APIKey: masterKey, Timeout: 1, }) var privateClient = NewClient(ClientConfig{ - Host: getMeilisearchHost(), + Host: getenv("MEILISEARCH_HOST", "http://localhost:7700"), APIKey: GetPrivateKey(), })