diff --git a/agent/cache-types/mock_Agent.go b/agent/cache-types/mock_Agent.go deleted file mode 100644 index ec3ba4031b..0000000000 --- a/agent/cache-types/mock_Agent.go +++ /dev/null @@ -1,92 +0,0 @@ -// Code generated by mockery v2.11.0. DO NOT EDIT. - -package cachetype - -import ( - local "github.com/hashicorp/consul/agent/local" - memdb "github.com/hashicorp/go-memdb" - - mock "github.com/stretchr/testify/mock" - - structs "github.com/hashicorp/consul/agent/structs" - - testing "testing" - - time "time" -) - -// MockAgent is an autogenerated mock type for the Agent type -type MockAgent struct { - mock.Mock -} - -// LocalBlockingQuery provides a mock function with given fields: alwaysBlock, hash, wait, fn -func (_m *MockAgent) LocalBlockingQuery(alwaysBlock bool, hash string, wait time.Duration, fn func(memdb.WatchSet) (string, interface{}, error)) (string, interface{}, error) { - ret := _m.Called(alwaysBlock, hash, wait, fn) - - var r0 string - if rf, ok := ret.Get(0).(func(bool, string, time.Duration, func(memdb.WatchSet) (string, interface{}, error)) string); ok { - r0 = rf(alwaysBlock, hash, wait, fn) - } else { - r0 = ret.Get(0).(string) - } - - var r1 interface{} - if rf, ok := ret.Get(1).(func(bool, string, time.Duration, func(memdb.WatchSet) (string, interface{}, error)) interface{}); ok { - r1 = rf(alwaysBlock, hash, wait, fn) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(interface{}) - } - } - - var r2 error - if rf, ok := ret.Get(2).(func(bool, string, time.Duration, func(memdb.WatchSet) (string, interface{}, error)) error); ok { - r2 = rf(alwaysBlock, hash, wait, fn) - } else { - r2 = ret.Error(2) - } - - return r0, r1, r2 -} - -// LocalState provides a mock function with given fields: -func (_m *MockAgent) LocalState() *local.State { - ret := _m.Called() - - var r0 *local.State - if rf, ok := ret.Get(0).(func() *local.State); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*local.State) - } - } - - return r0 -} - -// ServiceHTTPBasedChecks provides a mock function with given fields: id -func (_m *MockAgent) ServiceHTTPBasedChecks(id structs.ServiceID) []structs.CheckType { - ret := _m.Called(id) - - var r0 []structs.CheckType - if rf, ok := ret.Get(0).(func(structs.ServiceID) []structs.CheckType); ok { - r0 = rf(id) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]structs.CheckType) - } - } - - return r0 -} - -// NewMockAgent creates a new instance of MockAgent. It also registers a cleanup function to assert the mocks expectations. -func NewMockAgent(t testing.TB) *MockAgent { - mock := &MockAgent{} - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/agent/cache-types/mock_RPC.go b/agent/cache-types/mock_RPC.go index 67052f3549..059623f04a 100644 --- a/agent/cache-types/mock_RPC.go +++ b/agent/cache-types/mock_RPC.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.11.0. DO NOT EDIT. +// Code generated by mockery v2.12.2. DO NOT EDIT. package cachetype @@ -27,9 +27,10 @@ func (_m *MockRPC) RPC(method string, args interface{}, reply interface{}) error return r0 } -// NewMockRPC creates a new instance of MockRPC. It also registers a cleanup function to assert the mocks expectations. +// NewMockRPC creates a new instance of MockRPC. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. func NewMockRPC(t testing.TB) *MockRPC { mock := &MockRPC{} + mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/agent/cache-types/mock_TrustBundleLister_test.go b/agent/cache-types/mock_TrustBundleLister_test.go new file mode 100644 index 0000000000..aeb4ac88f9 --- /dev/null +++ b/agent/cache-types/mock_TrustBundleLister_test.go @@ -0,0 +1,60 @@ +// Code generated by mockery v2.12.2. DO NOT EDIT. + +package cachetype + +import ( + context "context" + + grpc "google.golang.org/grpc" + + mock "github.com/stretchr/testify/mock" + + pbpeering "github.com/hashicorp/consul/proto/pbpeering" + + testing "testing" +) + +// MockTrustBundleLister is an autogenerated mock type for the TrustBundleLister type +type MockTrustBundleLister struct { + mock.Mock +} + +// TrustBundleListByService provides a mock function with given fields: ctx, in, opts +func (_m *MockTrustBundleLister) TrustBundleListByService(ctx context.Context, in *pbpeering.TrustBundleListByServiceRequest, opts ...grpc.CallOption) (*pbpeering.TrustBundleListByServiceResponse, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *pbpeering.TrustBundleListByServiceResponse + if rf, ok := ret.Get(0).(func(context.Context, *pbpeering.TrustBundleListByServiceRequest, ...grpc.CallOption) *pbpeering.TrustBundleListByServiceResponse); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*pbpeering.TrustBundleListByServiceResponse) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, *pbpeering.TrustBundleListByServiceRequest, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewMockTrustBundleLister creates a new instance of MockTrustBundleLister. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. +func NewMockTrustBundleLister(t testing.TB) *MockTrustBundleLister { + mock := &MockTrustBundleLister{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/agent/cache-types/rpc.go b/agent/cache-types/rpc.go index ebf0925aff..cc0a4a8e54 100644 --- a/agent/cache-types/rpc.go +++ b/agent/cache-types/rpc.go @@ -1,10 +1,9 @@ package cachetype -//go:generate mockery --all --inpackage - // RPC is an interface that an RPC client must implement. This is a helper // interface that is implemented by the agent delegate so that Type // implementations can request RPC access. +//go:generate mockery --name RPC --inpackage type RPC interface { RPC(method string, args interface{}, reply interface{}) error } diff --git a/agent/cache-types/testing.go b/agent/cache-types/testing.go index 461d8948b7..c033a022d9 100644 --- a/agent/cache-types/testing.go +++ b/agent/cache-types/testing.go @@ -4,13 +4,13 @@ import ( "reflect" "time" - "github.com/mitchellh/go-testing-interface" + testinf "github.com/mitchellh/go-testing-interface" "github.com/hashicorp/consul/agent/cache" ) // TestRPC returns a mock implementation of the RPC interface. -func TestRPC(t testing.T) *MockRPC { +func TestRPC(t testinf.T) *MockRPC { // This function is relatively useless but this allows us to perhaps // perform some initialization later. return &MockRPC{} @@ -21,7 +21,7 @@ func TestRPC(t testing.T) *MockRPC { // Errors will show up as an error type on the resulting channel so a // type switch should be used. func TestFetchCh( - t testing.T, + t testinf.T, typ cache.Type, opts cache.FetchOptions, req cache.Request, @@ -43,7 +43,7 @@ func TestFetchCh( // TestFetchChResult tests that the result from TestFetchCh matches // within a reasonable period of time (it expects it to be "immediate" but // waits some milliseconds). -func TestFetchChResult(t testing.T, ch <-chan interface{}, expected interface{}) { +func TestFetchChResult(t testinf.T, ch <-chan interface{}, expected interface{}) { t.Helper() select { diff --git a/agent/cache-types/trust_bundle.go b/agent/cache-types/trust_bundle.go index 6539a1ae87..16b8f204bc 100644 --- a/agent/cache-types/trust_bundle.go +++ b/agent/cache-types/trust_bundle.go @@ -4,9 +4,10 @@ import ( "context" "fmt" + "google.golang.org/grpc" + "github.com/hashicorp/consul/agent/cache" "github.com/hashicorp/consul/proto/pbpeering" - "google.golang.org/grpc" ) // Recommended name for registration. @@ -19,7 +20,7 @@ type TrustBundle struct { Client TrustBundleReader } -//go:generate mockery --name TrustBundleReader --inpackage --testonly +//go:generate mockery --name TrustBundleReader --inpackage --filename mock_TrustBundleReader_test.go type TrustBundleReader interface { TrustBundleRead( ctx context.Context, in *pbpeering.TrustBundleReadRequest, opts ...grpc.CallOption, diff --git a/agent/cache-types/trust_bundles.go b/agent/cache-types/trust_bundles.go index f4cd2d3c18..5b4bbcc136 100644 --- a/agent/cache-types/trust_bundles.go +++ b/agent/cache-types/trust_bundles.go @@ -4,9 +4,10 @@ import ( "context" "fmt" + "google.golang.org/grpc" + "github.com/hashicorp/consul/agent/cache" "github.com/hashicorp/consul/proto/pbpeering" - "google.golang.org/grpc" ) // Recommended name for registration. @@ -19,6 +20,7 @@ type TrustBundles struct { Client TrustBundleLister } +//go:generate mockery --name TrustBundleLister --inpackage --filename mock_TrustBundleLister_test.go type TrustBundleLister interface { TrustBundleListByService( ctx context.Context, in *pbpeering.TrustBundleListByServiceRequest, opts ...grpc.CallOption, diff --git a/agent/cache-types/trust_bundles_test.go b/agent/cache-types/trust_bundles_test.go index 451508b0d0..d5fbd6f501 100644 --- a/agent/cache-types/trust_bundles_test.go +++ b/agent/cache-types/trust_bundles_test.go @@ -5,11 +5,11 @@ import ( "testing" "time" - "github.com/hashicorp/consul/agent/cache" - "github.com/hashicorp/consul/proto/pbpeering" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - "google.golang.org/grpc" + + "github.com/hashicorp/consul/agent/cache" + "github.com/hashicorp/consul/proto/pbpeering" ) func TestTrustBundles(t *testing.T) { @@ -105,48 +105,3 @@ func TestTrustBundles_MultipleUpdates(t *testing.T) { } } } - -// MockTrustBundleLister is an autogenerated mock type for the TrustBundleLister type -type MockTrustBundleLister struct { - mock.Mock -} - -// TrustBundleListByService provides a mock function with given fields: ctx, in, opts -func (_m *MockTrustBundleLister) TrustBundleListByService(ctx context.Context, in *pbpeering.TrustBundleListByServiceRequest, opts ...grpc.CallOption) (*pbpeering.TrustBundleListByServiceResponse, error) { - _va := make([]interface{}, len(opts)) - for _i := range opts { - _va[_i] = opts[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx, in) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 *pbpeering.TrustBundleListByServiceResponse - if rf, ok := ret.Get(0).(func(context.Context, *pbpeering.TrustBundleListByServiceRequest, ...grpc.CallOption) *pbpeering.TrustBundleListByServiceResponse); ok { - r0 = rf(ctx, in, opts...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*pbpeering.TrustBundleListByServiceResponse) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(context.Context, *pbpeering.TrustBundleListByServiceRequest, ...grpc.CallOption) error); ok { - r1 = rf(ctx, in, opts...) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// NewMockTrustBundleLister creates a new instance of MockTrustBundleLister. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewMockTrustBundleLister(t testing.TB) *MockTrustBundleLister { - mock := &MockTrustBundleLister{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/agent/cache/cache.go b/agent/cache/cache.go index de6d001e32..29690012b5 100644 --- a/agent/cache/cache.go +++ b/agent/cache/cache.go @@ -33,8 +33,6 @@ import ( "github.com/hashicorp/consul/lib/ttlcache" ) -//go:generate mockery --all --inpackage - // TODO(kit): remove the namespace from these once the metrics themselves change var Gauges = []prometheus.GaugeDefinition{ { diff --git a/agent/cache/mock_Request.go b/agent/cache/mock_Request.go index 7cd7343f8f..dd585c57e0 100644 --- a/agent/cache/mock_Request.go +++ b/agent/cache/mock_Request.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.11.0. DO NOT EDIT. +// Code generated by mockery v2.12.2. DO NOT EDIT. package cache @@ -27,9 +27,10 @@ func (_m *MockRequest) CacheInfo() RequestInfo { return r0 } -// NewMockRequest creates a new instance of MockRequest. It also registers a cleanup function to assert the mocks expectations. +// NewMockRequest creates a new instance of MockRequest. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. func NewMockRequest(t testing.TB) *MockRequest { mock := &MockRequest{} + mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/agent/cache/mock_Type.go b/agent/cache/mock_Type.go index 628e7a0184..76642bb5ce 100644 --- a/agent/cache/mock_Type.go +++ b/agent/cache/mock_Type.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.11.0. DO NOT EDIT. +// Code generated by mockery v2.12.2. DO NOT EDIT. package cache @@ -48,9 +48,10 @@ func (_m *MockType) RegisterOptions() RegisterOptions { return r0 } -// NewMockType creates a new instance of MockType. It also registers a cleanup function to assert the mocks expectations. +// NewMockType creates a new instance of MockType. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. func NewMockType(t testing.TB) *MockType { mock := &MockType{} + mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/agent/cache/request.go b/agent/cache/request.go index fbce6f8917..48023882d4 100644 --- a/agent/cache/request.go +++ b/agent/cache/request.go @@ -8,6 +8,7 @@ import ( // // This interface is typically implemented by request structures in // the agent/structs package. +//go:generate mockery --name Request --inpackage type Request interface { // CacheInfo returns information used for caching this request. CacheInfo() RequestInfo diff --git a/agent/cache/testing.go b/agent/cache/testing.go index 90a0d7bef5..bbcee6b272 100644 --- a/agent/cache/testing.go +++ b/agent/cache/testing.go @@ -5,7 +5,7 @@ import ( "reflect" "time" - "github.com/mitchellh/go-testing-interface" + testinf "github.com/mitchellh/go-testing-interface" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -13,7 +13,7 @@ import ( // TestCacheGetCh returns a channel that returns the result of the Get call. // This is useful for testing timing and concurrency with Get calls. Any // error will be logged, so the result value should always be asserted. -func TestCacheGetCh(t testing.T, c *Cache, typ string, r Request) <-chan interface{} { +func TestCacheGetCh(t testinf.T, c *Cache, typ string, r Request) <-chan interface{} { resultCh := make(chan interface{}) go func() { result, _, err := c.Get(context.Background(), typ, r) @@ -32,7 +32,7 @@ func TestCacheGetCh(t testing.T, c *Cache, typ string, r Request) <-chan interfa // TestCacheGetChResult tests that the result from TestCacheGetCh matches // within a reasonable period of time (it expects it to be "immediate" but // waits some milliseconds). -func TestCacheGetChResult(t testing.T, ch <-chan interface{}, expected interface{}) { +func TestCacheGetChResult(t testinf.T, ch <-chan interface{}, expected interface{}) { t.Helper() select { @@ -51,7 +51,7 @@ func TestCacheGetChResult(t testing.T, ch <-chan interface{}, expected interface // "immediate" but waits some milliseconds). Expected may be given multiple // times and if so these are all waited for and asserted to match but IN ANY // ORDER to ensure we aren't timing dependent. -func TestCacheNotifyChResult(t testing.T, ch <-chan UpdateEvent, expected ...UpdateEvent) { +func TestCacheNotifyChResult(t testinf.T, ch <-chan UpdateEvent, expected ...UpdateEvent) { t.Helper() expectLen := len(expected) @@ -85,14 +85,14 @@ OUT: // TestRequest returns a Request that returns the given cache key and index. // The Reset method can be called to reset it for custom usage. -func TestRequest(t testing.T, info RequestInfo) *MockRequest { +func TestRequest(t testinf.T, info RequestInfo) *MockRequest { req := &MockRequest{} req.On("CacheInfo").Return(info) return req } // TestType returns a MockType that sets default RegisterOptions. -func TestType(t testing.T) *MockType { +func TestType(t testinf.T) *MockType { typ := &MockType{} typ.On("RegisterOptions").Return(RegisterOptions{ SupportsBlocking: true, @@ -101,7 +101,7 @@ func TestType(t testing.T) *MockType { } // TestTypeNonBlocking returns a MockType that returns false to SupportsBlocking. -func TestTypeNonBlocking(t testing.T) *MockType { +func TestTypeNonBlocking(t testinf.T) *MockType { typ := &MockType{} typ.On("RegisterOptions").Return(RegisterOptions{ SupportsBlocking: false, diff --git a/agent/cache/type.go b/agent/cache/type.go index febdc18d7b..05b28ad1b5 100644 --- a/agent/cache/type.go +++ b/agent/cache/type.go @@ -5,6 +5,7 @@ import ( ) // Type implements the logic to fetch certain types of data. +//go:generate mockery --name Type --inpackage type Type interface { // Fetch fetches a single unique item. // diff --git a/agent/consul/autopilotevents/mock_Publisher_test.go b/agent/consul/autopilotevents/mock_Publisher_test.go index 98f6e4065c..c0a736be3d 100644 --- a/agent/consul/autopilotevents/mock_Publisher_test.go +++ b/agent/consul/autopilotevents/mock_Publisher_test.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.11.0. DO NOT EDIT. +// Code generated by mockery v2.12.2. DO NOT EDIT. package autopilotevents @@ -19,9 +19,10 @@ func (_m *MockPublisher) Publish(_a0 []stream.Event) { _m.Called(_a0) } -// NewMockPublisher creates a new instance of MockPublisher. It also registers a cleanup function to assert the mocks expectations. +// NewMockPublisher creates a new instance of MockPublisher. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. func NewMockPublisher(t testing.TB) *MockPublisher { mock := &MockPublisher{} + mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/agent/consul/autopilotevents/mock_StateStore_test.go b/agent/consul/autopilotevents/mock_StateStore_test.go index 200e68be71..0262b410ae 100644 --- a/agent/consul/autopilotevents/mock_StateStore_test.go +++ b/agent/consul/autopilotevents/mock_StateStore_test.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.11.0. DO NOT EDIT. +// Code generated by mockery v2.12.2. DO NOT EDIT. package autopilotevents @@ -48,9 +48,10 @@ func (_m *MockStateStore) GetNodeID(_a0 types.NodeID, _a1 *acl.EnterpriseMeta, _ return r0, r1, r2 } -// NewMockStateStore creates a new instance of MockStateStore. It also registers a cleanup function to assert the mocks expectations. +// NewMockStateStore creates a new instance of MockStateStore. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. func NewMockStateStore(t testing.TB) *MockStateStore { mock := &MockStateStore{} + mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/agent/consul/autopilotevents/mock_timeProvider_test.go b/agent/consul/autopilotevents/mock_timeProvider_test.go index 147424101d..4640fadde0 100644 --- a/agent/consul/autopilotevents/mock_timeProvider_test.go +++ b/agent/consul/autopilotevents/mock_timeProvider_test.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.11.0. DO NOT EDIT. +// Code generated by mockery v2.12.2. DO NOT EDIT. package autopilotevents @@ -29,9 +29,10 @@ func (_m *mockTimeProvider) Now() time.Time { return r0 } -// newMockTimeProvider creates a new instance of mockTimeProvider. It also registers a cleanup function to assert the mocks expectations. +// newMockTimeProvider creates a new instance of mockTimeProvider. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. func newMockTimeProvider(t testing.TB) *mockTimeProvider { mock := &mockTimeProvider{} + mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/agent/consul/autopilotevents/ready_servers_events.go b/agent/consul/autopilotevents/ready_servers_events.go index 7943ccacc8..ad3221e9a9 100644 --- a/agent/consul/autopilotevents/ready_servers_events.go +++ b/agent/consul/autopilotevents/ready_servers_events.go @@ -119,17 +119,17 @@ func NewReadyServersEventPublisher(config Config) *ReadyServersEventPublisher { } } -//go:generate mockery --name StateStore --inpackage --testonly +//go:generate mockery --name StateStore --inpackage --filename mock_StateStore_test.go type StateStore interface { GetNodeID(types.NodeID, *acl.EnterpriseMeta, string) (uint64, *structs.Node, error) } -//go:generate mockery --name Publisher --inpackage --testonly +//go:generate mockery --name Publisher --inpackage --filename mock_Publisher_test.go type Publisher interface { Publish([]stream.Event) } -//go:generate mockery --name timeProvider --inpackage --testonly +//go:generate mockery --name timeProvider --inpackage --filename mock_timeProvider_test.go type timeProvider interface { Now() time.Time } diff --git a/agent/consul/watch/server_local.go b/agent/consul/watch/server_local.go index 589f5d6441..4ad23ee386 100644 --- a/agent/consul/watch/server_local.go +++ b/agent/consul/watch/server_local.go @@ -6,9 +6,10 @@ import ( "fmt" "time" - "github.com/hashicorp/consul/lib/retry" "github.com/hashicorp/go-memdb" hashstructure_v2 "github.com/mitchellh/hashstructure/v2" + + "github.com/hashicorp/consul/lib/retry" ) var ( @@ -21,7 +22,7 @@ var ( errNilNotify = errors.New("cannot call ServerLocalNotify without a callback to send notifications") ) -//go:generate mockery --name StateStore --inpackage --testonly +//go:generate mockery --name StateStore --inpackage --filename mock_StateStore_test.go type StateStore interface { AbandonCh() <-chan struct{} }