From a9b61f84070cc7ca0d6e26f187c745619a91422a Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Thu, 27 Jul 2023 19:03:41 +0200 Subject: init --- api/api_service_mock_test.go | 80 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 api/api_service_mock_test.go (limited to 'api/api_service_mock_test.go') diff --git a/api/api_service_mock_test.go b/api/api_service_mock_test.go new file mode 100644 index 0000000..a7536be --- /dev/null +++ b/api/api_service_mock_test.go @@ -0,0 +1,80 @@ +// Code generated by moq; DO NOT EDIT. +// github.com/matryer/moq + +package api + +import ( + "sync" +) + +// Ensure, that ServiceMock does implement Service. +// If this is not the case, regenerate this file with moq. +var _ Service = &ServiceMock{} + +// ServiceMock is a mock implementation of Service. +// +// func TestSomethingThatUsesService(t *testing.T) { +// +// // make and configure a mocked Service +// mockedService := &ServiceMock{ +// ScrapeURLFunc: func(url string, params map[string]any) (any, error) { +// panic("mock out the ScrapeURL method") +// }, +// } +// +// // use mockedService in code that requires Service +// // and then make assertions. +// +// } +type ServiceMock struct { + // ScrapeURLFunc mocks the ScrapeURL method. + ScrapeURLFunc func(url string, params map[string]any) (any, error) + + // calls tracks calls to the methods. + calls struct { + // ScrapeURL holds details about calls to the ScrapeURL method. + ScrapeURL []struct { + // URL is the url argument value. + URL string + // Params is the params argument value. + Params map[string]any + } + } + lockScrapeURL sync.RWMutex +} + +// ScrapeURL calls ScrapeURLFunc. +func (mock *ServiceMock) ScrapeURL(url string, params map[string]any) (any, error) { + if mock.ScrapeURLFunc == nil { + panic("ServiceMock.ScrapeURLFunc: method is nil but Service.ScrapeURL was just called") + } + callInfo := struct { + URL string + Params map[string]any + }{ + URL: url, + Params: params, + } + mock.lockScrapeURL.Lock() + mock.calls.ScrapeURL = append(mock.calls.ScrapeURL, callInfo) + mock.lockScrapeURL.Unlock() + return mock.ScrapeURLFunc(url, params) +} + +// ScrapeURLCalls gets all the calls that were made to ScrapeURL. +// Check the length with: +// +// len(mockedService.ScrapeURLCalls()) +func (mock *ServiceMock) ScrapeURLCalls() []struct { + URL string + Params map[string]any +} { + var calls []struct { + URL string + Params map[string]any + } + mock.lockScrapeURL.RLock() + calls = mock.calls.ScrapeURL + mock.lockScrapeURL.RUnlock() + return calls +} -- cgit v1.2.3