From 90362a3dbcf44db031b3ef6073ca7ca762cedc3b Mon Sep 17 00:00:00 2001 From: Igor Nemilentsev Date: Tue, 7 May 2024 23:42:27 +0300 Subject: [PATCH] Mockery tests --- .mockery.yaml | 18 +++ Makefile | 23 +++- go.mod | 1 + go.sum | 1 + internal/fakeapi/api.go | 11 +- internal/files/download.go | 46 +------ internal/files/testing/download_file_test.go | 26 ---- pkg/api/api.go | 16 +-- pkg/api/testing/translate_words_test.go | 27 ---- pkg/translator/download.go | 41 ++++++ pkg/translator/download_file_test.go | 27 ++++ pkg/translator/get_word_test.go | 23 +++- pkg/translator/linguleo.go | 67 +++++++++- pkg/translator/mock_Downloader.go | 88 +++++++++++++ pkg/translator/mock_Translator.go | 128 +++++++++++++++++++ pkg/translator/mock_decodeFunc.go | 79 ++++++++++++ pkg/translator/mock_processResult.go | 81 ++++++++++++ 17 files changed, 575 insertions(+), 128 deletions(-) create mode 100644 .mockery.yaml delete mode 100644 internal/files/testing/download_file_test.go delete mode 100644 pkg/api/testing/translate_words_test.go create mode 100644 pkg/translator/download.go create mode 100644 pkg/translator/download_file_test.go create mode 100644 pkg/translator/mock_Downloader.go create mode 100644 pkg/translator/mock_Translator.go create mode 100644 pkg/translator/mock_decodeFunc.go create mode 100644 pkg/translator/mock_processResult.go diff --git a/.mockery.yaml b/.mockery.yaml new file mode 100644 index 0000000..88e91df --- /dev/null +++ b/.mockery.yaml @@ -0,0 +1,18 @@ +testonly: false +with-expecter: true +# inpackage: true +# dir: mocks/{{ replaceAll .InterfaceDirRelative "internal" "internal_" }} +# mockname: "{{.InterfaceName}}" +# outpkg: "{{.PackageName}}" +filename: "{{.InterfaceName}}.go" +all: true +packages: + github.com/trezorg/lingualeo/pkg/translator: + config: + recursive: true + with-expecter: true + mockname: "Mock_{{.InterfaceName}}" + # outpkg: mocks + dir: ./{{ replaceAll .InterfaceDirRelative "internal" "internal_" }} + filename: "mock_{{.InterfaceName}}.go" + inpackage: true diff --git a/Makefile b/Makefile index e9efe81..01d59fe 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ DEST := $(GOPATH)/src/$(GIT_HOST)/$(BASE_DIR) SOURCES := $(shell find $(DEST) -name '*.go' 2>/dev/null) HAS_GOLANGCI := $(shell command -v golangci-lint;) HAS_GOIMPORTS := $(shell command -v goimports;) +HAS_MOCKERY := $(shell command -v mockery;) TARGETS ?= darwin/amd64 linux/amd64 linux/386 linux/arm linux/arm64 linux/ppc64le linux/s390x DIST_DIRS = find * -type d -exec @@ -66,7 +67,7 @@ fmt: goimports: ifndef HAS_GOIMPORTS echo "installing goimports" - GO111MODULE=off go get golang.org/x/tools/cmd/goimports + go install golang.org/x/tools/cmd/goimports@latest endif goimports -d $(shell find . -path ./.go -prune -o -type f -iname "*.go") find . -iname "*.go" @@ -76,24 +77,36 @@ vet: golangci: ifndef HAS_GOLANGCI - curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.49.0 + curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.58.0 endif golangci-lint run +generate: +ifndef HAS_MOCKERY + echo "installing mockery" + go install github.com/vektra/mockery/v2@latest +endif + go generate ./... + cover: work go test $(TESTARGS) -tags=unit -cover -coverpkg=./ ./... prepare: ifndef HAS_GOLANGCI - curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.49.0 + curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.58.0 endif echo "golangci-lint already installed" ifndef HAS_GOIMPORTS echo "installing goimports" - GO111MODULE=off go get golang.org/x/tools/cmd/goimports + go install golang.org/x/tools/cmd/goimports@latest endif echo "goimports already installed" +ifndef HAS_MOCKERY + echo "installing mockery" + go install github.com/vektra/mockery/v2@latest +endif + echo "mockery already installed" shell: $(SHELL) -i @@ -104,4 +117,4 @@ clean: work version: @echo ${VERSION} -.PHONY: install build cover work fmt test version clean prepare +.PHONY: install build cover work fmt test version clean prepare generate diff --git a/go.mod b/go.mod index df4b2d0..082d2d4 100644 --- a/go.mod +++ b/go.mod @@ -21,6 +21,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/russross/blackfriday/v2 v2.0.1 // indirect github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect + github.com/stretchr/objx v0.1.0 // indirect golang.org/x/sys v0.18.0 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect ) diff --git a/go.sum b/go.sum index f5af0bd..71191b8 100644 --- a/go.sum +++ b/go.sum @@ -22,6 +22,7 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5I github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q= github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo= +github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= diff --git a/internal/fakeapi/api.go b/internal/fakeapi/api.go index 3eaaf22..85ca185 100644 --- a/internal/fakeapi/api.go +++ b/internal/fakeapi/api.go @@ -10,7 +10,8 @@ import ( ) var ( - responseData = []byte(`{"error_msg":"","translate_source":"base","is_user":0, + SoundURL = "http://audiocdn.lingualeo.com/v2/3/102085-631152000.mp3" + ResponseData = []byte(`{"error_msg":"","translate_source":"base","is_user":0, "word_forms":[{"word":"accommodation","type":"прил."}], "pic_url":"http:\/\/contentcdn.lingualeo.com\/uploads\/picture\/3589594.png", "translate":[ @@ -25,19 +26,17 @@ var ( SearchWord = "accommodation" ) -type FakeAPI struct { - api.Translator -} +type FakeAPI struct{} func (f *FakeAPI) TranslateWord(word string) api.OperationResult { res := api.Result{Word: word} - err := res.FromResponse(responseData) + err := res.FromResponse(ResponseData) return api.OperationResult{Result: res, Error: err} } func (f *FakeAPI) AddWord(word string, _ []string) api.OperationResult { res := api.Result{Word: word} - err := res.FromResponse(responseData) + err := res.FromResponse(ResponseData) return api.OperationResult{Result: res, Error: err} } diff --git a/internal/files/download.go b/internal/files/download.go index ed103bb..a44a483 100644 --- a/internal/files/download.go +++ b/internal/files/download.go @@ -1,28 +1,18 @@ package files import ( - "context" "fmt" "io" "net/http" "os" - "sync" "github.com/trezorg/lingualeo/internal/logger" - "github.com/trezorg/lingualeo/pkg/channel" ) -const fileTemplate = "lingualeo" -const filePath = "/tmp" - -// Downloader interface -type Downloader interface { - Download(url string) (string, error) - Writer() (io.WriteCloser, string, error) -} - -// NewDownloader function type -type NewDownloader func(url string) Downloader +const ( + fileTemplate = "lingualeo" + filePath = "/tmp" +) // File represents file for downloading type File struct { @@ -37,8 +27,7 @@ func (f File) GetIndex() int { } // FileDownloader structure -type FileDownloader struct { -} +type FileDownloader struct{} // NewFileDownloader initialize new file downloader func NewFileDownloader() *FileDownloader { @@ -89,28 +78,3 @@ func (f *FileDownloader) Download(url string) (string, error) { } return filename, nil } - -// DownloadFiles download files from URLs channel -func DownloadFiles(ctx context.Context, urls <-chan string, downloader Downloader) <-chan File { - out := make(chan File) - var wg sync.WaitGroup - wg.Add(1) - go func() { - defer wg.Done() - idx := 0 - for url := range channel.OrDone(ctx, urls) { - wg.Add(1) - go func(idx int, url string) { - defer wg.Done() - filename, err := downloader.Download(url) - out <- File{Error: err, Filename: filename, Index: idx} - }(idx, url) - idx++ - } - }() - go func() { - defer close(out) - wg.Wait() - }() - return out -} diff --git a/internal/files/testing/download_file_test.go b/internal/files/testing/download_file_test.go deleted file mode 100644 index aa18052..0000000 --- a/internal/files/testing/download_file_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package testing - -import ( - "context" - "testing" - - "github.com/trezorg/lingualeo/internal/fakeapi" - - "github.com/trezorg/lingualeo/internal/files" - - "github.com/stretchr/testify/assert" -) - -func TestDownloadWordFile(t *testing.T) { - - inChan := make(chan string, 1) - inChan <- "http://test.com/file" - - ctx := context.Background() - - close(inChan) - - out := files.DownloadFiles(ctx, inChan, &fakeapi.FakeFileDownloader{}) - fileName := (<-out).Filename - assert.Equal(t, fileName, fakeapi.TestFile) -} diff --git a/pkg/api/api.go b/pkg/api/api.go index 5cdb19e..f28a6f2 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -24,14 +24,6 @@ import ( "golang.org/x/net/publicsuffix" ) -// Translator interface -type Translator interface { - translateWord(word string) OperationResult - TranslateWords(ctx context.Context, results <-chan string) <-chan OperationResult - addWord(word string, translate []string) OperationResult - AddWords(ctx context.Context, results <-chan Result) <-chan OperationResult -} - // API structure represents API request type API struct { client *http.Client @@ -226,7 +218,7 @@ func (api *API) addRequest(word string, translate []string) ([]byte, error) { return request("POST", addWordURL, api.client, jsonValue, "", api.Debug) } -func (api *API) translateWord(word string) OperationResult { +func (api *API) TranslateWord(word string) OperationResult { body, err := api.translateRequest(word) if err != nil { return OperationResult{Error: err} @@ -234,7 +226,7 @@ func (api *API) translateWord(word string) OperationResult { return opResultFromBody(word, body) } -func (api *API) addWord(word string, translate []string) OperationResult { +func (api *API) AddWord(word string, translate []string) OperationResult { body, err := api.addRequest(word, translate) if err != nil { return OperationResult{Error: err} @@ -253,7 +245,7 @@ func (api *API) TranslateWords(ctx context.Context, results <-chan string) <-cha wg.Add(1) go func(word string) { defer wg.Done() - out <- api.translateWord(word) + out <- api.TranslateWord(word) }(word) } }() @@ -276,7 +268,7 @@ func (api *API) AddWords(ctx context.Context, results <-chan Result) <-chan Oper result := res go func(result Result) { defer wg.Done() - out <- api.addWord(result.Word, result.Words) + out <- api.AddWord(result.Word, result.Words) }(result) } }() diff --git a/pkg/api/testing/translate_words_test.go b/pkg/api/testing/translate_words_test.go deleted file mode 100644 index caa661d..0000000 --- a/pkg/api/testing/translate_words_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package testing - -import ( - "context" - "testing" - - "github.com/trezorg/lingualeo/internal/fakeapi" - "github.com/trezorg/lingualeo/pkg/channel" - - "github.com/stretchr/testify/assert" -) - -func TestTranslateWord(t *testing.T) { - res := (&fakeapi.FakeAPI{}).TranslateWord(fakeapi.SearchWord) - assert.NoError(t, res.Error, "Cannot get object from json") - fakeapi.CheckResult(t, res.Result, fakeapi.SearchWord, fakeapi.Expected) -} - -func TestTranslateWords(t *testing.T) { - searchWords := []string{fakeapi.SearchWord} - fakeAPI := fakeapi.FakeAPI{} - ctx := context.Background() - ch := channel.ToChannel(ctx, searchWords...) - out := fakeAPI.TranslateWords(ctx, ch) - res := (<-out).Result - fakeapi.CheckResult(t, res, searchWords[0], fakeapi.Expected) -} diff --git a/pkg/translator/download.go b/pkg/translator/download.go new file mode 100644 index 0000000..5252f8a --- /dev/null +++ b/pkg/translator/download.go @@ -0,0 +1,41 @@ +package translator + +import ( + "context" + "sync" + + "github.com/trezorg/lingualeo/internal/files" + "github.com/trezorg/lingualeo/pkg/channel" +) + +// Downloader interface +// +//go:generate mockery +type Downloader interface { + Download(url string) (string, error) +} + +// DownloadFiles download files from URLs channel +func DownloadFiles(ctx context.Context, urls <-chan string, downloader Downloader) <-chan files.File { + out := make(chan files.File) + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Done() + idx := 0 + for url := range channel.OrDone(ctx, urls) { + wg.Add(1) + go func(idx int, url string) { + defer wg.Done() + filename, err := downloader.Download(url) + out <- files.File{Error: err, Filename: filename, Index: idx} + }(idx, url) + idx++ + } + }() + go func() { + defer close(out) + wg.Wait() + }() + return out +} diff --git a/pkg/translator/download_file_test.go b/pkg/translator/download_file_test.go new file mode 100644 index 0000000..bc22d76 --- /dev/null +++ b/pkg/translator/download_file_test.go @@ -0,0 +1,27 @@ +package translator + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestDownloadWordFile(t *testing.T) { + downloader := NewMock_Downloader(t) + url := "http://test.com/file" + testFile := "/tmp/test.file" + + downloader.EXPECT().Download(url).Return(testFile, nil).Once() + + inChan := make(chan string, 1) + inChan <- url + + ctx := context.Background() + + close(inChan) + + out := DownloadFiles(ctx, inChan, downloader) + fileName := (<-out).Filename + assert.Equal(t, fileName, testFile) +} diff --git a/pkg/translator/get_word_test.go b/pkg/translator/get_word_test.go index 4b3a3f3..bf09fcb 100644 --- a/pkg/translator/get_word_test.go +++ b/pkg/translator/get_word_test.go @@ -6,13 +6,28 @@ import ( "testing" "github.com/trezorg/lingualeo/internal/logger" + "github.com/trezorg/lingualeo/pkg/api" "github.com/trezorg/lingualeo/internal/fakeapi" ) -func TestProcessTranslationResponseJson(t *testing.T) { +func translateWordResult(word string) api.OperationResult { + res := api.Result{Word: word} + err := res.FromResponse(fakeapi.ResponseData) + return api.OperationResult{Result: res, Error: err} +} +func TestProcessTranslationResponseJson(t *testing.T) { + downloader := NewMock_Downloader(t) + testFile := "/tmp/test.file" count := 1000 // max for race checking + translator := NewMock_Translator(t) + + res := translateWordResult(fakeapi.SearchWord) + + downloader.EXPECT().Download(fakeapi.SoundURL).Return(testFile, nil).Times(count) + translator.EXPECT().TranslateWord(fakeapi.SearchWord).Return(res).Times(count) + logger.InitLogger("FATAL", true) searchWords := make([]string, 0, count) @@ -20,21 +35,19 @@ func TestProcessTranslationResponseJson(t *testing.T) { searchWords = append(searchWords, fakeapi.SearchWord) } ctx := context.Background() - fakeAPI := fakeapi.FakeAPI{} - args := Lingualeo{Sound: true, Words: searchWords, Add: false, API: &fakeAPI} + args := Lingualeo{Sound: true, Words: searchWords, Add: false, Translator: translator} var wg sync.WaitGroup wg.Add(1) soundChan, _, resultChan := args.Process(ctx, &wg) wg.Add(1) - go args.downloadAndPronounce(ctx, soundChan, &wg, &fakeapi.FakeFileDownloader{}) + go args.downloadAndPronounce(ctx, soundChan, &wg, downloader) for result := range resultChan { fakeapi.CheckResult(t, result, searchWords[0], fakeapi.Expected) } wg.Wait() - } diff --git a/pkg/translator/linguleo.go b/pkg/translator/linguleo.go index 42580c2..662ea61 100644 --- a/pkg/translator/linguleo.go +++ b/pkg/translator/linguleo.go @@ -37,8 +37,16 @@ func (args *Lingualeo) checkMediaPlayer() { } } +// Translator interface +// +//go:generate mockery +type Translator interface { + TranslateWord(word string) api.OperationResult + AddWord(word string, translate []string) api.OperationResult +} + type Lingualeo struct { - API api.Translator + Translator Translator LogLevel string `yaml:"log_level" json:"log_level" toml:"log_level"` Password string `yaml:"password" json:"password" toml:"password"` Config string @@ -81,19 +89,65 @@ func New(version string) (Lingualeo, error) { } logger.InitLogger(client.LogLevel, client.LogPrettyPrint) client.checkMediaPlayer() - client.API, err = api.New(client.Email, client.Password, client.Debug) + client.Translator, err = api.New(client.Email, client.Password, client.Debug) if err != nil { return client, err } return client, nil } +// translateWords translate words from string channel +func translateWords(ctx context.Context, translator Translator, results <-chan string) <-chan api.OperationResult { + out := make(chan api.OperationResult) + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Done() + for word := range channel.OrDone(ctx, results) { + wg.Add(1) + go func(word string) { + defer wg.Done() + out <- translator.TranslateWord(word) + }(word) + } + }() + go func() { + defer close(out) + wg.Wait() + }() + return out +} + +// addWords add words +func addWords(ctx context.Context, translator Translator, results <-chan api.Result) <-chan api.OperationResult { + out := make(chan api.OperationResult) + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Done() + for res := range channel.OrDone(ctx, results) { + wg.Add(1) + result := res + go func(result api.Result) { + defer wg.Done() + out <- translator.AddWord(result.Word, result.Words) + }(result) + } + }() + go func() { + defer close(out) + wg.Wait() + }() + return out +} + func (args *Lingualeo) translateWords(ctx context.Context) <-chan api.OperationResult { results := make(chan api.OperationResult, len(args.Words)) input := channel.ToChannel(ctx, args.Words...) go func() { defer close(results) - for res := range channel.OrDone(ctx, args.API.TranslateWords(ctx, input)) { + ch := translateWords(ctx, args.Translator, input) + for res := range channel.OrDone(ctx, ch) { if res.Error != nil { err := messages.Message( messages.RED, @@ -130,9 +184,9 @@ func (args *Lingualeo) prepareResultToAdd(result *api.Result) bool { return false } -func (args *Lingualeo) downloadAndPronounce(ctx context.Context, urls <-chan string, wg *sync.WaitGroup, downloader files.Downloader) { +func (args *Lingualeo) downloadAndPronounce(ctx context.Context, urls <-chan string, wg *sync.WaitGroup, downloader Downloader) { defer wg.Done() - fileChannel := files.OrderedChannel(files.DownloadFiles(ctx, urls, downloader), len(urls)) + fileChannel := files.OrderedChannel(DownloadFiles(ctx, urls, downloader), len(urls)) for res := range channel.OrDone(ctx, fileChannel) { if res.Error != nil { logger.Error(res.Error) @@ -174,7 +228,8 @@ func (args *Lingualeo) Pronounce(ctx context.Context, urls <-chan string, wg *sy // AddToDictionary adds words to dictionary func (args *Lingualeo) AddToDictionary(ctx context.Context, resultsToAdd <-chan api.Result, wg *sync.WaitGroup) { defer wg.Done() - for res := range args.API.AddWords(ctx, resultsToAdd) { + ch := addWords(ctx, args.Translator, resultsToAdd) + for res := range ch { if res.Error != nil { logger.Error(res.Error) continue diff --git a/pkg/translator/mock_Downloader.go b/pkg/translator/mock_Downloader.go new file mode 100644 index 0000000..2ce77b9 --- /dev/null +++ b/pkg/translator/mock_Downloader.go @@ -0,0 +1,88 @@ +// Code generated by mockery v2.43.0. DO NOT EDIT. + +package translator + +import mock "github.com/stretchr/testify/mock" + +// Mock_Downloader is an autogenerated mock type for the Downloader type +type Mock_Downloader struct { + mock.Mock +} + +type Mock_Downloader_Expecter struct { + mock *mock.Mock +} + +func (_m *Mock_Downloader) EXPECT() *Mock_Downloader_Expecter { + return &Mock_Downloader_Expecter{mock: &_m.Mock} +} + +// Download provides a mock function with given fields: url +func (_m *Mock_Downloader) Download(url string) (string, error) { + ret := _m.Called(url) + + if len(ret) == 0 { + panic("no return value specified for Download") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(string) (string, error)); ok { + return rf(url) + } + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(url) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(url) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Mock_Downloader_Download_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Download' +type Mock_Downloader_Download_Call struct { + *mock.Call +} + +// Download is a helper method to define mock.On call +// - url string +func (_e *Mock_Downloader_Expecter) Download(url interface{}) *Mock_Downloader_Download_Call { + return &Mock_Downloader_Download_Call{Call: _e.mock.On("Download", url)} +} + +func (_c *Mock_Downloader_Download_Call) Run(run func(url string)) *Mock_Downloader_Download_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Mock_Downloader_Download_Call) Return(_a0 string, _a1 error) *Mock_Downloader_Download_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Mock_Downloader_Download_Call) RunAndReturn(run func(string) (string, error)) *Mock_Downloader_Download_Call { + _c.Call.Return(run) + return _c +} + +// NewMock_Downloader creates a new instance of Mock_Downloader. 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 NewMock_Downloader(t interface { + mock.TestingT + Cleanup(func()) +}) *Mock_Downloader { + mock := &Mock_Downloader{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/translator/mock_Translator.go b/pkg/translator/mock_Translator.go new file mode 100644 index 0000000..96b82b3 --- /dev/null +++ b/pkg/translator/mock_Translator.go @@ -0,0 +1,128 @@ +// Code generated by mockery v2.43.0. DO NOT EDIT. + +package translator + +import ( + mock "github.com/stretchr/testify/mock" + api "github.com/trezorg/lingualeo/pkg/api" +) + +// Mock_Translator is an autogenerated mock type for the Translator type +type Mock_Translator struct { + mock.Mock +} + +type Mock_Translator_Expecter struct { + mock *mock.Mock +} + +func (_m *Mock_Translator) EXPECT() *Mock_Translator_Expecter { + return &Mock_Translator_Expecter{mock: &_m.Mock} +} + +// AddWord provides a mock function with given fields: word, translate +func (_m *Mock_Translator) AddWord(word string, translate []string) api.OperationResult { + ret := _m.Called(word, translate) + + if len(ret) == 0 { + panic("no return value specified for AddWord") + } + + var r0 api.OperationResult + if rf, ok := ret.Get(0).(func(string, []string) api.OperationResult); ok { + r0 = rf(word, translate) + } else { + r0 = ret.Get(0).(api.OperationResult) + } + + return r0 +} + +// Mock_Translator_AddWord_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddWord' +type Mock_Translator_AddWord_Call struct { + *mock.Call +} + +// AddWord is a helper method to define mock.On call +// - word string +// - translate []string +func (_e *Mock_Translator_Expecter) AddWord(word interface{}, translate interface{}) *Mock_Translator_AddWord_Call { + return &Mock_Translator_AddWord_Call{Call: _e.mock.On("AddWord", word, translate)} +} + +func (_c *Mock_Translator_AddWord_Call) Run(run func(word string, translate []string)) *Mock_Translator_AddWord_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].([]string)) + }) + return _c +} + +func (_c *Mock_Translator_AddWord_Call) Return(_a0 api.OperationResult) *Mock_Translator_AddWord_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Mock_Translator_AddWord_Call) RunAndReturn(run func(string, []string) api.OperationResult) *Mock_Translator_AddWord_Call { + _c.Call.Return(run) + return _c +} + +// TranslateWord provides a mock function with given fields: word +func (_m *Mock_Translator) TranslateWord(word string) api.OperationResult { + ret := _m.Called(word) + + if len(ret) == 0 { + panic("no return value specified for TranslateWord") + } + + var r0 api.OperationResult + if rf, ok := ret.Get(0).(func(string) api.OperationResult); ok { + r0 = rf(word) + } else { + r0 = ret.Get(0).(api.OperationResult) + } + + return r0 +} + +// Mock_Translator_TranslateWord_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TranslateWord' +type Mock_Translator_TranslateWord_Call struct { + *mock.Call +} + +// TranslateWord is a helper method to define mock.On call +// - word string +func (_e *Mock_Translator_Expecter) TranslateWord(word interface{}) *Mock_Translator_TranslateWord_Call { + return &Mock_Translator_TranslateWord_Call{Call: _e.mock.On("TranslateWord", word)} +} + +func (_c *Mock_Translator_TranslateWord_Call) Run(run func(word string)) *Mock_Translator_TranslateWord_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Mock_Translator_TranslateWord_Call) Return(_a0 api.OperationResult) *Mock_Translator_TranslateWord_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Mock_Translator_TranslateWord_Call) RunAndReturn(run func(string) api.OperationResult) *Mock_Translator_TranslateWord_Call { + _c.Call.Return(run) + return _c +} + +// NewMock_Translator creates a new instance of Mock_Translator. 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 NewMock_Translator(t interface { + mock.TestingT + Cleanup(func()) +}) *Mock_Translator { + mock := &Mock_Translator{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/translator/mock_decodeFunc.go b/pkg/translator/mock_decodeFunc.go new file mode 100644 index 0000000..be75d16 --- /dev/null +++ b/pkg/translator/mock_decodeFunc.go @@ -0,0 +1,79 @@ +// Code generated by mockery v2.43.0. DO NOT EDIT. + +package translator + +import mock "github.com/stretchr/testify/mock" + +// Mock_decodeFunc is an autogenerated mock type for the decodeFunc type +type Mock_decodeFunc struct { + mock.Mock +} + +type Mock_decodeFunc_Expecter struct { + mock *mock.Mock +} + +func (_m *Mock_decodeFunc) EXPECT() *Mock_decodeFunc_Expecter { + return &Mock_decodeFunc_Expecter{mock: &_m.Mock} +} + +// Execute provides a mock function with given fields: data, args +func (_m *Mock_decodeFunc) Execute(data []byte, args *Lingualeo) error { + ret := _m.Called(data, args) + + if len(ret) == 0 { + panic("no return value specified for Execute") + } + + var r0 error + if rf, ok := ret.Get(0).(func([]byte, *Lingualeo) error); ok { + r0 = rf(data, args) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Mock_decodeFunc_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' +type Mock_decodeFunc_Execute_Call struct { + *mock.Call +} + +// Execute is a helper method to define mock.On call +// - data []byte +// - args *Lingualeo +func (_e *Mock_decodeFunc_Expecter) Execute(data interface{}, args interface{}) *Mock_decodeFunc_Execute_Call { + return &Mock_decodeFunc_Execute_Call{Call: _e.mock.On("Execute", data, args)} +} + +func (_c *Mock_decodeFunc_Execute_Call) Run(run func(data []byte, args *Lingualeo)) *Mock_decodeFunc_Execute_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]byte), args[1].(*Lingualeo)) + }) + return _c +} + +func (_c *Mock_decodeFunc_Execute_Call) Return(_a0 error) *Mock_decodeFunc_Execute_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Mock_decodeFunc_Execute_Call) RunAndReturn(run func([]byte, *Lingualeo) error) *Mock_decodeFunc_Execute_Call { + _c.Call.Return(run) + return _c +} + +// NewMock_decodeFunc creates a new instance of Mock_decodeFunc. 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 NewMock_decodeFunc(t interface { + mock.TestingT + Cleanup(func()) +}) *Mock_decodeFunc { + mock := &Mock_decodeFunc{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/translator/mock_processResult.go b/pkg/translator/mock_processResult.go new file mode 100644 index 0000000..a6df6f2 --- /dev/null +++ b/pkg/translator/mock_processResult.go @@ -0,0 +1,81 @@ +// Code generated by mockery v2.43.0. DO NOT EDIT. + +package translator + +import ( + mock "github.com/stretchr/testify/mock" + api "github.com/trezorg/lingualeo/pkg/api" +) + +// Mock_processResult is an autogenerated mock type for the processResult type +type Mock_processResult struct { + mock.Mock +} + +type Mock_processResult_Expecter struct { + mock *mock.Mock +} + +func (_m *Mock_processResult) EXPECT() *Mock_processResult_Expecter { + return &Mock_processResult_Expecter{mock: &_m.Mock} +} + +// Execute provides a mock function with given fields: _a0 +func (_m *Mock_processResult) Execute(_a0 api.Result) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Execute") + } + + var r0 error + if rf, ok := ret.Get(0).(func(api.Result) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Mock_processResult_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' +type Mock_processResult_Execute_Call struct { + *mock.Call +} + +// Execute is a helper method to define mock.On call +// - _a0 api.Result +func (_e *Mock_processResult_Expecter) Execute(_a0 interface{}) *Mock_processResult_Execute_Call { + return &Mock_processResult_Execute_Call{Call: _e.mock.On("Execute", _a0)} +} + +func (_c *Mock_processResult_Execute_Call) Run(run func(_a0 api.Result)) *Mock_processResult_Execute_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(api.Result)) + }) + return _c +} + +func (_c *Mock_processResult_Execute_Call) Return(_a0 error) *Mock_processResult_Execute_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Mock_processResult_Execute_Call) RunAndReturn(run func(api.Result) error) *Mock_processResult_Execute_Call { + _c.Call.Return(run) + return _c +} + +// NewMock_processResult creates a new instance of Mock_processResult. 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 NewMock_processResult(t interface { + mock.TestingT + Cleanup(func()) +}) *Mock_processResult { + mock := &Mock_processResult{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +}