Skip to content

Commit f675d01

Browse files
authored
feat: Make Mocks Exportable (#341)
Signed-off-by: Jordan Blacker <[email protected]>
1 parent 640448d commit f675d01

File tree

14 files changed

+170
-151
lines changed

14 files changed

+170
-151
lines changed

.github/workflows/pr-checks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ jobs:
5454
path: ~/go/pkg/mod
5555
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }}
5656
- name: Run unit tests
57-
run: go test -race -short -coverpkg=./... -coverprofile=coverage-unit.out -covermode=atomic ./...
57+
run: go test -tags testtools -race -short -coverpkg=./... -coverprofile=coverage-unit.out -covermode=atomic ./...
5858
- name: Run e2e tests
59-
run: go test -race -coverpkg=./... -coverprofile=coverage-e2e.out -covermode=atomic ./e2e/...
59+
run: go test -tags testtools -race -coverpkg=./... -coverprofile=coverage-e2e.out -covermode=atomic ./e2e/...
6060
- name: Upload coverage to Codecov (unit)
6161
uses: codecov/codecov-action@ad3126e916f78f00edff4ed0317cf185271ccc2d # v5.4.2
6262
with:

Makefile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
.PHONY: mockgen test lint e2e-test
22
mockgen:
3-
mockgen -source=openfeature/provider.go -destination=openfeature/provider_mock_test.go -package=openfeature
4-
mockgen -source=openfeature/hooks.go -destination=openfeature/hooks_mock_test.go -package=openfeature
5-
mockgen -source=openfeature/interfaces.go -destination=openfeature/interfaces_mock_test.go -package=openfeature
3+
go install go.uber.org/mock/mockgen@latest
4+
mockgen -source=openfeature/provider.go -destination=openfeature/provider_mock.go -package=openfeature
5+
mockgen -source=openfeature/hooks.go -destination=openfeature/hooks_mock.go -package=openfeature
6+
mockgen -source=openfeature/interfaces.go -destination=openfeature/interfaces_mock.go -package=openfeature
7+
sed -i.old $$'1s;^;//go:build testtools\\n\\n;' openfeature/*_mock.go
8+
rm -f openfeature/*_mock.go.old
9+
610
test:
7-
go test --short -cover ./...
11+
go test --short -tags testtools -cover ./...
812
e2e-test:
9-
git submodule update --init --recursive && go test -race -cover ./e2e/...
13+
git submodule update --init --recursive && go test -tags testtools -race -cover ./e2e/...
1014
lint:
1115
go install -v github.com/golangci/golangci-lint/cmd/[email protected]
12-
${GOPATH}/bin/golangci-lint run --deadline=3m --timeout=3m ./... # Run linters
16+
${GOPATH}/bin/golangci-lint run --build-tags testtools --deadline=3m --timeout=3m ./... # Run linters

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,13 @@ for name, tt := range tests {
500500
}
501501
```
502502

503+
### Mocks
504+
505+
Mocks are also available for testing purposes for all interfaces within the OpenFeature SDK. These are primarily
506+
intended for internal use for testing the SDK, but have been exported to ease the testing burden for any extensions
507+
or custom components (e.g. hooks & providers). These mocks are not include in builds by default. The build tag
508+
`testtools` must be used to have the mocks included in builds.
509+
503510
<!-- x-hide-in-docs-start -->
504511
## ⭐️ Support the project
505512

codecov.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ignore:
2+
- "openfeature/*_mock.go"

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.21
55
require (
66
github.com/cucumber/godog v0.15.0
77
github.com/go-logr/logr v1.4.2
8-
github.com/golang/mock v1.6.0
8+
go.uber.org/mock v0.4.0
99
golang.org/x/text v0.22.0
1010
)
1111

@@ -17,5 +17,4 @@ require (
1717
github.com/hashicorp/go-memdb v1.3.4 // indirect
1818
github.com/hashicorp/golang-lru v1.0.2 // indirect
1919
github.com/spf13/pflag v1.0.5 // indirect
20-
github.com/stretchr/testify v1.8.4 // indirect
2120
)

go.sum

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRx
1515
github.com/gofrs/uuid v4.3.1+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
1616
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
1717
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
18-
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
19-
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
2018
github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
2119
github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc=
2220
github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
@@ -45,34 +43,12 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
4543
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
4644
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
4745
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
46+
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
4847
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
49-
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
50-
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
51-
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
52-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
53-
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
54-
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
55-
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
56-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
57-
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
58-
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
59-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
60-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
61-
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
62-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
63-
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
64-
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
65-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
66-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
67-
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
48+
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
49+
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
6850
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
6951
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
70-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
71-
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
72-
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
73-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
74-
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
75-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
7652
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
7753
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
7854
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

openfeature/client_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ package openfeature
33
import (
44
"context"
55
"errors"
6+
"go.uber.org/mock/gomock"
67
"math"
78
"reflect"
89
"testing"
910
"time"
10-
11-
"github.com/golang/mock/gomock"
1211
)
1312

1413
type clientMocks struct {

openfeature/evaluation_context_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"reflect"
66
"testing"
77

8-
"github.com/golang/mock/gomock"
98
"github.com/open-feature/go-sdk/openfeature/internal"
9+
"go.uber.org/mock/gomock"
1010
)
1111

1212
// The `evaluation context` structure MUST define an optional `targeting key` field of type string,

openfeature/hooks_mock_test.go renamed to openfeature/hooks_mock.go

Lines changed: 15 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openfeature/hooks_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ package openfeature
33
import (
44
"context"
55
"errors"
6+
"go.uber.org/mock/gomock"
67
"reflect"
78
"testing"
89
"time"
910

10-
"github.com/golang/mock/gomock"
11-
1211
"golang.org/x/text/cases"
1312
"golang.org/x/text/language"
1413
)

0 commit comments

Comments
 (0)