Skip to content

Commit

Permalink
Create config file for Mockery instead of using explicit CLI flags in…
Browse files Browse the repository at this point in the history
… the Makefile (#5623)

## Which problem is this PR solving?
- Part of #5569

## Description of the changes
- Created the configuration file (.mockery.yaml) to match what was being
done by `make generate-mocks`
- Removed a few mock files from es/mocks that were defined within the
subpackage `client`. These files are still (auto) generated but within
es/client/mocks only

## How was this change tested?
- manually by running `mockery`
- by running `make test`

## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [ ] I have added unit tests for the new functionality
- [ ] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`

---------

Signed-off-by: jessica lourenco <jess.mailed@gmail.com>
Signed-off-by: jesslourenco <70455379+jesslourenco@users.noreply.github.com>
Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
  • Loading branch information
jesslourenco and yurishkuro committed Jun 13, 2024
1 parent d1a5107 commit 1830148
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 138 deletions.
20 changes: 20 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
with-expecter: false
disable-version-string: true
outpkg: "mocks"
dir: "{{.InterfaceDir}}/mocks/"
mockname: "{{.InterfaceName}}"
filename: "{{.InterfaceName}}.go"
packages:
github.com/jaegertracing/jaeger/pkg/es:
config:
all: true
github.com/jaegertracing/jaeger/storage/spanstore:
config:
all: true
github.com/jaegertracing/jaeger/proto-gen/storage_v1:
config:
all: true
github.com/jaegertracing/jaeger/pkg/es/client:
config:
all: true

4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,7 @@ init-submodules:
MOCKERY_FLAGS := --all --disable-version-string
.PHONY: generate-mocks
generate-mocks: $(MOCKERY)
$(MOCKERY) $(MOCKERY_FLAGS) --dir ./pkg/es/ --output ./pkg/es/mocks
$(MOCKERY) $(MOCKERY_FLAGS) --dir ./storage/spanstore/ --output ./storage/spanstore/mocks
$(MOCKERY) $(MOCKERY_FLAGS) --dir ./proto-gen/storage_v1/ --output ./proto-gen/storage_v1/mocks
$(MOCKERY)

.PHONY: certs
certs:
Expand Down
28 changes: 14 additions & 14 deletions cmd/es-rollover/app/init/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestIndexCreateIfNotExist(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
indexClient := &mocks.MockIndexAPI{}
indexClient := &mocks.IndexAPI{}
indexClient.On("CreateIndex", "jaeger-span").Return(test.returnErr)
err := createIndexIfNotExist(indexClient, "jaeger-span")
if test.containsError != "" {
Expand All @@ -91,13 +91,13 @@ func TestIndexCreateIfNotExist(t *testing.T) {
func TestRolloverAction(t *testing.T) {
tests := []struct {
name string
setupCallExpectations func(indexClient *mocks.MockIndexAPI, clusterClient *mocks.MockClusterAPI, ilmClient *mocks.MockILMAPI)
setupCallExpectations func(indexClient *mocks.IndexAPI, clusterClient *mocks.ClusterAPI, ilmClient *mocks.IndexManagementLifecycleAPI)
config Config
expectedErr error
}{
{
name: "Unsupported version",
setupCallExpectations: func(_ *mocks.MockIndexAPI, clusterClient *mocks.MockClusterAPI, _ *mocks.MockILMAPI) {
setupCallExpectations: func(_ *mocks.IndexAPI, clusterClient *mocks.ClusterAPI, _ *mocks.IndexManagementLifecycleAPI) {
clusterClient.On("Version").Return(uint(5), nil)
},
config: Config{
Expand All @@ -110,7 +110,7 @@ func TestRolloverAction(t *testing.T) {
},
{
name: "error getting version",
setupCallExpectations: func(_ *mocks.MockIndexAPI, clusterClient *mocks.MockClusterAPI, _ *mocks.MockILMAPI) {
setupCallExpectations: func(_ *mocks.IndexAPI, clusterClient *mocks.ClusterAPI, _ *mocks.IndexManagementLifecycleAPI) {
clusterClient.On("Version").Return(uint(0), errors.New("version error"))
},
expectedErr: errors.New("version error"),
Expand All @@ -123,7 +123,7 @@ func TestRolloverAction(t *testing.T) {
},
{
name: "ilm doesnt exist",
setupCallExpectations: func(_ *mocks.MockIndexAPI, clusterClient *mocks.MockClusterAPI, ilmClient *mocks.MockILMAPI) {
setupCallExpectations: func(_ *mocks.IndexAPI, clusterClient *mocks.ClusterAPI, ilmClient *mocks.IndexManagementLifecycleAPI) {
clusterClient.On("Version").Return(uint(7), nil)
ilmClient.On("Exists", "myilmpolicy").Return(false, nil)
},
Expand All @@ -138,7 +138,7 @@ func TestRolloverAction(t *testing.T) {
},
{
name: "fail get ilm policy",
setupCallExpectations: func(_ *mocks.MockIndexAPI, clusterClient *mocks.MockClusterAPI, ilmClient *mocks.MockILMAPI) {
setupCallExpectations: func(_ *mocks.IndexAPI, clusterClient *mocks.ClusterAPI, ilmClient *mocks.IndexManagementLifecycleAPI) {
clusterClient.On("Version").Return(uint(7), nil)
ilmClient.On("Exists", "myilmpolicy").Return(false, errors.New("error getting ilm policy"))
},
Expand All @@ -153,7 +153,7 @@ func TestRolloverAction(t *testing.T) {
},
{
name: "fail to create template",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, clusterClient *mocks.MockClusterAPI, _ *mocks.MockILMAPI) {
setupCallExpectations: func(indexClient *mocks.IndexAPI, clusterClient *mocks.ClusterAPI, _ *mocks.IndexManagementLifecycleAPI) {
clusterClient.On("Version").Return(uint(7), nil)
indexClient.On("CreateTemplate", mock.Anything, "jaeger-span").Return(errors.New("error creating template"))
},
Expand All @@ -167,7 +167,7 @@ func TestRolloverAction(t *testing.T) {
},
{
name: "fail to get jaeger indices",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, clusterClient *mocks.MockClusterAPI, _ *mocks.MockILMAPI) {
setupCallExpectations: func(indexClient *mocks.IndexAPI, clusterClient *mocks.ClusterAPI, _ *mocks.IndexManagementLifecycleAPI) {
clusterClient.On("Version").Return(uint(7), nil)
indexClient.On("CreateTemplate", mock.Anything, "jaeger-span").Return(nil)
indexClient.On("CreateIndex", "jaeger-span-archive-000001").Return(nil)
Expand All @@ -183,7 +183,7 @@ func TestRolloverAction(t *testing.T) {
},
{
name: "fail to create alias",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, clusterClient *mocks.MockClusterAPI, _ *mocks.MockILMAPI) {
setupCallExpectations: func(indexClient *mocks.IndexAPI, clusterClient *mocks.ClusterAPI, _ *mocks.IndexManagementLifecycleAPI) {
clusterClient.On("Version").Return(uint(7), nil)
indexClient.On("CreateTemplate", mock.Anything, "jaeger-span").Return(nil)
indexClient.On("CreateIndex", "jaeger-span-archive-000001").Return(nil)
Expand All @@ -203,7 +203,7 @@ func TestRolloverAction(t *testing.T) {
},
{
name: "create rollover index",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, clusterClient *mocks.MockClusterAPI, _ *mocks.MockILMAPI) {
setupCallExpectations: func(indexClient *mocks.IndexAPI, clusterClient *mocks.ClusterAPI, _ *mocks.IndexManagementLifecycleAPI) {
clusterClient.On("Version").Return(uint(7), nil)
indexClient.On("CreateTemplate", mock.Anything, "jaeger-span").Return(nil)
indexClient.On("CreateIndex", "jaeger-span-archive-000001").Return(nil)
Expand All @@ -223,7 +223,7 @@ func TestRolloverAction(t *testing.T) {
},
{
name: "create rollover index with ilm",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, clusterClient *mocks.MockClusterAPI, ilmClient *mocks.MockILMAPI) {
setupCallExpectations: func(indexClient *mocks.IndexAPI, clusterClient *mocks.ClusterAPI, ilmClient *mocks.IndexManagementLifecycleAPI) {
clusterClient.On("Version").Return(uint(7), nil)
indexClient.On("CreateTemplate", mock.Anything, "jaeger-span").Return(nil)
indexClient.On("CreateIndex", "jaeger-span-archive-000001").Return(nil)
Expand All @@ -247,9 +247,9 @@ func TestRolloverAction(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
indexClient := &mocks.MockIndexAPI{}
clusterClient := &mocks.MockClusterAPI{}
ilmClient := &mocks.MockILMAPI{}
indexClient := &mocks.IndexAPI{}
clusterClient := &mocks.ClusterAPI{}
ilmClient := &mocks.IndexManagementLifecycleAPI{}
initAction := Action{
Config: test.config,
IndicesClient: indexClient,
Expand Down
10 changes: 5 additions & 5 deletions cmd/es-rollover/app/lookback/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ func TestLookBackAction(t *testing.T) {

tests := []struct {
name string
setupCallExpectations func(indexClient *mocks.MockIndexAPI)
setupCallExpectations func(indexClient *mocks.IndexAPI)
config Config
expectedErr error
}{
{
name: "success",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI) {
setupCallExpectations: func(indexClient *mocks.IndexAPI) {
indexClient.On("GetJaegerIndices", "").Return(indices, nil)
indexClient.On("DeleteAlias", []client.Alias{
{
Expand All @@ -103,7 +103,7 @@ func TestLookBackAction(t *testing.T) {
},
{
name: "get indices error",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI) {
setupCallExpectations: func(indexClient *mocks.IndexAPI) {
indexClient.On("GetJaegerIndices", "").Return(indices, errors.New("get indices error"))
},
config: Config{
Expand All @@ -118,7 +118,7 @@ func TestLookBackAction(t *testing.T) {
},
{
name: "empty indices",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI) {
setupCallExpectations: func(indexClient *mocks.IndexAPI) {
indexClient.On("GetJaegerIndices", "").Return([]client.Index{}, nil)
},
config: Config{
Expand All @@ -137,7 +137,7 @@ func TestLookBackAction(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
indexClient := &mocks.MockIndexAPI{}
indexClient := &mocks.IndexAPI{}
lookbackAction := Action{
Config: test.config,
IndicesClient: indexClient,
Expand Down
16 changes: 8 additions & 8 deletions cmd/es-rollover/app/rollover/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestRolloverAction(t *testing.T) {
createAliasErr error
expectedError bool
indices []client.Index
setupCallExpectations func(indexClient *mocks.MockIndexAPI, t *testCase)
setupCallExpectations func(indexClient *mocks.IndexAPI, t *testCase)
}

tests := []testCase{
Expand All @@ -54,7 +54,7 @@ func TestRolloverAction(t *testing.T) {
conditions: "{\"max_age\": \"2d\"}",
expectedError: false,
indices: readIndices,
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, test *testCase) {
setupCallExpectations: func(indexClient *mocks.IndexAPI, test *testCase) {
indexClient.On("GetJaegerIndices", "").Return(test.indices, test.getJaegerIndicesErr)
indexClient.On("CreateAlias", aliasToCreate).Return(test.createAliasErr)
indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).Return(test.rolloverErr)
Expand All @@ -72,7 +72,7 @@ func TestRolloverAction(t *testing.T) {
},
},
},
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, test *testCase) {
setupCallExpectations: func(indexClient *mocks.IndexAPI, test *testCase) {
indexClient.On("GetJaegerIndices", "").Return(test.indices, test.getJaegerIndicesErr)
indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).Return(test.rolloverErr)
},
Expand All @@ -83,7 +83,7 @@ func TestRolloverAction(t *testing.T) {
expectedError: true,
getJaegerIndicesErr: errors.New("unable to get indices"),
indices: readIndices,
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, test *testCase) {
setupCallExpectations: func(indexClient *mocks.IndexAPI, test *testCase) {
indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).Return(test.rolloverErr)
indexClient.On("GetJaegerIndices", "").Return(test.indices, test.getJaegerIndicesErr)
},
Expand All @@ -94,7 +94,7 @@ func TestRolloverAction(t *testing.T) {
expectedError: true,
rolloverErr: errors.New("unable to rollover"),
indices: readIndices,
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, test *testCase) {
setupCallExpectations: func(indexClient *mocks.IndexAPI, test *testCase) {
indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).Return(test.rolloverErr)
},
},
Expand All @@ -104,7 +104,7 @@ func TestRolloverAction(t *testing.T) {
expectedError: true,
createAliasErr: errors.New("unable to create alias"),
indices: readIndices,
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, test *testCase) {
setupCallExpectations: func(indexClient *mocks.IndexAPI, test *testCase) {
indexClient.On("GetJaegerIndices", "").Return(test.indices, test.getJaegerIndicesErr)
indexClient.On("CreateAlias", aliasToCreate).Return(test.createAliasErr)
indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).Return(test.rolloverErr)
Expand All @@ -116,13 +116,13 @@ func TestRolloverAction(t *testing.T) {
unmarshalErrExpected: true,
createAliasErr: errors.New("unable to create alias"),
indices: readIndices,
setupCallExpectations: func(_ *mocks.MockIndexAPI, _ *testCase) {},
setupCallExpectations: func(_ *mocks.IndexAPI, _ *testCase) {},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
indexClient := &mocks.MockIndexAPI{}
indexClient := &mocks.IndexAPI{}

rolloverAction := Action{
Config: Config{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 0 additions & 28 deletions pkg/es/client/mocks/cluster_client.go

This file was deleted.

26 changes: 0 additions & 26 deletions pkg/es/client/mocks/ilm_client.go

This file was deleted.

54 changes: 0 additions & 54 deletions pkg/es/client/mocks/index_client.go

This file was deleted.

0 comments on commit 1830148

Please sign in to comment.