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 <florian.bacher@dynatrace.com>
This commit is contained in:
parent
470d038346
commit
25041c016a
7
Makefile
7
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue