From 25041c016ae84afb01b8eb1e2b693aae3199a6ac Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 23 May 2024 22:25:47 +0200 Subject: [PATCH] chore: fix unit tests and ensure their execution (#1316) When running the tests locally I noticed that one of them was failing in the `flagd` submodule of the repo. After looking into this, I noticed that the unit tests are only executed for the `core` package in the PR checks - this is fixed with this PR --------- Signed-off-by: Florian Bacher --- Makefile | 7 +++++-- .../flag-evaluation/ofrep/ofrep_service_test.go | 17 ++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index e4b4bf2cc..8b4064819 100644 --- a/Makefile +++ b/Makefile @@ -40,10 +40,13 @@ build: workspace-init # default to flagd build-flagd: go build -ldflags "-X main.version=dev -X main.commit=$$(git rev-parse --short HEAD) -X main.date=$$(date +%FT%TZ)" -o ./bin/flagd ./flagd .PHONY: test -test: # default to core - make test-core +test: test-core test-flagd test-flagd-proxy test-core: go test -race -covermode=atomic -cover -short ./core/pkg/... -coverprofile=core-coverage.out +test-flagd: + go test -race -covermode=atomic -cover -short ./flagd/pkg/... -coverprofile=flagd-coverage.out +test-flagd-proxy: + go test -race -covermode=atomic -cover -short ./flagd-proxy/pkg/... -coverprofile=flagd-proxy-coverage.out flagd-integration-test: # dependent on ./bin/flagd start -f file:test-harness/flags/testing-flags.json -f file:test-harness/flags/custom-ops.json -f file:test-harness/flags/evaluator-refs.json -f file:test-harness/flags/zero-flags.json go test -cover ./test/integration $(ARGS) run: # default to flagd diff --git a/flagd/pkg/service/flag-evaluation/ofrep/ofrep_service_test.go b/flagd/pkg/service/flag-evaluation/ofrep/ofrep_service_test.go index 6bf479c58..c05c09711 100644 --- a/flagd/pkg/service/flag-evaluation/ofrep/ofrep_service_test.go +++ b/flagd/pkg/service/flag-evaluation/ofrep/ofrep_service_test.go @@ -5,10 +5,10 @@ import ( "context" "fmt" "net/http" - "net/url" "testing" "time" + "github.com/open-feature/flagd/core/pkg/evaluator" mock "github.com/open-feature/flagd/core/pkg/evaluator/mock" "github.com/open-feature/flagd/core/pkg/logger" "go.uber.org/mock/gomock" @@ -18,6 +18,8 @@ import ( func Test_OfrepServiceStartStop(t *testing.T) { port := 18282 eval := mock.NewMockIEvaluator(gomock.NewController(t)) + + eval.EXPECT().ResolveAllValues(gomock.Any(), gomock.Any(), gomock.Any()).Return([]evaluator.AnyValue{}) cfg := SvcConfiguration{ Logger: logger.NewLogger(nil, false), Port: uint16(port), @@ -39,10 +41,8 @@ func Test_OfrepServiceStartStop(t *testing.T) { // allow time for server startup <-time.After(2 * time.Second) - path, err := url.JoinPath(fmt.Sprintf("http://localhost:%d", port), bulkEvaluation) - if err != nil { - t.Fatalf("error creating the path: %v", err) - } + path := fmt.Sprintf("http://localhost:%d/ofrep/v1/evaluate/flags", port) + // validate response response, err := tryResponse(http.MethodPost, path, []byte{}) if err != nil { @@ -69,9 +69,12 @@ func tryResponse(method string, uri string, payload []byte) (int, error) { request, err := http.NewRequest(method, uri, bytes.NewReader(payload)) if err != nil { - return 0, fmt.Errorf("error forming the request: %v", err) + return 0, fmt.Errorf("error forming the request: %w", err) } rsp, err := client.Do(request) - return rsp.StatusCode, fmt.Errorf("error from the request: %v", err) + if err != nil { + return 0, fmt.Errorf("error from the request: %w", err) + } + return rsp.StatusCode, nil }