diff --git a/justfile b/justfile index c0bd6a7176..b38a38dccd 100644 --- a/justfile +++ b/justfile @@ -175,8 +175,10 @@ generate-mocks: # run to validate no mocks are missing validate-mocks: - ./scripts/validate-mocks.sh - + # delete and re-generate files to check nothing is different / missing + find . -name 'mock_*.go' -exec rm -f {} \; + just generate-mocks + git diff --exit-code #### TESTS #### diff --git a/resources/providers/gcplib/auth/credentials_test.go b/resources/providers/gcplib/auth/credentials_test.go index e060a579b0..e534ecb53e 100644 --- a/resources/providers/gcplib/auth/credentials_test.go +++ b/resources/providers/gcplib/auth/credentials_test.go @@ -172,8 +172,8 @@ func createServiceAccountFile(t *testing.T) *os.File { return f } -func mockGoogleAuthProvider(err error) *MockGoogleProviderAPI { - googleProviderAPI := &MockGoogleProviderAPI{} +func mockGoogleAuthProvider(err error) *MockGoogleAuthProviderAPI { + googleProviderAPI := &MockGoogleAuthProviderAPI{} on := googleProviderAPI.EXPECT().FindDefaultCredentials(mock.Anything) if err == nil { on.Return( diff --git a/resources/providers/gcplib/auth/mock_google_provider_api.go b/resources/providers/gcplib/auth/mock_google_provider_api.go deleted file mode 100644 index 75ea3865d0..0000000000 --- a/resources/providers/gcplib/auth/mock_google_provider_api.go +++ /dev/null @@ -1,109 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -// Code generated by mockery v2.24.0. DO NOT EDIT. - -package auth - -import ( - context "context" - - mock "github.com/stretchr/testify/mock" - google "golang.org/x/oauth2/google" -) - -// MockGoogleProviderAPI is an autogenerated mock type for the GoogleAuthProviderAPI type -type MockGoogleProviderAPI struct { - mock.Mock -} - -type MockGoogleProviderAPI_Expecter struct { - mock *mock.Mock -} - -func (_m *MockGoogleProviderAPI) EXPECT() *MockGoogleProviderAPI_Expecter { - return &MockGoogleProviderAPI_Expecter{mock: &_m.Mock} -} - -// FindDefaultCredentials provides a mock function with given fields: ctx -func (_m *MockGoogleProviderAPI) FindDefaultCredentials(ctx context.Context) (*google.Credentials, error) { - ret := _m.Called(ctx) - - var r0 *google.Credentials - var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (*google.Credentials, error)); ok { - return rf(ctx) - } - if rf, ok := ret.Get(0).(func(context.Context) *google.Credentials); ok { - r0 = rf(ctx) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*google.Credentials) - } - } - - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(ctx) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockGoogleProviderAPI_FindDefaultCredentials_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindDefaultCredentials' -type MockGoogleProviderAPI_FindDefaultCredentials_Call struct { - *mock.Call -} - -// FindDefaultCredentials is a helper method to define mock.On call -// - ctx context.Context -func (_e *MockGoogleProviderAPI_Expecter) FindDefaultCredentials(ctx interface{}) *MockGoogleProviderAPI_FindDefaultCredentials_Call { - return &MockGoogleProviderAPI_FindDefaultCredentials_Call{Call: _e.mock.On("FindDefaultCredentials", ctx)} -} - -func (_c *MockGoogleProviderAPI_FindDefaultCredentials_Call) Run(run func(ctx context.Context)) *MockGoogleProviderAPI_FindDefaultCredentials_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context)) - }) - return _c -} - -func (_c *MockGoogleProviderAPI_FindDefaultCredentials_Call) Return(_a0 *google.Credentials, _a1 error) *MockGoogleProviderAPI_FindDefaultCredentials_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *MockGoogleProviderAPI_FindDefaultCredentials_Call) RunAndReturn(run func(context.Context) (*google.Credentials, error)) *MockGoogleProviderAPI_FindDefaultCredentials_Call { - _c.Call.Return(run) - return _c -} - -type mockConstructorTestingTNewMockGoogleProviderAPI interface { - mock.TestingT - Cleanup(func()) -} - -// NewMockGoogleProviderAPI creates a new instance of MockGoogleProviderAPI. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewMockGoogleProviderAPI(t mockConstructorTestingTNewMockGoogleProviderAPI) *MockGoogleProviderAPI { - mock := &MockGoogleProviderAPI{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/scripts/validate-mocks.sh b/scripts/validate-mocks.sh deleted file mode 100755 index 1d2a14f260..0000000000 --- a/scripts/validate-mocks.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -## validate that all mocks exists and up to date -## the script will run the "mockery" command and we dont expect any changes - -mock="mockery --dir . --inpackage --all --with-expecter --case underscore --recursive" -eval $mock > /dev/null 2>&1 -mage AddLicenseHeaders > /dev/null 2>&1 - -diff="git diff --name-only | grep \".*/mock_.*.go\"" -diff_count=$(eval $diff | wc -l) - - -untracked="git ls-files --others --exclude-standard | grep \".*/mock_.*.go\"" -untracked_count=$(eval $untracked | wc -l) - -if [ $diff_count -eq 0 ] && [ $untracked_count -eq 0 ]; then - exit 0 -fi - - -echo "There are missing mocks for interfaces, please run \"$mock\" to update all mocks" -echo "Mock files:" -eval $diff -eval $untracked -exit 1