From 587d3dceece7d6c92c654e5f34862cbaafb1d863 Mon Sep 17 00:00:00 2001 From: Joshua Rich Date: Mon, 10 Jul 2023 10:59:30 +0000 Subject: [PATCH] test!: replace mockery with moq --- internal/api/mock_Request.go | 64 ---- internal/api/mock_Request_test.go | 156 ++++++++ internal/api/mock_Response.go | 80 ----- internal/api/mock_Response_test.go | 178 ++++++++++ internal/api/request.go | 2 +- internal/api/request_test.go | 29 +- internal/api/response.go | 2 +- internal/hass/device.go | 2 +- internal/hass/mock_DeviceInfo.go | 206 ----------- internal/hass/mock_DeviceInfo_test.go | 474 +++++++++++++++++++++++++ internal/hass/registration_test.go | 14 +- internal/tracker/mock_Registry_test.go | 306 ++++++++++++++++ internal/tracker/mock_Sensor_test.go | 403 +++++++++++++++++++++ internal/tracker/mocks/Registry.go | 112 ------ internal/tracker/mocks/Sensor.go | 175 --------- internal/tracker/registry.go | 2 +- internal/tracker/sensor.go | 2 +- 17 files changed, 1549 insertions(+), 658 deletions(-) delete mode 100644 internal/api/mock_Request.go create mode 100644 internal/api/mock_Request_test.go delete mode 100644 internal/api/mock_Response.go create mode 100644 internal/api/mock_Response_test.go delete mode 100644 internal/hass/mock_DeviceInfo.go create mode 100644 internal/hass/mock_DeviceInfo_test.go create mode 100644 internal/tracker/mock_Registry_test.go create mode 100644 internal/tracker/mock_Sensor_test.go delete mode 100644 internal/tracker/mocks/Registry.go delete mode 100644 internal/tracker/mocks/Sensor.go diff --git a/internal/api/mock_Request.go b/internal/api/mock_Request.go deleted file mode 100644 index a7386d23f..000000000 --- a/internal/api/mock_Request.go +++ /dev/null @@ -1,64 +0,0 @@ -// Code generated by mockery v2.30.16. DO NOT EDIT. - -package api - -import ( - bytes "bytes" - json "encoding/json" - - mock "github.com/stretchr/testify/mock" -) - -// MockRequest is an autogenerated mock type for the Request type -type MockRequest struct { - mock.Mock -} - -// RequestData provides a mock function with given fields: -func (_m *MockRequest) RequestData() json.RawMessage { - ret := _m.Called() - - var r0 json.RawMessage - if rf, ok := ret.Get(0).(func() json.RawMessage); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(json.RawMessage) - } - } - - return r0 -} - -// RequestType provides a mock function with given fields: -func (_m *MockRequest) RequestType() RequestType { - ret := _m.Called() - - var r0 RequestType - if rf, ok := ret.Get(0).(func() RequestType); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(RequestType) - } - - return r0 -} - -// ResponseHandler provides a mock function with given fields: _a0, _a1 -func (_m *MockRequest) ResponseHandler(_a0 bytes.Buffer, _a1 chan Response) { - _m.Called(_a0, _a1) -} - -// NewMockRequest creates a new instance of MockRequest. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockRequest(t interface { - mock.TestingT - Cleanup(func()) -}) *MockRequest { - mock := &MockRequest{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/internal/api/mock_Request_test.go b/internal/api/mock_Request_test.go new file mode 100644 index 000000000..9b57d6ef6 --- /dev/null +++ b/internal/api/mock_Request_test.go @@ -0,0 +1,156 @@ +// Code generated by moq; DO NOT EDIT. +// github.com/matryer/moq + +package api + +import ( + "bytes" + "encoding/json" + "sync" +) + +// Ensure, that RequestMock does implement Request. +// If this is not the case, regenerate this file with moq. +var _ Request = &RequestMock{} + +// RequestMock is a mock implementation of Request. +// +// func TestSomethingThatUsesRequest(t *testing.T) { +// +// // make and configure a mocked Request +// mockedRequest := &RequestMock{ +// RequestDataFunc: func() json.RawMessage { +// panic("mock out the RequestData method") +// }, +// RequestTypeFunc: func() RequestType { +// panic("mock out the RequestType method") +// }, +// ResponseHandlerFunc: func(buffer bytes.Buffer, responseCh chan Response) { +// panic("mock out the ResponseHandler method") +// }, +// } +// +// // use mockedRequest in code that requires Request +// // and then make assertions. +// +// } +type RequestMock struct { + // RequestDataFunc mocks the RequestData method. + RequestDataFunc func() json.RawMessage + + // RequestTypeFunc mocks the RequestType method. + RequestTypeFunc func() RequestType + + // ResponseHandlerFunc mocks the ResponseHandler method. + ResponseHandlerFunc func(buffer bytes.Buffer, responseCh chan Response) + + // calls tracks calls to the methods. + calls struct { + // RequestData holds details about calls to the RequestData method. + RequestData []struct { + } + // RequestType holds details about calls to the RequestType method. + RequestType []struct { + } + // ResponseHandler holds details about calls to the ResponseHandler method. + ResponseHandler []struct { + // Buffer is the buffer argument value. + Buffer bytes.Buffer + // ResponseCh is the responseCh argument value. + ResponseCh chan Response + } + } + lockRequestData sync.RWMutex + lockRequestType sync.RWMutex + lockResponseHandler sync.RWMutex +} + +// RequestData calls RequestDataFunc. +func (mock *RequestMock) RequestData() json.RawMessage { + if mock.RequestDataFunc == nil { + panic("RequestMock.RequestDataFunc: method is nil but Request.RequestData was just called") + } + callInfo := struct { + }{} + mock.lockRequestData.Lock() + mock.calls.RequestData = append(mock.calls.RequestData, callInfo) + mock.lockRequestData.Unlock() + return mock.RequestDataFunc() +} + +// RequestDataCalls gets all the calls that were made to RequestData. +// Check the length with: +// +// len(mockedRequest.RequestDataCalls()) +func (mock *RequestMock) RequestDataCalls() []struct { +} { + var calls []struct { + } + mock.lockRequestData.RLock() + calls = mock.calls.RequestData + mock.lockRequestData.RUnlock() + return calls +} + +// RequestType calls RequestTypeFunc. +func (mock *RequestMock) RequestType() RequestType { + if mock.RequestTypeFunc == nil { + panic("RequestMock.RequestTypeFunc: method is nil but Request.RequestType was just called") + } + callInfo := struct { + }{} + mock.lockRequestType.Lock() + mock.calls.RequestType = append(mock.calls.RequestType, callInfo) + mock.lockRequestType.Unlock() + return mock.RequestTypeFunc() +} + +// RequestTypeCalls gets all the calls that were made to RequestType. +// Check the length with: +// +// len(mockedRequest.RequestTypeCalls()) +func (mock *RequestMock) RequestTypeCalls() []struct { +} { + var calls []struct { + } + mock.lockRequestType.RLock() + calls = mock.calls.RequestType + mock.lockRequestType.RUnlock() + return calls +} + +// ResponseHandler calls ResponseHandlerFunc. +func (mock *RequestMock) ResponseHandler(buffer bytes.Buffer, responseCh chan Response) { + if mock.ResponseHandlerFunc == nil { + panic("RequestMock.ResponseHandlerFunc: method is nil but Request.ResponseHandler was just called") + } + callInfo := struct { + Buffer bytes.Buffer + ResponseCh chan Response + }{ + Buffer: buffer, + ResponseCh: responseCh, + } + mock.lockResponseHandler.Lock() + mock.calls.ResponseHandler = append(mock.calls.ResponseHandler, callInfo) + mock.lockResponseHandler.Unlock() + mock.ResponseHandlerFunc(buffer, responseCh) +} + +// ResponseHandlerCalls gets all the calls that were made to ResponseHandler. +// Check the length with: +// +// len(mockedRequest.ResponseHandlerCalls()) +func (mock *RequestMock) ResponseHandlerCalls() []struct { + Buffer bytes.Buffer + ResponseCh chan Response +} { + var calls []struct { + Buffer bytes.Buffer + ResponseCh chan Response + } + mock.lockResponseHandler.RLock() + calls = mock.calls.ResponseHandler + mock.lockResponseHandler.RUnlock() + return calls +} diff --git a/internal/api/mock_Response.go b/internal/api/mock_Response.go deleted file mode 100644 index b5ece7833..000000000 --- a/internal/api/mock_Response.go +++ /dev/null @@ -1,80 +0,0 @@ -// Code generated by mockery v2.30.16. DO NOT EDIT. - -package api - -import mock "github.com/stretchr/testify/mock" - -// MockResponse is an autogenerated mock type for the Response type -type MockResponse struct { - mock.Mock -} - -// Disabled provides a mock function with given fields: -func (_m *MockResponse) Disabled() bool { - ret := _m.Called() - - var r0 bool - if rf, ok := ret.Get(0).(func() bool); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// Error provides a mock function with given fields: -func (_m *MockResponse) Error() error { - ret := _m.Called() - - var r0 error - if rf, ok := ret.Get(0).(func() error); ok { - r0 = rf() - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// Registered provides a mock function with given fields: -func (_m *MockResponse) Registered() bool { - ret := _m.Called() - - var r0 bool - if rf, ok := ret.Get(0).(func() bool); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// Type provides a mock function with given fields: -func (_m *MockResponse) Type() RequestType { - ret := _m.Called() - - var r0 RequestType - if rf, ok := ret.Get(0).(func() RequestType); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(RequestType) - } - - return r0 -} - -// NewMockResponse creates a new instance of MockResponse. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockResponse(t interface { - mock.TestingT - Cleanup(func()) -}) *MockResponse { - mock := &MockResponse{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/internal/api/mock_Response_test.go b/internal/api/mock_Response_test.go new file mode 100644 index 000000000..f4a19d3e6 --- /dev/null +++ b/internal/api/mock_Response_test.go @@ -0,0 +1,178 @@ +// Code generated by moq; DO NOT EDIT. +// github.com/matryer/moq + +package api + +import ( + "sync" +) + +// Ensure, that ResponseMock does implement Response. +// If this is not the case, regenerate this file with moq. +var _ Response = &ResponseMock{} + +// ResponseMock is a mock implementation of Response. +// +// func TestSomethingThatUsesResponse(t *testing.T) { +// +// // make and configure a mocked Response +// mockedResponse := &ResponseMock{ +// DisabledFunc: func() bool { +// panic("mock out the Disabled method") +// }, +// ErrorFunc: func() error { +// panic("mock out the Error method") +// }, +// RegisteredFunc: func() bool { +// panic("mock out the Registered method") +// }, +// TypeFunc: func() RequestType { +// panic("mock out the Type method") +// }, +// } +// +// // use mockedResponse in code that requires Response +// // and then make assertions. +// +// } +type ResponseMock struct { + // DisabledFunc mocks the Disabled method. + DisabledFunc func() bool + + // ErrorFunc mocks the Error method. + ErrorFunc func() error + + // RegisteredFunc mocks the Registered method. + RegisteredFunc func() bool + + // TypeFunc mocks the Type method. + TypeFunc func() RequestType + + // calls tracks calls to the methods. + calls struct { + // Disabled holds details about calls to the Disabled method. + Disabled []struct { + } + // Error holds details about calls to the Error method. + Error []struct { + } + // Registered holds details about calls to the Registered method. + Registered []struct { + } + // Type holds details about calls to the Type method. + Type []struct { + } + } + lockDisabled sync.RWMutex + lockError sync.RWMutex + lockRegistered sync.RWMutex + lockType sync.RWMutex +} + +// Disabled calls DisabledFunc. +func (mock *ResponseMock) Disabled() bool { + if mock.DisabledFunc == nil { + panic("ResponseMock.DisabledFunc: method is nil but Response.Disabled was just called") + } + callInfo := struct { + }{} + mock.lockDisabled.Lock() + mock.calls.Disabled = append(mock.calls.Disabled, callInfo) + mock.lockDisabled.Unlock() + return mock.DisabledFunc() +} + +// DisabledCalls gets all the calls that were made to Disabled. +// Check the length with: +// +// len(mockedResponse.DisabledCalls()) +func (mock *ResponseMock) DisabledCalls() []struct { +} { + var calls []struct { + } + mock.lockDisabled.RLock() + calls = mock.calls.Disabled + mock.lockDisabled.RUnlock() + return calls +} + +// Error calls ErrorFunc. +func (mock *ResponseMock) Error() error { + if mock.ErrorFunc == nil { + panic("ResponseMock.ErrorFunc: method is nil but Response.Error was just called") + } + callInfo := struct { + }{} + mock.lockError.Lock() + mock.calls.Error = append(mock.calls.Error, callInfo) + mock.lockError.Unlock() + return mock.ErrorFunc() +} + +// ErrorCalls gets all the calls that were made to Error. +// Check the length with: +// +// len(mockedResponse.ErrorCalls()) +func (mock *ResponseMock) ErrorCalls() []struct { +} { + var calls []struct { + } + mock.lockError.RLock() + calls = mock.calls.Error + mock.lockError.RUnlock() + return calls +} + +// Registered calls RegisteredFunc. +func (mock *ResponseMock) Registered() bool { + if mock.RegisteredFunc == nil { + panic("ResponseMock.RegisteredFunc: method is nil but Response.Registered was just called") + } + callInfo := struct { + }{} + mock.lockRegistered.Lock() + mock.calls.Registered = append(mock.calls.Registered, callInfo) + mock.lockRegistered.Unlock() + return mock.RegisteredFunc() +} + +// RegisteredCalls gets all the calls that were made to Registered. +// Check the length with: +// +// len(mockedResponse.RegisteredCalls()) +func (mock *ResponseMock) RegisteredCalls() []struct { +} { + var calls []struct { + } + mock.lockRegistered.RLock() + calls = mock.calls.Registered + mock.lockRegistered.RUnlock() + return calls +} + +// Type calls TypeFunc. +func (mock *ResponseMock) Type() RequestType { + if mock.TypeFunc == nil { + panic("ResponseMock.TypeFunc: method is nil but Response.Type was just called") + } + callInfo := struct { + }{} + mock.lockType.Lock() + mock.calls.Type = append(mock.calls.Type, callInfo) + mock.lockType.Unlock() + return mock.TypeFunc() +} + +// TypeCalls gets all the calls that were made to Type. +// Check the length with: +// +// len(mockedResponse.TypeCalls()) +func (mock *ResponseMock) TypeCalls() []struct { +} { + var calls []struct { + } + mock.lockType.RLock() + calls = mock.calls.Type + mock.lockType.RUnlock() + return calls +} diff --git a/internal/api/request.go b/internal/api/request.go index f76425daf..d26f1b08b 100644 --- a/internal/api/request.go +++ b/internal/api/request.go @@ -27,7 +27,7 @@ const ( type RequestType int -//go:generate mockery --name Request --inpackage +//go:generate moq -out mock_Request_test.go . Request type Request interface { RequestType() RequestType RequestData() json.RawMessage diff --git a/internal/api/request_test.go b/internal/api/request_test.go index e645af115..f41ae7629 100644 --- a/internal/api/request_test.go +++ b/internal/api/request_test.go @@ -21,14 +21,23 @@ import ( ) func Test_marshalJSON(t *testing.T) { - requestData := json.RawMessage(`{"someField": "someValue"}`) - request := NewMockRequest(t) - request.On("RequestType").Return(RequestTypeUpdateSensorStates) - request.On("RequestData").Return(requestData) + mockReq := &RequestMock{ + RequestDataFunc: func() json.RawMessage { + return json.RawMessage(`{"someField": "someValue"}`) + }, + RequestTypeFunc: func() RequestType { + return RequestTypeUpdateSensorStates + }, + } - encryptedRequest := NewMockRequest(t) - encryptedRequest.On("RequestType").Return(RequestTypeEncrypted) - encryptedRequest.On("RequestData").Return(requestData) + mockEncReq := &RequestMock{ + RequestDataFunc: func() json.RawMessage { + return json.RawMessage(`{"someField": "someValue"}`) + }, + RequestTypeFunc: func() RequestType { + return RequestTypeEncrypted + }, + } type args struct { request Request @@ -42,18 +51,18 @@ func Test_marshalJSON(t *testing.T) { }{ { name: "unencrypted request", - args: args{request: request}, + args: args{request: mockReq}, want: []byte(`{"type":"update_sensor_states","data":{"someField":"someValue"}}`), }, { name: "encrypted request without secret", - args: args{request: encryptedRequest}, + args: args{request: mockEncReq}, want: nil, wantErr: true, }, { name: "encrypted request with secret", - args: args{request: encryptedRequest, secret: "fakeSecret"}, + args: args{request: mockEncReq, secret: "fakeSecret"}, want: []byte(`{"type":"encrypted","encrypted_data":{"someField":"someValue"},"encrypted":true}`), }, } diff --git a/internal/api/response.go b/internal/api/response.go index 17ace0721..465b4441a 100644 --- a/internal/api/response.go +++ b/internal/api/response.go @@ -5,7 +5,7 @@ package api -//go:generate mockery --name Response --inpackage +//go:generate moq -out mock_Response_test.go . Response type Response interface { SensorRegistrationResponse SensorUpdateResponse diff --git a/internal/hass/device.go b/internal/hass/device.go index 52233b5c8..945ef3b3d 100644 --- a/internal/hass/device.go +++ b/internal/hass/device.go @@ -5,7 +5,7 @@ package hass -//go:generate mockery --name DeviceInfo --inpackage +//go:generate moq -out mock_DeviceInfo_test.go . DeviceInfo type DeviceInfo interface { DeviceID() string AppID() string diff --git a/internal/hass/mock_DeviceInfo.go b/internal/hass/mock_DeviceInfo.go deleted file mode 100644 index 3ec80be5f..000000000 --- a/internal/hass/mock_DeviceInfo.go +++ /dev/null @@ -1,206 +0,0 @@ -// Code generated by mockery v2.30.16. DO NOT EDIT. - -package hass - -import mock "github.com/stretchr/testify/mock" - -// MockDeviceInfo is an autogenerated mock type for the DeviceInfo type -type MockDeviceInfo struct { - mock.Mock -} - -// AppData provides a mock function with given fields: -func (_m *MockDeviceInfo) AppData() interface{} { - ret := _m.Called() - - var r0 interface{} - if rf, ok := ret.Get(0).(func() interface{}); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(interface{}) - } - } - - return r0 -} - -// AppID provides a mock function with given fields: -func (_m *MockDeviceInfo) AppID() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// AppName provides a mock function with given fields: -func (_m *MockDeviceInfo) AppName() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// AppVersion provides a mock function with given fields: -func (_m *MockDeviceInfo) AppVersion() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// DeviceID provides a mock function with given fields: -func (_m *MockDeviceInfo) DeviceID() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// DeviceName provides a mock function with given fields: -func (_m *MockDeviceInfo) DeviceName() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// Manufacturer provides a mock function with given fields: -func (_m *MockDeviceInfo) Manufacturer() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// MarshalJSON provides a mock function with given fields: -func (_m *MockDeviceInfo) MarshalJSON() ([]byte, error) { - ret := _m.Called() - - var r0 []byte - var r1 error - if rf, ok := ret.Get(0).(func() ([]byte, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() []byte); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]byte) - } - } - - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// Model provides a mock function with given fields: -func (_m *MockDeviceInfo) Model() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// OsName provides a mock function with given fields: -func (_m *MockDeviceInfo) OsName() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// OsVersion provides a mock function with given fields: -func (_m *MockDeviceInfo) OsVersion() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// SupportsEncryption provides a mock function with given fields: -func (_m *MockDeviceInfo) SupportsEncryption() bool { - ret := _m.Called() - - var r0 bool - if rf, ok := ret.Get(0).(func() bool); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// NewMockDeviceInfo creates a new instance of MockDeviceInfo. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockDeviceInfo(t interface { - mock.TestingT - Cleanup(func()) -}) *MockDeviceInfo { - mock := &MockDeviceInfo{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/internal/hass/mock_DeviceInfo_test.go b/internal/hass/mock_DeviceInfo_test.go new file mode 100644 index 000000000..616764d33 --- /dev/null +++ b/internal/hass/mock_DeviceInfo_test.go @@ -0,0 +1,474 @@ +// Code generated by moq; DO NOT EDIT. +// github.com/matryer/moq + +package hass + +import ( + "sync" +) + +// Ensure, that DeviceInfoMock does implement DeviceInfo. +// If this is not the case, regenerate this file with moq. +var _ DeviceInfo = &DeviceInfoMock{} + +// DeviceInfoMock is a mock implementation of DeviceInfo. +// +// func TestSomethingThatUsesDeviceInfo(t *testing.T) { +// +// // make and configure a mocked DeviceInfo +// mockedDeviceInfo := &DeviceInfoMock{ +// AppDataFunc: func() interface{} { +// panic("mock out the AppData method") +// }, +// AppIDFunc: func() string { +// panic("mock out the AppID method") +// }, +// AppNameFunc: func() string { +// panic("mock out the AppName method") +// }, +// AppVersionFunc: func() string { +// panic("mock out the AppVersion method") +// }, +// DeviceIDFunc: func() string { +// panic("mock out the DeviceID method") +// }, +// DeviceNameFunc: func() string { +// panic("mock out the DeviceName method") +// }, +// ManufacturerFunc: func() string { +// panic("mock out the Manufacturer method") +// }, +// MarshalJSONFunc: func() ([]byte, error) { +// panic("mock out the MarshalJSON method") +// }, +// ModelFunc: func() string { +// panic("mock out the Model method") +// }, +// OsNameFunc: func() string { +// panic("mock out the OsName method") +// }, +// OsVersionFunc: func() string { +// panic("mock out the OsVersion method") +// }, +// SupportsEncryptionFunc: func() bool { +// panic("mock out the SupportsEncryption method") +// }, +// } +// +// // use mockedDeviceInfo in code that requires DeviceInfo +// // and then make assertions. +// +// } +type DeviceInfoMock struct { + // AppDataFunc mocks the AppData method. + AppDataFunc func() interface{} + + // AppIDFunc mocks the AppID method. + AppIDFunc func() string + + // AppNameFunc mocks the AppName method. + AppNameFunc func() string + + // AppVersionFunc mocks the AppVersion method. + AppVersionFunc func() string + + // DeviceIDFunc mocks the DeviceID method. + DeviceIDFunc func() string + + // DeviceNameFunc mocks the DeviceName method. + DeviceNameFunc func() string + + // ManufacturerFunc mocks the Manufacturer method. + ManufacturerFunc func() string + + // MarshalJSONFunc mocks the MarshalJSON method. + MarshalJSONFunc func() ([]byte, error) + + // ModelFunc mocks the Model method. + ModelFunc func() string + + // OsNameFunc mocks the OsName method. + OsNameFunc func() string + + // OsVersionFunc mocks the OsVersion method. + OsVersionFunc func() string + + // SupportsEncryptionFunc mocks the SupportsEncryption method. + SupportsEncryptionFunc func() bool + + // calls tracks calls to the methods. + calls struct { + // AppData holds details about calls to the AppData method. + AppData []struct { + } + // AppID holds details about calls to the AppID method. + AppID []struct { + } + // AppName holds details about calls to the AppName method. + AppName []struct { + } + // AppVersion holds details about calls to the AppVersion method. + AppVersion []struct { + } + // DeviceID holds details about calls to the DeviceID method. + DeviceID []struct { + } + // DeviceName holds details about calls to the DeviceName method. + DeviceName []struct { + } + // Manufacturer holds details about calls to the Manufacturer method. + Manufacturer []struct { + } + // MarshalJSON holds details about calls to the MarshalJSON method. + MarshalJSON []struct { + } + // Model holds details about calls to the Model method. + Model []struct { + } + // OsName holds details about calls to the OsName method. + OsName []struct { + } + // OsVersion holds details about calls to the OsVersion method. + OsVersion []struct { + } + // SupportsEncryption holds details about calls to the SupportsEncryption method. + SupportsEncryption []struct { + } + } + lockAppData sync.RWMutex + lockAppID sync.RWMutex + lockAppName sync.RWMutex + lockAppVersion sync.RWMutex + lockDeviceID sync.RWMutex + lockDeviceName sync.RWMutex + lockManufacturer sync.RWMutex + lockMarshalJSON sync.RWMutex + lockModel sync.RWMutex + lockOsName sync.RWMutex + lockOsVersion sync.RWMutex + lockSupportsEncryption sync.RWMutex +} + +// AppData calls AppDataFunc. +func (mock *DeviceInfoMock) AppData() interface{} { + if mock.AppDataFunc == nil { + panic("DeviceInfoMock.AppDataFunc: method is nil but DeviceInfo.AppData was just called") + } + callInfo := struct { + }{} + mock.lockAppData.Lock() + mock.calls.AppData = append(mock.calls.AppData, callInfo) + mock.lockAppData.Unlock() + return mock.AppDataFunc() +} + +// AppDataCalls gets all the calls that were made to AppData. +// Check the length with: +// +// len(mockedDeviceInfo.AppDataCalls()) +func (mock *DeviceInfoMock) AppDataCalls() []struct { +} { + var calls []struct { + } + mock.lockAppData.RLock() + calls = mock.calls.AppData + mock.lockAppData.RUnlock() + return calls +} + +// AppID calls AppIDFunc. +func (mock *DeviceInfoMock) AppID() string { + if mock.AppIDFunc == nil { + panic("DeviceInfoMock.AppIDFunc: method is nil but DeviceInfo.AppID was just called") + } + callInfo := struct { + }{} + mock.lockAppID.Lock() + mock.calls.AppID = append(mock.calls.AppID, callInfo) + mock.lockAppID.Unlock() + return mock.AppIDFunc() +} + +// AppIDCalls gets all the calls that were made to AppID. +// Check the length with: +// +// len(mockedDeviceInfo.AppIDCalls()) +func (mock *DeviceInfoMock) AppIDCalls() []struct { +} { + var calls []struct { + } + mock.lockAppID.RLock() + calls = mock.calls.AppID + mock.lockAppID.RUnlock() + return calls +} + +// AppName calls AppNameFunc. +func (mock *DeviceInfoMock) AppName() string { + if mock.AppNameFunc == nil { + panic("DeviceInfoMock.AppNameFunc: method is nil but DeviceInfo.AppName was just called") + } + callInfo := struct { + }{} + mock.lockAppName.Lock() + mock.calls.AppName = append(mock.calls.AppName, callInfo) + mock.lockAppName.Unlock() + return mock.AppNameFunc() +} + +// AppNameCalls gets all the calls that were made to AppName. +// Check the length with: +// +// len(mockedDeviceInfo.AppNameCalls()) +func (mock *DeviceInfoMock) AppNameCalls() []struct { +} { + var calls []struct { + } + mock.lockAppName.RLock() + calls = mock.calls.AppName + mock.lockAppName.RUnlock() + return calls +} + +// AppVersion calls AppVersionFunc. +func (mock *DeviceInfoMock) AppVersion() string { + if mock.AppVersionFunc == nil { + panic("DeviceInfoMock.AppVersionFunc: method is nil but DeviceInfo.AppVersion was just called") + } + callInfo := struct { + }{} + mock.lockAppVersion.Lock() + mock.calls.AppVersion = append(mock.calls.AppVersion, callInfo) + mock.lockAppVersion.Unlock() + return mock.AppVersionFunc() +} + +// AppVersionCalls gets all the calls that were made to AppVersion. +// Check the length with: +// +// len(mockedDeviceInfo.AppVersionCalls()) +func (mock *DeviceInfoMock) AppVersionCalls() []struct { +} { + var calls []struct { + } + mock.lockAppVersion.RLock() + calls = mock.calls.AppVersion + mock.lockAppVersion.RUnlock() + return calls +} + +// DeviceID calls DeviceIDFunc. +func (mock *DeviceInfoMock) DeviceID() string { + if mock.DeviceIDFunc == nil { + panic("DeviceInfoMock.DeviceIDFunc: method is nil but DeviceInfo.DeviceID was just called") + } + callInfo := struct { + }{} + mock.lockDeviceID.Lock() + mock.calls.DeviceID = append(mock.calls.DeviceID, callInfo) + mock.lockDeviceID.Unlock() + return mock.DeviceIDFunc() +} + +// DeviceIDCalls gets all the calls that were made to DeviceID. +// Check the length with: +// +// len(mockedDeviceInfo.DeviceIDCalls()) +func (mock *DeviceInfoMock) DeviceIDCalls() []struct { +} { + var calls []struct { + } + mock.lockDeviceID.RLock() + calls = mock.calls.DeviceID + mock.lockDeviceID.RUnlock() + return calls +} + +// DeviceName calls DeviceNameFunc. +func (mock *DeviceInfoMock) DeviceName() string { + if mock.DeviceNameFunc == nil { + panic("DeviceInfoMock.DeviceNameFunc: method is nil but DeviceInfo.DeviceName was just called") + } + callInfo := struct { + }{} + mock.lockDeviceName.Lock() + mock.calls.DeviceName = append(mock.calls.DeviceName, callInfo) + mock.lockDeviceName.Unlock() + return mock.DeviceNameFunc() +} + +// DeviceNameCalls gets all the calls that were made to DeviceName. +// Check the length with: +// +// len(mockedDeviceInfo.DeviceNameCalls()) +func (mock *DeviceInfoMock) DeviceNameCalls() []struct { +} { + var calls []struct { + } + mock.lockDeviceName.RLock() + calls = mock.calls.DeviceName + mock.lockDeviceName.RUnlock() + return calls +} + +// Manufacturer calls ManufacturerFunc. +func (mock *DeviceInfoMock) Manufacturer() string { + if mock.ManufacturerFunc == nil { + panic("DeviceInfoMock.ManufacturerFunc: method is nil but DeviceInfo.Manufacturer was just called") + } + callInfo := struct { + }{} + mock.lockManufacturer.Lock() + mock.calls.Manufacturer = append(mock.calls.Manufacturer, callInfo) + mock.lockManufacturer.Unlock() + return mock.ManufacturerFunc() +} + +// ManufacturerCalls gets all the calls that were made to Manufacturer. +// Check the length with: +// +// len(mockedDeviceInfo.ManufacturerCalls()) +func (mock *DeviceInfoMock) ManufacturerCalls() []struct { +} { + var calls []struct { + } + mock.lockManufacturer.RLock() + calls = mock.calls.Manufacturer + mock.lockManufacturer.RUnlock() + return calls +} + +// MarshalJSON calls MarshalJSONFunc. +func (mock *DeviceInfoMock) MarshalJSON() ([]byte, error) { + if mock.MarshalJSONFunc == nil { + panic("DeviceInfoMock.MarshalJSONFunc: method is nil but DeviceInfo.MarshalJSON was just called") + } + callInfo := struct { + }{} + mock.lockMarshalJSON.Lock() + mock.calls.MarshalJSON = append(mock.calls.MarshalJSON, callInfo) + mock.lockMarshalJSON.Unlock() + return mock.MarshalJSONFunc() +} + +// MarshalJSONCalls gets all the calls that were made to MarshalJSON. +// Check the length with: +// +// len(mockedDeviceInfo.MarshalJSONCalls()) +func (mock *DeviceInfoMock) MarshalJSONCalls() []struct { +} { + var calls []struct { + } + mock.lockMarshalJSON.RLock() + calls = mock.calls.MarshalJSON + mock.lockMarshalJSON.RUnlock() + return calls +} + +// Model calls ModelFunc. +func (mock *DeviceInfoMock) Model() string { + if mock.ModelFunc == nil { + panic("DeviceInfoMock.ModelFunc: method is nil but DeviceInfo.Model was just called") + } + callInfo := struct { + }{} + mock.lockModel.Lock() + mock.calls.Model = append(mock.calls.Model, callInfo) + mock.lockModel.Unlock() + return mock.ModelFunc() +} + +// ModelCalls gets all the calls that were made to Model. +// Check the length with: +// +// len(mockedDeviceInfo.ModelCalls()) +func (mock *DeviceInfoMock) ModelCalls() []struct { +} { + var calls []struct { + } + mock.lockModel.RLock() + calls = mock.calls.Model + mock.lockModel.RUnlock() + return calls +} + +// OsName calls OsNameFunc. +func (mock *DeviceInfoMock) OsName() string { + if mock.OsNameFunc == nil { + panic("DeviceInfoMock.OsNameFunc: method is nil but DeviceInfo.OsName was just called") + } + callInfo := struct { + }{} + mock.lockOsName.Lock() + mock.calls.OsName = append(mock.calls.OsName, callInfo) + mock.lockOsName.Unlock() + return mock.OsNameFunc() +} + +// OsNameCalls gets all the calls that were made to OsName. +// Check the length with: +// +// len(mockedDeviceInfo.OsNameCalls()) +func (mock *DeviceInfoMock) OsNameCalls() []struct { +} { + var calls []struct { + } + mock.lockOsName.RLock() + calls = mock.calls.OsName + mock.lockOsName.RUnlock() + return calls +} + +// OsVersion calls OsVersionFunc. +func (mock *DeviceInfoMock) OsVersion() string { + if mock.OsVersionFunc == nil { + panic("DeviceInfoMock.OsVersionFunc: method is nil but DeviceInfo.OsVersion was just called") + } + callInfo := struct { + }{} + mock.lockOsVersion.Lock() + mock.calls.OsVersion = append(mock.calls.OsVersion, callInfo) + mock.lockOsVersion.Unlock() + return mock.OsVersionFunc() +} + +// OsVersionCalls gets all the calls that were made to OsVersion. +// Check the length with: +// +// len(mockedDeviceInfo.OsVersionCalls()) +func (mock *DeviceInfoMock) OsVersionCalls() []struct { +} { + var calls []struct { + } + mock.lockOsVersion.RLock() + calls = mock.calls.OsVersion + mock.lockOsVersion.RUnlock() + return calls +} + +// SupportsEncryption calls SupportsEncryptionFunc. +func (mock *DeviceInfoMock) SupportsEncryption() bool { + if mock.SupportsEncryptionFunc == nil { + panic("DeviceInfoMock.SupportsEncryptionFunc: method is nil but DeviceInfo.SupportsEncryption was just called") + } + callInfo := struct { + }{} + mock.lockSupportsEncryption.Lock() + mock.calls.SupportsEncryption = append(mock.calls.SupportsEncryption, callInfo) + mock.lockSupportsEncryption.Unlock() + return mock.SupportsEncryptionFunc() +} + +// SupportsEncryptionCalls gets all the calls that were made to SupportsEncryption. +// Check the length with: +// +// len(mockedDeviceInfo.SupportsEncryptionCalls()) +func (mock *DeviceInfoMock) SupportsEncryptionCalls() []struct { +} { + var calls []struct { + } + mock.lockSupportsEncryption.RLock() + calls = mock.calls.SupportsEncryption + mock.lockSupportsEncryption.RUnlock() + return calls +} diff --git a/internal/hass/registration_test.go b/internal/hass/registration_test.go index 5ae9100b2..eb1da3fba 100644 --- a/internal/hass/registration_test.go +++ b/internal/hass/registration_test.go @@ -14,6 +14,8 @@ import ( ) func TestRegistrationDetails_Validate(t *testing.T) { + mockDeviceInfo := &DeviceInfoMock{} + type fields struct { Server string Token string @@ -29,7 +31,7 @@ func TestRegistrationDetails_Validate(t *testing.T) { fields: fields{ Server: "localhost", Token: "abcde.abcde_abcde", - Device: NewMockDeviceInfo(t), + Device: mockDeviceInfo, }, want: false, }, @@ -38,7 +40,7 @@ func TestRegistrationDetails_Validate(t *testing.T) { fields: fields{ Server: "localhost:8123", Token: "abcde.abcde_abcde", - Device: NewMockDeviceInfo(t), + Device: mockDeviceInfo, }, want: false, }, @@ -47,7 +49,7 @@ func TestRegistrationDetails_Validate(t *testing.T) { fields: fields{ Server: "http://localhost", Token: "abcde.abcde_abcde", - Device: NewMockDeviceInfo(t), + Device: mockDeviceInfo, }, want: true, }, @@ -56,7 +58,7 @@ func TestRegistrationDetails_Validate(t *testing.T) { fields: fields{ Server: "http://localhost:8123", Token: "abcde.abcde_abcde", - Device: NewMockDeviceInfo(t), + Device: mockDeviceInfo, }, want: true, }, @@ -65,7 +67,7 @@ func TestRegistrationDetails_Validate(t *testing.T) { fields: fields{ Server: "http://localhost/", Token: "abcde.abcde_abcde", - Device: NewMockDeviceInfo(t), + Device: mockDeviceInfo, }, want: true, }, @@ -74,7 +76,7 @@ func TestRegistrationDetails_Validate(t *testing.T) { fields: fields{ Server: "asdegasg://localhost//", Token: "abcde.abcde_abcde", - Device: NewMockDeviceInfo(t), + Device: mockDeviceInfo, }, want: false, }, diff --git a/internal/tracker/mock_Registry_test.go b/internal/tracker/mock_Registry_test.go new file mode 100644 index 000000000..e7cb0bb88 --- /dev/null +++ b/internal/tracker/mock_Registry_test.go @@ -0,0 +1,306 @@ +// Code generated by moq; DO NOT EDIT. +// github.com/matryer/moq + +package tracker + +import ( + "context" + "sync" +) + +// Ensure, that RegistryMock does implement Registry. +// If this is not the case, regenerate this file with moq. +var _ Registry = &RegistryMock{} + +// RegistryMock is a mock implementation of Registry. +// +// func TestSomethingThatUsesRegistry(t *testing.T) { +// +// // make and configure a mocked Registry +// mockedRegistry := &RegistryMock{ +// CloseFunc: func() error { +// panic("mock out the Close method") +// }, +// IsDisabledFunc: func(s string) bool { +// panic("mock out the IsDisabled method") +// }, +// IsRegisteredFunc: func(s string) bool { +// panic("mock out the IsRegistered method") +// }, +// OpenFunc: func(contextMoqParam context.Context, s string) error { +// panic("mock out the Open method") +// }, +// SetDisabledFunc: func(s string, b bool) error { +// panic("mock out the SetDisabled method") +// }, +// SetRegisteredFunc: func(s string, b bool) error { +// panic("mock out the SetRegistered method") +// }, +// } +// +// // use mockedRegistry in code that requires Registry +// // and then make assertions. +// +// } +type RegistryMock struct { + // CloseFunc mocks the Close method. + CloseFunc func() error + + // IsDisabledFunc mocks the IsDisabled method. + IsDisabledFunc func(s string) bool + + // IsRegisteredFunc mocks the IsRegistered method. + IsRegisteredFunc func(s string) bool + + // OpenFunc mocks the Open method. + OpenFunc func(contextMoqParam context.Context, s string) error + + // SetDisabledFunc mocks the SetDisabled method. + SetDisabledFunc func(s string, b bool) error + + // SetRegisteredFunc mocks the SetRegistered method. + SetRegisteredFunc func(s string, b bool) error + + // calls tracks calls to the methods. + calls struct { + // Close holds details about calls to the Close method. + Close []struct { + } + // IsDisabled holds details about calls to the IsDisabled method. + IsDisabled []struct { + // S is the s argument value. + S string + } + // IsRegistered holds details about calls to the IsRegistered method. + IsRegistered []struct { + // S is the s argument value. + S string + } + // Open holds details about calls to the Open method. + Open []struct { + // ContextMoqParam is the contextMoqParam argument value. + ContextMoqParam context.Context + // S is the s argument value. + S string + } + // SetDisabled holds details about calls to the SetDisabled method. + SetDisabled []struct { + // S is the s argument value. + S string + // B is the b argument value. + B bool + } + // SetRegistered holds details about calls to the SetRegistered method. + SetRegistered []struct { + // S is the s argument value. + S string + // B is the b argument value. + B bool + } + } + lockClose sync.RWMutex + lockIsDisabled sync.RWMutex + lockIsRegistered sync.RWMutex + lockOpen sync.RWMutex + lockSetDisabled sync.RWMutex + lockSetRegistered sync.RWMutex +} + +// Close calls CloseFunc. +func (mock *RegistryMock) Close() error { + if mock.CloseFunc == nil { + panic("RegistryMock.CloseFunc: method is nil but Registry.Close was just called") + } + callInfo := struct { + }{} + mock.lockClose.Lock() + mock.calls.Close = append(mock.calls.Close, callInfo) + mock.lockClose.Unlock() + return mock.CloseFunc() +} + +// CloseCalls gets all the calls that were made to Close. +// Check the length with: +// +// len(mockedRegistry.CloseCalls()) +func (mock *RegistryMock) CloseCalls() []struct { +} { + var calls []struct { + } + mock.lockClose.RLock() + calls = mock.calls.Close + mock.lockClose.RUnlock() + return calls +} + +// IsDisabled calls IsDisabledFunc. +func (mock *RegistryMock) IsDisabled(s string) bool { + if mock.IsDisabledFunc == nil { + panic("RegistryMock.IsDisabledFunc: method is nil but Registry.IsDisabled was just called") + } + callInfo := struct { + S string + }{ + S: s, + } + mock.lockIsDisabled.Lock() + mock.calls.IsDisabled = append(mock.calls.IsDisabled, callInfo) + mock.lockIsDisabled.Unlock() + return mock.IsDisabledFunc(s) +} + +// IsDisabledCalls gets all the calls that were made to IsDisabled. +// Check the length with: +// +// len(mockedRegistry.IsDisabledCalls()) +func (mock *RegistryMock) IsDisabledCalls() []struct { + S string +} { + var calls []struct { + S string + } + mock.lockIsDisabled.RLock() + calls = mock.calls.IsDisabled + mock.lockIsDisabled.RUnlock() + return calls +} + +// IsRegistered calls IsRegisteredFunc. +func (mock *RegistryMock) IsRegistered(s string) bool { + if mock.IsRegisteredFunc == nil { + panic("RegistryMock.IsRegisteredFunc: method is nil but Registry.IsRegistered was just called") + } + callInfo := struct { + S string + }{ + S: s, + } + mock.lockIsRegistered.Lock() + mock.calls.IsRegistered = append(mock.calls.IsRegistered, callInfo) + mock.lockIsRegistered.Unlock() + return mock.IsRegisteredFunc(s) +} + +// IsRegisteredCalls gets all the calls that were made to IsRegistered. +// Check the length with: +// +// len(mockedRegistry.IsRegisteredCalls()) +func (mock *RegistryMock) IsRegisteredCalls() []struct { + S string +} { + var calls []struct { + S string + } + mock.lockIsRegistered.RLock() + calls = mock.calls.IsRegistered + mock.lockIsRegistered.RUnlock() + return calls +} + +// Open calls OpenFunc. +func (mock *RegistryMock) Open(contextMoqParam context.Context, s string) error { + if mock.OpenFunc == nil { + panic("RegistryMock.OpenFunc: method is nil but Registry.Open was just called") + } + callInfo := struct { + ContextMoqParam context.Context + S string + }{ + ContextMoqParam: contextMoqParam, + S: s, + } + mock.lockOpen.Lock() + mock.calls.Open = append(mock.calls.Open, callInfo) + mock.lockOpen.Unlock() + return mock.OpenFunc(contextMoqParam, s) +} + +// OpenCalls gets all the calls that were made to Open. +// Check the length with: +// +// len(mockedRegistry.OpenCalls()) +func (mock *RegistryMock) OpenCalls() []struct { + ContextMoqParam context.Context + S string +} { + var calls []struct { + ContextMoqParam context.Context + S string + } + mock.lockOpen.RLock() + calls = mock.calls.Open + mock.lockOpen.RUnlock() + return calls +} + +// SetDisabled calls SetDisabledFunc. +func (mock *RegistryMock) SetDisabled(s string, b bool) error { + if mock.SetDisabledFunc == nil { + panic("RegistryMock.SetDisabledFunc: method is nil but Registry.SetDisabled was just called") + } + callInfo := struct { + S string + B bool + }{ + S: s, + B: b, + } + mock.lockSetDisabled.Lock() + mock.calls.SetDisabled = append(mock.calls.SetDisabled, callInfo) + mock.lockSetDisabled.Unlock() + return mock.SetDisabledFunc(s, b) +} + +// SetDisabledCalls gets all the calls that were made to SetDisabled. +// Check the length with: +// +// len(mockedRegistry.SetDisabledCalls()) +func (mock *RegistryMock) SetDisabledCalls() []struct { + S string + B bool +} { + var calls []struct { + S string + B bool + } + mock.lockSetDisabled.RLock() + calls = mock.calls.SetDisabled + mock.lockSetDisabled.RUnlock() + return calls +} + +// SetRegistered calls SetRegisteredFunc. +func (mock *RegistryMock) SetRegistered(s string, b bool) error { + if mock.SetRegisteredFunc == nil { + panic("RegistryMock.SetRegisteredFunc: method is nil but Registry.SetRegistered was just called") + } + callInfo := struct { + S string + B bool + }{ + S: s, + B: b, + } + mock.lockSetRegistered.Lock() + mock.calls.SetRegistered = append(mock.calls.SetRegistered, callInfo) + mock.lockSetRegistered.Unlock() + return mock.SetRegisteredFunc(s, b) +} + +// SetRegisteredCalls gets all the calls that were made to SetRegistered. +// Check the length with: +// +// len(mockedRegistry.SetRegisteredCalls()) +func (mock *RegistryMock) SetRegisteredCalls() []struct { + S string + B bool +} { + var calls []struct { + S string + B bool + } + mock.lockSetRegistered.RLock() + calls = mock.calls.SetRegistered + mock.lockSetRegistered.RUnlock() + return calls +} diff --git a/internal/tracker/mock_Sensor_test.go b/internal/tracker/mock_Sensor_test.go new file mode 100644 index 000000000..4837088bb --- /dev/null +++ b/internal/tracker/mock_Sensor_test.go @@ -0,0 +1,403 @@ +// Code generated by moq; DO NOT EDIT. +// github.com/matryer/moq + +package tracker + +import ( + "github.com/joshuar/go-hass-agent/internal/hass/deviceClass" + "github.com/joshuar/go-hass-agent/internal/hass/sensorType" + "github.com/joshuar/go-hass-agent/internal/hass/stateClass" + "sync" +) + +// Ensure, that SensorMock does implement Sensor. +// If this is not the case, regenerate this file with moq. +var _ Sensor = &SensorMock{} + +// SensorMock is a mock implementation of Sensor. +// +// func TestSomethingThatUsesSensor(t *testing.T) { +// +// // make and configure a mocked Sensor +// mockedSensor := &SensorMock{ +// AttributesFunc: func() interface{} { +// panic("mock out the Attributes method") +// }, +// CategoryFunc: func() string { +// panic("mock out the Category method") +// }, +// DeviceClassFunc: func() deviceClass.SensorDeviceClass { +// panic("mock out the DeviceClass method") +// }, +// IDFunc: func() string { +// panic("mock out the ID method") +// }, +// IconFunc: func() string { +// panic("mock out the Icon method") +// }, +// NameFunc: func() string { +// panic("mock out the Name method") +// }, +// SensorTypeFunc: func() sensorType.SensorType { +// panic("mock out the SensorType method") +// }, +// StateFunc: func() interface{} { +// panic("mock out the State method") +// }, +// StateClassFunc: func() stateClass.SensorStateClass { +// panic("mock out the StateClass method") +// }, +// UnitsFunc: func() string { +// panic("mock out the Units method") +// }, +// } +// +// // use mockedSensor in code that requires Sensor +// // and then make assertions. +// +// } +type SensorMock struct { + // AttributesFunc mocks the Attributes method. + AttributesFunc func() interface{} + + // CategoryFunc mocks the Category method. + CategoryFunc func() string + + // DeviceClassFunc mocks the DeviceClass method. + DeviceClassFunc func() deviceClass.SensorDeviceClass + + // IDFunc mocks the ID method. + IDFunc func() string + + // IconFunc mocks the Icon method. + IconFunc func() string + + // NameFunc mocks the Name method. + NameFunc func() string + + // SensorTypeFunc mocks the SensorType method. + SensorTypeFunc func() sensorType.SensorType + + // StateFunc mocks the State method. + StateFunc func() interface{} + + // StateClassFunc mocks the StateClass method. + StateClassFunc func() stateClass.SensorStateClass + + // UnitsFunc mocks the Units method. + UnitsFunc func() string + + // calls tracks calls to the methods. + calls struct { + // Attributes holds details about calls to the Attributes method. + Attributes []struct { + } + // Category holds details about calls to the Category method. + Category []struct { + } + // DeviceClass holds details about calls to the DeviceClass method. + DeviceClass []struct { + } + // ID holds details about calls to the ID method. + ID []struct { + } + // Icon holds details about calls to the Icon method. + Icon []struct { + } + // Name holds details about calls to the Name method. + Name []struct { + } + // SensorType holds details about calls to the SensorType method. + SensorType []struct { + } + // State holds details about calls to the State method. + State []struct { + } + // StateClass holds details about calls to the StateClass method. + StateClass []struct { + } + // Units holds details about calls to the Units method. + Units []struct { + } + } + lockAttributes sync.RWMutex + lockCategory sync.RWMutex + lockDeviceClass sync.RWMutex + lockID sync.RWMutex + lockIcon sync.RWMutex + lockName sync.RWMutex + lockSensorType sync.RWMutex + lockState sync.RWMutex + lockStateClass sync.RWMutex + lockUnits sync.RWMutex +} + +// Attributes calls AttributesFunc. +func (mock *SensorMock) Attributes() interface{} { + if mock.AttributesFunc == nil { + panic("SensorMock.AttributesFunc: method is nil but Sensor.Attributes was just called") + } + callInfo := struct { + }{} + mock.lockAttributes.Lock() + mock.calls.Attributes = append(mock.calls.Attributes, callInfo) + mock.lockAttributes.Unlock() + return mock.AttributesFunc() +} + +// AttributesCalls gets all the calls that were made to Attributes. +// Check the length with: +// +// len(mockedSensor.AttributesCalls()) +func (mock *SensorMock) AttributesCalls() []struct { +} { + var calls []struct { + } + mock.lockAttributes.RLock() + calls = mock.calls.Attributes + mock.lockAttributes.RUnlock() + return calls +} + +// Category calls CategoryFunc. +func (mock *SensorMock) Category() string { + if mock.CategoryFunc == nil { + panic("SensorMock.CategoryFunc: method is nil but Sensor.Category was just called") + } + callInfo := struct { + }{} + mock.lockCategory.Lock() + mock.calls.Category = append(mock.calls.Category, callInfo) + mock.lockCategory.Unlock() + return mock.CategoryFunc() +} + +// CategoryCalls gets all the calls that were made to Category. +// Check the length with: +// +// len(mockedSensor.CategoryCalls()) +func (mock *SensorMock) CategoryCalls() []struct { +} { + var calls []struct { + } + mock.lockCategory.RLock() + calls = mock.calls.Category + mock.lockCategory.RUnlock() + return calls +} + +// DeviceClass calls DeviceClassFunc. +func (mock *SensorMock) DeviceClass() deviceClass.SensorDeviceClass { + if mock.DeviceClassFunc == nil { + panic("SensorMock.DeviceClassFunc: method is nil but Sensor.DeviceClass was just called") + } + callInfo := struct { + }{} + mock.lockDeviceClass.Lock() + mock.calls.DeviceClass = append(mock.calls.DeviceClass, callInfo) + mock.lockDeviceClass.Unlock() + return mock.DeviceClassFunc() +} + +// DeviceClassCalls gets all the calls that were made to DeviceClass. +// Check the length with: +// +// len(mockedSensor.DeviceClassCalls()) +func (mock *SensorMock) DeviceClassCalls() []struct { +} { + var calls []struct { + } + mock.lockDeviceClass.RLock() + calls = mock.calls.DeviceClass + mock.lockDeviceClass.RUnlock() + return calls +} + +// ID calls IDFunc. +func (mock *SensorMock) ID() string { + if mock.IDFunc == nil { + panic("SensorMock.IDFunc: method is nil but Sensor.ID was just called") + } + callInfo := struct { + }{} + mock.lockID.Lock() + mock.calls.ID = append(mock.calls.ID, callInfo) + mock.lockID.Unlock() + return mock.IDFunc() +} + +// IDCalls gets all the calls that were made to ID. +// Check the length with: +// +// len(mockedSensor.IDCalls()) +func (mock *SensorMock) IDCalls() []struct { +} { + var calls []struct { + } + mock.lockID.RLock() + calls = mock.calls.ID + mock.lockID.RUnlock() + return calls +} + +// Icon calls IconFunc. +func (mock *SensorMock) Icon() string { + if mock.IconFunc == nil { + panic("SensorMock.IconFunc: method is nil but Sensor.Icon was just called") + } + callInfo := struct { + }{} + mock.lockIcon.Lock() + mock.calls.Icon = append(mock.calls.Icon, callInfo) + mock.lockIcon.Unlock() + return mock.IconFunc() +} + +// IconCalls gets all the calls that were made to Icon. +// Check the length with: +// +// len(mockedSensor.IconCalls()) +func (mock *SensorMock) IconCalls() []struct { +} { + var calls []struct { + } + mock.lockIcon.RLock() + calls = mock.calls.Icon + mock.lockIcon.RUnlock() + return calls +} + +// Name calls NameFunc. +func (mock *SensorMock) Name() string { + if mock.NameFunc == nil { + panic("SensorMock.NameFunc: method is nil but Sensor.Name was just called") + } + callInfo := struct { + }{} + mock.lockName.Lock() + mock.calls.Name = append(mock.calls.Name, callInfo) + mock.lockName.Unlock() + return mock.NameFunc() +} + +// NameCalls gets all the calls that were made to Name. +// Check the length with: +// +// len(mockedSensor.NameCalls()) +func (mock *SensorMock) NameCalls() []struct { +} { + var calls []struct { + } + mock.lockName.RLock() + calls = mock.calls.Name + mock.lockName.RUnlock() + return calls +} + +// SensorType calls SensorTypeFunc. +func (mock *SensorMock) SensorType() sensorType.SensorType { + if mock.SensorTypeFunc == nil { + panic("SensorMock.SensorTypeFunc: method is nil but Sensor.SensorType was just called") + } + callInfo := struct { + }{} + mock.lockSensorType.Lock() + mock.calls.SensorType = append(mock.calls.SensorType, callInfo) + mock.lockSensorType.Unlock() + return mock.SensorTypeFunc() +} + +// SensorTypeCalls gets all the calls that were made to SensorType. +// Check the length with: +// +// len(mockedSensor.SensorTypeCalls()) +func (mock *SensorMock) SensorTypeCalls() []struct { +} { + var calls []struct { + } + mock.lockSensorType.RLock() + calls = mock.calls.SensorType + mock.lockSensorType.RUnlock() + return calls +} + +// State calls StateFunc. +func (mock *SensorMock) State() interface{} { + if mock.StateFunc == nil { + panic("SensorMock.StateFunc: method is nil but Sensor.State was just called") + } + callInfo := struct { + }{} + mock.lockState.Lock() + mock.calls.State = append(mock.calls.State, callInfo) + mock.lockState.Unlock() + return mock.StateFunc() +} + +// StateCalls gets all the calls that were made to State. +// Check the length with: +// +// len(mockedSensor.StateCalls()) +func (mock *SensorMock) StateCalls() []struct { +} { + var calls []struct { + } + mock.lockState.RLock() + calls = mock.calls.State + mock.lockState.RUnlock() + return calls +} + +// StateClass calls StateClassFunc. +func (mock *SensorMock) StateClass() stateClass.SensorStateClass { + if mock.StateClassFunc == nil { + panic("SensorMock.StateClassFunc: method is nil but Sensor.StateClass was just called") + } + callInfo := struct { + }{} + mock.lockStateClass.Lock() + mock.calls.StateClass = append(mock.calls.StateClass, callInfo) + mock.lockStateClass.Unlock() + return mock.StateClassFunc() +} + +// StateClassCalls gets all the calls that were made to StateClass. +// Check the length with: +// +// len(mockedSensor.StateClassCalls()) +func (mock *SensorMock) StateClassCalls() []struct { +} { + var calls []struct { + } + mock.lockStateClass.RLock() + calls = mock.calls.StateClass + mock.lockStateClass.RUnlock() + return calls +} + +// Units calls UnitsFunc. +func (mock *SensorMock) Units() string { + if mock.UnitsFunc == nil { + panic("SensorMock.UnitsFunc: method is nil but Sensor.Units was just called") + } + callInfo := struct { + }{} + mock.lockUnits.Lock() + mock.calls.Units = append(mock.calls.Units, callInfo) + mock.lockUnits.Unlock() + return mock.UnitsFunc() +} + +// UnitsCalls gets all the calls that were made to Units. +// Check the length with: +// +// len(mockedSensor.UnitsCalls()) +func (mock *SensorMock) UnitsCalls() []struct { +} { + var calls []struct { + } + mock.lockUnits.RLock() + calls = mock.calls.Units + mock.lockUnits.RUnlock() + return calls +} diff --git a/internal/tracker/mocks/Registry.go b/internal/tracker/mocks/Registry.go deleted file mode 100644 index 38f68fc60..000000000 --- a/internal/tracker/mocks/Registry.go +++ /dev/null @@ -1,112 +0,0 @@ -// Code generated by mockery v2.30.16. DO NOT EDIT. - -package mocks - -import ( - context "context" - - mock "github.com/stretchr/testify/mock" -) - -// Registry is an autogenerated mock type for the Registry type -type Registry struct { - mock.Mock -} - -// Close provides a mock function with given fields: -func (_m *Registry) Close() error { - ret := _m.Called() - - var r0 error - if rf, ok := ret.Get(0).(func() error); ok { - r0 = rf() - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// IsDisabled provides a mock function with given fields: _a0 -func (_m *Registry) IsDisabled(_a0 string) bool { - ret := _m.Called(_a0) - - var r0 bool - if rf, ok := ret.Get(0).(func(string) bool); ok { - r0 = rf(_a0) - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// IsRegistered provides a mock function with given fields: _a0 -func (_m *Registry) IsRegistered(_a0 string) bool { - ret := _m.Called(_a0) - - var r0 bool - if rf, ok := ret.Get(0).(func(string) bool); ok { - r0 = rf(_a0) - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// Open provides a mock function with given fields: _a0, _a1 -func (_m *Registry) Open(_a0 context.Context, _a1 string) error { - ret := _m.Called(_a0, _a1) - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// SetDisabled provides a mock function with given fields: _a0, _a1 -func (_m *Registry) SetDisabled(_a0 string, _a1 bool) error { - ret := _m.Called(_a0, _a1) - - var r0 error - if rf, ok := ret.Get(0).(func(string, bool) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// SetRegistered provides a mock function with given fields: _a0, _a1 -func (_m *Registry) SetRegistered(_a0 string, _a1 bool) error { - ret := _m.Called(_a0, _a1) - - var r0 error - if rf, ok := ret.Get(0).(func(string, bool) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// NewRegistry creates a new instance of Registry. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewRegistry(t interface { - mock.TestingT - Cleanup(func()) -}) *Registry { - mock := &Registry{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/internal/tracker/mocks/Sensor.go b/internal/tracker/mocks/Sensor.go deleted file mode 100644 index 2aa0b45a5..000000000 --- a/internal/tracker/mocks/Sensor.go +++ /dev/null @@ -1,175 +0,0 @@ -// Code generated by mockery v2.30.16. DO NOT EDIT. - -package mocks - -import ( - deviceClass "github.com/joshuar/go-hass-agent/internal/hass/deviceClass" - mock "github.com/stretchr/testify/mock" - - sensorType "github.com/joshuar/go-hass-agent/internal/hass/sensorType" - - stateClass "github.com/joshuar/go-hass-agent/internal/hass/stateClass" -) - -// Sensor is an autogenerated mock type for the Sensor type -type Sensor struct { - mock.Mock -} - -// Attributes provides a mock function with given fields: -func (_m *Sensor) Attributes() interface{} { - ret := _m.Called() - - var r0 interface{} - if rf, ok := ret.Get(0).(func() interface{}); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(interface{}) - } - } - - return r0 -} - -// Category provides a mock function with given fields: -func (_m *Sensor) Category() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// DeviceClass provides a mock function with given fields: -func (_m *Sensor) DeviceClass() deviceClass.SensorDeviceClass { - ret := _m.Called() - - var r0 deviceClass.SensorDeviceClass - if rf, ok := ret.Get(0).(func() deviceClass.SensorDeviceClass); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(deviceClass.SensorDeviceClass) - } - - return r0 -} - -// ID provides a mock function with given fields: -func (_m *Sensor) ID() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// Icon provides a mock function with given fields: -func (_m *Sensor) Icon() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// Name provides a mock function with given fields: -func (_m *Sensor) Name() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// SensorType provides a mock function with given fields: -func (_m *Sensor) SensorType() sensorType.SensorType { - ret := _m.Called() - - var r0 sensorType.SensorType - if rf, ok := ret.Get(0).(func() sensorType.SensorType); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(sensorType.SensorType) - } - - return r0 -} - -// State provides a mock function with given fields: -func (_m *Sensor) State() interface{} { - ret := _m.Called() - - var r0 interface{} - if rf, ok := ret.Get(0).(func() interface{}); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(interface{}) - } - } - - return r0 -} - -// StateClass provides a mock function with given fields: -func (_m *Sensor) StateClass() stateClass.SensorStateClass { - ret := _m.Called() - - var r0 stateClass.SensorStateClass - if rf, ok := ret.Get(0).(func() stateClass.SensorStateClass); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(stateClass.SensorStateClass) - } - - return r0 -} - -// Units provides a mock function with given fields: -func (_m *Sensor) Units() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// NewSensor creates a new instance of Sensor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewSensor(t interface { - mock.TestingT - Cleanup(func()) -}) *Sensor { - mock := &Sensor{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/internal/tracker/registry.go b/internal/tracker/registry.go index 8317ec762..b2def985c 100644 --- a/internal/tracker/registry.go +++ b/internal/tracker/registry.go @@ -9,7 +9,7 @@ import ( "context" ) -//go:generate mockery --name Registry +//go:generate moq -out mock_Registry_test.go . Registry type Registry interface { Open(context.Context, string) error Close() error diff --git a/internal/tracker/sensor.go b/internal/tracker/sensor.go index 437014b45..6c6d9f367 100644 --- a/internal/tracker/sensor.go +++ b/internal/tracker/sensor.go @@ -16,7 +16,7 @@ import ( // of the sensor at the point in time it is used. It provides a bridge between // platform/device and HA implementations of what a sensor is. // -//go:generate mockery --name Sensor +//go:generate moq -out mock_Sensor_test.go . Sensor type Sensor interface { Name() string ID() string