Skip to content

Commit

Permalink
chore: fix unit tests and ensure their execution (#1316)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bacherfl committed May 23, 2024
1 parent 470d038 commit 25041c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions flagd/pkg/service/flag-evaluation/ofrep/ofrep_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
Expand All @@ -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 {
Expand All @@ -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
}

0 comments on commit 25041c0

Please sign in to comment.