From 066fd3479a925eb7bd99b7b2e916b5d1455a6066 Mon Sep 17 00:00:00 2001 From: Matias Daloia <66310421+matiasdaloia@users.noreply.github.com> Date: Fri, 11 Oct 2024 10:19:25 +0200 Subject: [PATCH] Add test workflow + unit tests (#54) * Add test workflow * Add .mockery.yaml file, generate all interface mocks * Add file module unit tests * Add config module unit tests * Use t.TempDir() instead of os.TempDir() for tests * Cancel in progress workflows * Remove test * Fix component controller test * Fix testutils --- .github/workflows/test.yml | 44 +++ .mockery.yaml | 9 + backend/main/internal/testutils.go | 67 +--- .../config_repository_json_impl_test.go | 106 ++++++ .../repository/mocks/mock_ConfigRepository.go | 168 +++++++++ .../service/config_service_impl_test.go | 46 +++ .../service/mocks/mock_ConfigService.go | 90 +++++ .../mocks/mock_ScanossSettingsController.go | 132 +++++++ .../mocks/mock_ScanossSettingsRepository.go | 329 +++++++++++++++++ .../service/mocks/ScanossSettingsService.go | 132 ------- .../mocks/mock_ScanossSettingsService.go | 132 +++++++ .../service/scanoss_settings_service.go | 1 - .../component_controller_impl_test.go | 87 ++--- .../mocks/mock_ComponentController.go | 337 ++++++++++++++++++ .../component/entities/mocks/mock_License.go | 32 ++ .../mocks/mock_ComponentRepository.go | 91 +++++ .../service/mocks/mock_ComponentService.go | 243 +++++++++++++ .../controllers/file_controller_impl_test.go | 79 ++++ .../controllers/mocks/mock_FileController.go | 147 ++++++++ .../repository/file_repository_impl_test.go | 56 +++ .../repository/mocks/mock_FileRepository.go | 204 +++++++++++ .../file/service/file_service_impl_test.go | 72 ++++ .../file/service/mocks/mock_FileService.go | 148 ++++++++ .../controllers/mocks/ResultController.go | 93 ----- .../mocks/mock_ResultController.go | 93 +++++ .../result/controllers/result_controller.go | 1 - .../result_controller_impl_test.go | 8 +- .../pkg/result/entities/mocks/ResultFilter.go | 81 ----- .../entities/mocks/mock_ResultFilter.go | 81 +++++ backend/main/pkg/result/entities/result.go | 1 - .../pkg/result/mappers/mocks/ResultMapper.go | 130 ------- .../result/mappers/mocks/mock_ResultMapper.go | 130 +++++++ .../main/pkg/result/mappers/result_mapper.go | 1 - .../repository/mocks/ResultRepository.go | 93 ----- .../repository/mocks/mock_ResultRepository.go | 93 +++++ .../result/repository/result_repository.go | 1 - .../result_repository_json_impl_test.go | 4 +- .../pkg/result/service/mocks/ResultService.go | 93 ----- .../service/mocks/mock_ResultService.go | 93 +++++ .../main/pkg/result/service/result_service.go | 1 - .../service/result_service_impl_test.go | 6 +- .../main/pkg/utils/mocks/mock_FileReader.go | 90 +++++ 42 files changed, 3096 insertions(+), 749 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 .mockery.yaml create mode 100644 backend/main/pkg/common/config/repository/config_repository_json_impl_test.go create mode 100644 backend/main/pkg/common/config/repository/mocks/mock_ConfigRepository.go create mode 100644 backend/main/pkg/common/config/service/config_service_impl_test.go create mode 100644 backend/main/pkg/common/config/service/mocks/mock_ConfigService.go create mode 100644 backend/main/pkg/common/scanoss_settings/controllers/mocks/mock_ScanossSettingsController.go create mode 100644 backend/main/pkg/common/scanoss_settings/repository/mocks/mock_ScanossSettingsRepository.go delete mode 100644 backend/main/pkg/common/scanoss_settings/service/mocks/ScanossSettingsService.go create mode 100644 backend/main/pkg/common/scanoss_settings/service/mocks/mock_ScanossSettingsService.go create mode 100644 backend/main/pkg/component/controllers/mocks/mock_ComponentController.go create mode 100644 backend/main/pkg/component/entities/mocks/mock_License.go create mode 100644 backend/main/pkg/component/repository/mocks/mock_ComponentRepository.go create mode 100644 backend/main/pkg/component/service/mocks/mock_ComponentService.go create mode 100644 backend/main/pkg/file/controllers/file_controller_impl_test.go create mode 100644 backend/main/pkg/file/controllers/mocks/mock_FileController.go create mode 100644 backend/main/pkg/file/repository/file_repository_impl_test.go create mode 100644 backend/main/pkg/file/repository/mocks/mock_FileRepository.go create mode 100644 backend/main/pkg/file/service/file_service_impl_test.go create mode 100644 backend/main/pkg/file/service/mocks/mock_FileService.go delete mode 100644 backend/main/pkg/result/controllers/mocks/ResultController.go create mode 100644 backend/main/pkg/result/controllers/mocks/mock_ResultController.go delete mode 100644 backend/main/pkg/result/entities/mocks/ResultFilter.go create mode 100644 backend/main/pkg/result/entities/mocks/mock_ResultFilter.go delete mode 100644 backend/main/pkg/result/mappers/mocks/ResultMapper.go create mode 100644 backend/main/pkg/result/mappers/mocks/mock_ResultMapper.go delete mode 100644 backend/main/pkg/result/repository/mocks/ResultRepository.go create mode 100644 backend/main/pkg/result/repository/mocks/mock_ResultRepository.go delete mode 100644 backend/main/pkg/result/service/mocks/ResultService.go create mode 100644 backend/main/pkg/result/service/mocks/mock_ResultService.go create mode 100644 backend/main/pkg/utils/mocks/mock_FileReader.go diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..b157ddf --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,44 @@ +name: Test + +on: + workflow_dispatch: + pull_request: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + GOLANG_VERSION: "1.21" + NODE_VERSION: "16.x" + +jobs: + test-go: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Install Wails + run: go install github.com/wailsapp/wails/v2/cmd/wails@latest + shell: bash + + - name: Install Linux Wails deps + run: sudo apt-get update && sudo apt-get install libgtk-3-0 libwebkit2gtk-4.0-dev gcc-aarch64-linux-gnu + shell: bash + + - name: Build + run: | + mkdir build + cp -r assets build/assets + wails build + shell: bash + + - name: Run tests + uses: robherley/go-test-action@v0 diff --git a/.mockery.yaml b/.mockery.yaml new file mode 100644 index 0000000..002a8ae --- /dev/null +++ b/.mockery.yaml @@ -0,0 +1,9 @@ +dir: "{{.InterfaceDir}}/mocks" +mockname: "Mock{{.InterfaceName}}" +outpkg: "mocks" +with-expecter: True +all: True +packages: + github.com/scanoss/scanoss.lui: + config: + recursive: True diff --git a/backend/main/internal/testutils.go b/backend/main/internal/testutils.go index c24ecec..8939e0f 100644 --- a/backend/main/internal/testutils.go +++ b/backend/main/internal/testutils.go @@ -1,76 +1,33 @@ package internal_test import ( - "os" "testing" "github.com/scanoss/scanoss.lui/backend/main/pkg/common/config" - "github.com/scanoss/scanoss.lui/backend/main/pkg/common/scanoss_settings/repository" "github.com/stretchr/testify/mock" - - configEntities "github.com/scanoss/scanoss.lui/backend/main/pkg/common/config/entities" - "github.com/scanoss/scanoss.lui/backend/main/pkg/common/scanoss_settings/entities" - "github.com/scanoss/scanoss.lui/backend/main/pkg/utils" ) -func SetupTestFiles(t *testing.T) string { - t.Helper() - - scanSettingsFile, err := os.CreateTemp("", "scanoss-*.json") - if err != nil { - t.Fatalf("Failed to create temp file: %v", err) - } - scanSettingsFilePath := scanSettingsFile.Name() - - initialScanSettings := entities.SettingsFile{ - Bom: entities.Bom{ - Include: []entities.ComponentFilter{}, - Remove: []entities.ComponentFilter{}, - }, - } - scanSettingsFile.Close() - if err := utils.WriteJsonFile(scanSettingsFilePath, initialScanSettings); err != nil { - t.Fatalf("Failed to write initial scan settings file: %v", err) - } - - return scanSettingsFilePath -} - -func InitializeConfig(scanSettingsFilePath string) *configEntities.Config { - config := &configEntities.Config{ - ScanSettingsFilePath: scanSettingsFilePath, - } - - return config -} - func InitializeTestEnvironment(t *testing.T) func() { t.Helper() - scanSettingsFilePath := SetupTestFiles(t) - - InitializeConfig(scanSettingsFilePath) + cfgPath := t.TempDir() + "/config.json" + configModule := config.NewConfigModule(cfgPath) - cleanup := func() { - os.Remove(scanSettingsFilePath) + err := configModule.Init() + if err != nil { + t.Fatalf("Error initializing config: %s", err.Error()) } - cfg := config.NewConfigModule(scanSettingsFilePath) - cfg.Init() - cfg.LoadConfig() - - fr := utils.NewDefaultFileReader() - r := repository.NewScanossSettingsJsonRepository(fr) - settingsFile, err := r.Read() + err = configModule.LoadConfig() if err != nil { - t.Fatal(err.Error()) - } - // Init Scanoss bom module. Set current bom file to singleton - entities.ScanossSettingsJson = &entities.ScanossSettings{ - SettingsFile: &settingsFile, + t.Fatalf("Error loading config: %s", err.Error()) } - return cleanup + configModule.Config.ScanRoot = t.TempDir() + + return func() { + configModule = nil + } } type MockUtils struct { diff --git a/backend/main/pkg/common/config/repository/config_repository_json_impl_test.go b/backend/main/pkg/common/config/repository/config_repository_json_impl_test.go new file mode 100644 index 0000000..5cd79b9 --- /dev/null +++ b/backend/main/pkg/common/config/repository/config_repository_json_impl_test.go @@ -0,0 +1,106 @@ +package repository + +import ( + "os" + "path/filepath" + "testing" + + "github.com/scanoss/scanoss.lui/backend/main/pkg/common/config/entities" + "github.com/scanoss/scanoss.lui/backend/main/pkg/utils" + "github.com/stretchr/testify/assert" +) + +func TestNewConfigJsonRepository(t *testing.T) { + path := "config.json" + repo := NewConfigJsonRepository(path) + assert.Equal(t, path, repo.configPath) +} + +func TestConfigJsonRepository_Init(t *testing.T) { + path := "config.json" + repo := NewConfigJsonRepository(path) + + err := repo.Init() + assert.NoError(t, err) + + fileExists := utils.FileExist(path) + assert.NoError(t, fileExists) + + os.Remove(path) +} + +func TestConfigJsonRepository_Save(t *testing.T) { + path := t.TempDir() + "config.json" + repo := NewConfigJsonRepository(path) + + err := repo.Init() + assert.NoError(t, err) + + config := &entities.Config{ + ApiUrl: "https://api.scanoss.org", + ApiToken: "test-token", + } + + repo.Save(config) + + fileData, err := os.ReadFile(path) + assert.NoError(t, err) + + savedData, err := utils.JSONParse[map[string]string](fileData) + assert.NoError(t, err) + + assert.NoError(t, err) + assert.Equal(t, config.ApiUrl, savedData["apiUrl"]) + assert.Equal(t, config.ApiToken, savedData["apiToken"]) + + os.Remove(path) +} + +func TestConfigJsonRepository_Read(t *testing.T) { + path := t.TempDir() + "config.json" + repo := NewConfigJsonRepository(path) + config := &entities.Config{ + ApiUrl: "https://api.scanoss.org", + ApiToken: "test-token", + } + + err := repo.Init() + assert.NoError(t, err) + + repo.Save(config) + + readConfig, err := repo.Read() + + assert.NoError(t, err) + assert.Equal(t, config.ApiUrl, readConfig.ApiUrl) + assert.Equal(t, config.ApiToken, readConfig.ApiToken) + + os.Remove(path) +} + +func TestConfigJsonRepository_createConfigFile(t *testing.T) { + path := "/tmp/test_config.json" + repo := NewConfigJsonRepository(path) + + err := repo.createConfigFile() + assert.NoError(t, err) + + fileExists := utils.FileExist(path) + assert.NoError(t, fileExists) + + os.Remove(path) +} + +func TestGetDefaultConfigFile(t *testing.T) { + defaultConfig := getDefaultConfigFile() + + workingDir, _ := os.Getwd() + expectedResultFilePath := filepath.Join(workingDir, ".scanoss", "results.json") + expectedScanSettingsFilePath := filepath.Join(workingDir, "scanoss.json") + + assert.Equal(t, "", defaultConfig.ScanRoot) + assert.Equal(t, expectedResultFilePath, defaultConfig.ResultFilePath) + assert.Equal(t, "", defaultConfig.ApiToken) + assert.Equal(t, "https://api.osskb.org", defaultConfig.ApiUrl) + assert.Equal(t, expectedScanSettingsFilePath, defaultConfig.ScanSettingsFilePath) +} diff --git a/backend/main/pkg/common/config/repository/mocks/mock_ConfigRepository.go b/backend/main/pkg/common/config/repository/mocks/mock_ConfigRepository.go new file mode 100644 index 0000000..da4e96a --- /dev/null +++ b/backend/main/pkg/common/config/repository/mocks/mock_ConfigRepository.go @@ -0,0 +1,168 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import ( + entities "github.com/scanoss/scanoss.lui/backend/main/pkg/common/config/entities" + mock "github.com/stretchr/testify/mock" +) + +// MockConfigRepository is an autogenerated mock type for the ConfigRepository type +type MockConfigRepository struct { + mock.Mock +} + +type MockConfigRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockConfigRepository) EXPECT() *MockConfigRepository_Expecter { + return &MockConfigRepository_Expecter{mock: &_m.Mock} +} + +// Init provides a mock function with given fields: +func (_m *MockConfigRepository) Init() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Init") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockConfigRepository_Init_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Init' +type MockConfigRepository_Init_Call struct { + *mock.Call +} + +// Init is a helper method to define mock.On call +func (_e *MockConfigRepository_Expecter) Init() *MockConfigRepository_Init_Call { + return &MockConfigRepository_Init_Call{Call: _e.mock.On("Init")} +} + +func (_c *MockConfigRepository_Init_Call) Run(run func()) *MockConfigRepository_Init_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockConfigRepository_Init_Call) Return(_a0 error) *MockConfigRepository_Init_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockConfigRepository_Init_Call) RunAndReturn(run func() error) *MockConfigRepository_Init_Call { + _c.Call.Return(run) + return _c +} + +// Read provides a mock function with given fields: +func (_m *MockConfigRepository) Read() (entities.Config, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Read") + } + + var r0 entities.Config + var r1 error + if rf, ok := ret.Get(0).(func() (entities.Config, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() entities.Config); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(entities.Config) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockConfigRepository_Read_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Read' +type MockConfigRepository_Read_Call struct { + *mock.Call +} + +// Read is a helper method to define mock.On call +func (_e *MockConfigRepository_Expecter) Read() *MockConfigRepository_Read_Call { + return &MockConfigRepository_Read_Call{Call: _e.mock.On("Read")} +} + +func (_c *MockConfigRepository_Read_Call) Run(run func()) *MockConfigRepository_Read_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockConfigRepository_Read_Call) Return(_a0 entities.Config, _a1 error) *MockConfigRepository_Read_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockConfigRepository_Read_Call) RunAndReturn(run func() (entities.Config, error)) *MockConfigRepository_Read_Call { + _c.Call.Return(run) + return _c +} + +// Save provides a mock function with given fields: config +func (_m *MockConfigRepository) Save(config *entities.Config) { + _m.Called(config) +} + +// MockConfigRepository_Save_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Save' +type MockConfigRepository_Save_Call struct { + *mock.Call +} + +// Save is a helper method to define mock.On call +// - config *entities.Config +func (_e *MockConfigRepository_Expecter) Save(config interface{}) *MockConfigRepository_Save_Call { + return &MockConfigRepository_Save_Call{Call: _e.mock.On("Save", config)} +} + +func (_c *MockConfigRepository_Save_Call) Run(run func(config *entities.Config)) *MockConfigRepository_Save_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*entities.Config)) + }) + return _c +} + +func (_c *MockConfigRepository_Save_Call) Return() *MockConfigRepository_Save_Call { + _c.Call.Return() + return _c +} + +func (_c *MockConfigRepository_Save_Call) RunAndReturn(run func(*entities.Config)) *MockConfigRepository_Save_Call { + _c.Call.Return(run) + return _c +} + +// NewMockConfigRepository creates a new instance of MockConfigRepository. 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 NewMockConfigRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockConfigRepository { + mock := &MockConfigRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/common/config/service/config_service_impl_test.go b/backend/main/pkg/common/config/service/config_service_impl_test.go new file mode 100644 index 0000000..ba7c843 --- /dev/null +++ b/backend/main/pkg/common/config/service/config_service_impl_test.go @@ -0,0 +1,46 @@ +package service + +import ( + "errors" + "testing" + + "github.com/scanoss/scanoss.lui/backend/main/pkg/common/config/entities" + "github.com/scanoss/scanoss.lui/backend/main/pkg/common/config/repository/mocks" + "github.com/stretchr/testify/assert" +) + +func TestReadConfig_Success(t *testing.T) { + mockRepo := mocks.NewMockConfigRepository(t) + expectedConfig := entities.Config{ + ApiToken: "test-api-token", + ApiUrl: "http://api.scanoss.com/v1", + ResultFilePath: ".scanoss/results.json", + ScanRoot: "frontend/src", + } + + mockRepo.EXPECT().Read().Return(expectedConfig, nil) + + service := NewConfigService(mockRepo) + + config, err := service.ReadConfig() + + assert.NoError(t, err) + assert.Equal(t, expectedConfig, config) + mockRepo.AssertExpectations(t) +} + +func TestReadConfig_Error(t *testing.T) { + mockRepo := mocks.NewMockConfigRepository(t) + expectedError := errors.New("read error") + + mockRepo.EXPECT().Read().Return(entities.Config{}, expectedError) + + service := NewConfigService(mockRepo) + + config, err := service.ReadConfig() + + assert.Error(t, err) + assert.Equal(t, expectedError, err) + assert.Equal(t, entities.Config{}, config) + mockRepo.AssertExpectations(t) +} diff --git a/backend/main/pkg/common/config/service/mocks/mock_ConfigService.go b/backend/main/pkg/common/config/service/mocks/mock_ConfigService.go new file mode 100644 index 0000000..df2c047 --- /dev/null +++ b/backend/main/pkg/common/config/service/mocks/mock_ConfigService.go @@ -0,0 +1,90 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import ( + entities "github.com/scanoss/scanoss.lui/backend/main/pkg/common/config/entities" + mock "github.com/stretchr/testify/mock" +) + +// MockConfigService is an autogenerated mock type for the ConfigService type +type MockConfigService struct { + mock.Mock +} + +type MockConfigService_Expecter struct { + mock *mock.Mock +} + +func (_m *MockConfigService) EXPECT() *MockConfigService_Expecter { + return &MockConfigService_Expecter{mock: &_m.Mock} +} + +// ReadConfig provides a mock function with given fields: +func (_m *MockConfigService) ReadConfig() (entities.Config, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for ReadConfig") + } + + var r0 entities.Config + var r1 error + if rf, ok := ret.Get(0).(func() (entities.Config, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() entities.Config); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(entities.Config) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockConfigService_ReadConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReadConfig' +type MockConfigService_ReadConfig_Call struct { + *mock.Call +} + +// ReadConfig is a helper method to define mock.On call +func (_e *MockConfigService_Expecter) ReadConfig() *MockConfigService_ReadConfig_Call { + return &MockConfigService_ReadConfig_Call{Call: _e.mock.On("ReadConfig")} +} + +func (_c *MockConfigService_ReadConfig_Call) Run(run func()) *MockConfigService_ReadConfig_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockConfigService_ReadConfig_Call) Return(_a0 entities.Config, _a1 error) *MockConfigService_ReadConfig_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockConfigService_ReadConfig_Call) RunAndReturn(run func() (entities.Config, error)) *MockConfigService_ReadConfig_Call { + _c.Call.Return(run) + return _c +} + +// NewMockConfigService creates a new instance of MockConfigService. 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 NewMockConfigService(t interface { + mock.TestingT + Cleanup(func()) +}) *MockConfigService { + mock := &MockConfigService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/common/scanoss_settings/controllers/mocks/mock_ScanossSettingsController.go b/backend/main/pkg/common/scanoss_settings/controllers/mocks/mock_ScanossSettingsController.go new file mode 100644 index 0000000..f37aea0 --- /dev/null +++ b/backend/main/pkg/common/scanoss_settings/controllers/mocks/mock_ScanossSettingsController.go @@ -0,0 +1,132 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// MockScanossSettingsController is an autogenerated mock type for the ScanossSettingsController type +type MockScanossSettingsController struct { + mock.Mock +} + +type MockScanossSettingsController_Expecter struct { + mock *mock.Mock +} + +func (_m *MockScanossSettingsController) EXPECT() *MockScanossSettingsController_Expecter { + return &MockScanossSettingsController_Expecter{mock: &_m.Mock} +} + +// HasUnsavedChanges provides a mock function with given fields: +func (_m *MockScanossSettingsController) HasUnsavedChanges() (bool, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for HasUnsavedChanges") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func() (bool, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockScanossSettingsController_HasUnsavedChanges_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HasUnsavedChanges' +type MockScanossSettingsController_HasUnsavedChanges_Call struct { + *mock.Call +} + +// HasUnsavedChanges is a helper method to define mock.On call +func (_e *MockScanossSettingsController_Expecter) HasUnsavedChanges() *MockScanossSettingsController_HasUnsavedChanges_Call { + return &MockScanossSettingsController_HasUnsavedChanges_Call{Call: _e.mock.On("HasUnsavedChanges")} +} + +func (_c *MockScanossSettingsController_HasUnsavedChanges_Call) Run(run func()) *MockScanossSettingsController_HasUnsavedChanges_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockScanossSettingsController_HasUnsavedChanges_Call) Return(_a0 bool, _a1 error) *MockScanossSettingsController_HasUnsavedChanges_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockScanossSettingsController_HasUnsavedChanges_Call) RunAndReturn(run func() (bool, error)) *MockScanossSettingsController_HasUnsavedChanges_Call { + _c.Call.Return(run) + return _c +} + +// Save provides a mock function with given fields: +func (_m *MockScanossSettingsController) Save() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Save") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockScanossSettingsController_Save_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Save' +type MockScanossSettingsController_Save_Call struct { + *mock.Call +} + +// Save is a helper method to define mock.On call +func (_e *MockScanossSettingsController_Expecter) Save() *MockScanossSettingsController_Save_Call { + return &MockScanossSettingsController_Save_Call{Call: _e.mock.On("Save")} +} + +func (_c *MockScanossSettingsController_Save_Call) Run(run func()) *MockScanossSettingsController_Save_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockScanossSettingsController_Save_Call) Return(_a0 error) *MockScanossSettingsController_Save_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockScanossSettingsController_Save_Call) RunAndReturn(run func() error) *MockScanossSettingsController_Save_Call { + _c.Call.Return(run) + return _c +} + +// NewMockScanossSettingsController creates a new instance of MockScanossSettingsController. 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 NewMockScanossSettingsController(t interface { + mock.TestingT + Cleanup(func()) +}) *MockScanossSettingsController { + mock := &MockScanossSettingsController{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/common/scanoss_settings/repository/mocks/mock_ScanossSettingsRepository.go b/backend/main/pkg/common/scanoss_settings/repository/mocks/mock_ScanossSettingsRepository.go new file mode 100644 index 0000000..f2cdedc --- /dev/null +++ b/backend/main/pkg/common/scanoss_settings/repository/mocks/mock_ScanossSettingsRepository.go @@ -0,0 +1,329 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import ( + entities "github.com/scanoss/scanoss.lui/backend/main/pkg/common/scanoss_settings/entities" + mock "github.com/stretchr/testify/mock" +) + +// MockScanossSettingsRepository is an autogenerated mock type for the ScanossSettingsRepository type +type MockScanossSettingsRepository struct { + mock.Mock +} + +type MockScanossSettingsRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockScanossSettingsRepository) EXPECT() *MockScanossSettingsRepository_Expecter { + return &MockScanossSettingsRepository_Expecter{mock: &_m.Mock} +} + +// AddBomEntry provides a mock function with given fields: newEntry, filterAction +func (_m *MockScanossSettingsRepository) AddBomEntry(newEntry entities.ComponentFilter, filterAction string) error { + ret := _m.Called(newEntry, filterAction) + + if len(ret) == 0 { + panic("no return value specified for AddBomEntry") + } + + var r0 error + if rf, ok := ret.Get(0).(func(entities.ComponentFilter, string) error); ok { + r0 = rf(newEntry, filterAction) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockScanossSettingsRepository_AddBomEntry_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddBomEntry' +type MockScanossSettingsRepository_AddBomEntry_Call struct { + *mock.Call +} + +// AddBomEntry is a helper method to define mock.On call +// - newEntry entities.ComponentFilter +// - filterAction string +func (_e *MockScanossSettingsRepository_Expecter) AddBomEntry(newEntry interface{}, filterAction interface{}) *MockScanossSettingsRepository_AddBomEntry_Call { + return &MockScanossSettingsRepository_AddBomEntry_Call{Call: _e.mock.On("AddBomEntry", newEntry, filterAction)} +} + +func (_c *MockScanossSettingsRepository_AddBomEntry_Call) Run(run func(newEntry entities.ComponentFilter, filterAction string)) *MockScanossSettingsRepository_AddBomEntry_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(entities.ComponentFilter), args[1].(string)) + }) + return _c +} + +func (_c *MockScanossSettingsRepository_AddBomEntry_Call) Return(_a0 error) *MockScanossSettingsRepository_AddBomEntry_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockScanossSettingsRepository_AddBomEntry_Call) RunAndReturn(run func(entities.ComponentFilter, string) error) *MockScanossSettingsRepository_AddBomEntry_Call { + _c.Call.Return(run) + return _c +} + +// ClearAllFilters provides a mock function with given fields: +func (_m *MockScanossSettingsRepository) ClearAllFilters() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for ClearAllFilters") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockScanossSettingsRepository_ClearAllFilters_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ClearAllFilters' +type MockScanossSettingsRepository_ClearAllFilters_Call struct { + *mock.Call +} + +// ClearAllFilters is a helper method to define mock.On call +func (_e *MockScanossSettingsRepository_Expecter) ClearAllFilters() *MockScanossSettingsRepository_ClearAllFilters_Call { + return &MockScanossSettingsRepository_ClearAllFilters_Call{Call: _e.mock.On("ClearAllFilters")} +} + +func (_c *MockScanossSettingsRepository_ClearAllFilters_Call) Run(run func()) *MockScanossSettingsRepository_ClearAllFilters_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockScanossSettingsRepository_ClearAllFilters_Call) Return(_a0 error) *MockScanossSettingsRepository_ClearAllFilters_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockScanossSettingsRepository_ClearAllFilters_Call) RunAndReturn(run func() error) *MockScanossSettingsRepository_ClearAllFilters_Call { + _c.Call.Return(run) + return _c +} + +// GetSettingsFileContent provides a mock function with given fields: +func (_m *MockScanossSettingsRepository) GetSettingsFileContent() *entities.SettingsFile { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetSettingsFileContent") + } + + var r0 *entities.SettingsFile + if rf, ok := ret.Get(0).(func() *entities.SettingsFile); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*entities.SettingsFile) + } + } + + return r0 +} + +// MockScanossSettingsRepository_GetSettingsFileContent_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetSettingsFileContent' +type MockScanossSettingsRepository_GetSettingsFileContent_Call struct { + *mock.Call +} + +// GetSettingsFileContent is a helper method to define mock.On call +func (_e *MockScanossSettingsRepository_Expecter) GetSettingsFileContent() *MockScanossSettingsRepository_GetSettingsFileContent_Call { + return &MockScanossSettingsRepository_GetSettingsFileContent_Call{Call: _e.mock.On("GetSettingsFileContent")} +} + +func (_c *MockScanossSettingsRepository_GetSettingsFileContent_Call) Run(run func()) *MockScanossSettingsRepository_GetSettingsFileContent_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockScanossSettingsRepository_GetSettingsFileContent_Call) Return(_a0 *entities.SettingsFile) *MockScanossSettingsRepository_GetSettingsFileContent_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockScanossSettingsRepository_GetSettingsFileContent_Call) RunAndReturn(run func() *entities.SettingsFile) *MockScanossSettingsRepository_GetSettingsFileContent_Call { + _c.Call.Return(run) + return _c +} + +// HasUnsavedChanges provides a mock function with given fields: +func (_m *MockScanossSettingsRepository) HasUnsavedChanges() (bool, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for HasUnsavedChanges") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func() (bool, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockScanossSettingsRepository_HasUnsavedChanges_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HasUnsavedChanges' +type MockScanossSettingsRepository_HasUnsavedChanges_Call struct { + *mock.Call +} + +// HasUnsavedChanges is a helper method to define mock.On call +func (_e *MockScanossSettingsRepository_Expecter) HasUnsavedChanges() *MockScanossSettingsRepository_HasUnsavedChanges_Call { + return &MockScanossSettingsRepository_HasUnsavedChanges_Call{Call: _e.mock.On("HasUnsavedChanges")} +} + +func (_c *MockScanossSettingsRepository_HasUnsavedChanges_Call) Run(run func()) *MockScanossSettingsRepository_HasUnsavedChanges_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockScanossSettingsRepository_HasUnsavedChanges_Call) Return(_a0 bool, _a1 error) *MockScanossSettingsRepository_HasUnsavedChanges_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockScanossSettingsRepository_HasUnsavedChanges_Call) RunAndReturn(run func() (bool, error)) *MockScanossSettingsRepository_HasUnsavedChanges_Call { + _c.Call.Return(run) + return _c +} + +// Read provides a mock function with given fields: +func (_m *MockScanossSettingsRepository) Read() (entities.SettingsFile, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Read") + } + + var r0 entities.SettingsFile + var r1 error + if rf, ok := ret.Get(0).(func() (entities.SettingsFile, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() entities.SettingsFile); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(entities.SettingsFile) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockScanossSettingsRepository_Read_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Read' +type MockScanossSettingsRepository_Read_Call struct { + *mock.Call +} + +// Read is a helper method to define mock.On call +func (_e *MockScanossSettingsRepository_Expecter) Read() *MockScanossSettingsRepository_Read_Call { + return &MockScanossSettingsRepository_Read_Call{Call: _e.mock.On("Read")} +} + +func (_c *MockScanossSettingsRepository_Read_Call) Run(run func()) *MockScanossSettingsRepository_Read_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockScanossSettingsRepository_Read_Call) Return(_a0 entities.SettingsFile, _a1 error) *MockScanossSettingsRepository_Read_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockScanossSettingsRepository_Read_Call) RunAndReturn(run func() (entities.SettingsFile, error)) *MockScanossSettingsRepository_Read_Call { + _c.Call.Return(run) + return _c +} + +// Save provides a mock function with given fields: +func (_m *MockScanossSettingsRepository) Save() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Save") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockScanossSettingsRepository_Save_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Save' +type MockScanossSettingsRepository_Save_Call struct { + *mock.Call +} + +// Save is a helper method to define mock.On call +func (_e *MockScanossSettingsRepository_Expecter) Save() *MockScanossSettingsRepository_Save_Call { + return &MockScanossSettingsRepository_Save_Call{Call: _e.mock.On("Save")} +} + +func (_c *MockScanossSettingsRepository_Save_Call) Run(run func()) *MockScanossSettingsRepository_Save_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockScanossSettingsRepository_Save_Call) Return(_a0 error) *MockScanossSettingsRepository_Save_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockScanossSettingsRepository_Save_Call) RunAndReturn(run func() error) *MockScanossSettingsRepository_Save_Call { + _c.Call.Return(run) + return _c +} + +// NewMockScanossSettingsRepository creates a new instance of MockScanossSettingsRepository. 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 NewMockScanossSettingsRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockScanossSettingsRepository { + mock := &MockScanossSettingsRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/common/scanoss_settings/service/mocks/ScanossSettingsService.go b/backend/main/pkg/common/scanoss_settings/service/mocks/ScanossSettingsService.go deleted file mode 100644 index 124441c..0000000 --- a/backend/main/pkg/common/scanoss_settings/service/mocks/ScanossSettingsService.go +++ /dev/null @@ -1,132 +0,0 @@ -// Code generated by mockery v2.46.1. DO NOT EDIT. - -package mocks - -import mock "github.com/stretchr/testify/mock" - -// ScanossSettingsService is an autogenerated mock type for the ScanossSettingsService type -type ScanossSettingsService struct { - mock.Mock -} - -type ScanossSettingsService_Expecter struct { - mock *mock.Mock -} - -func (_m *ScanossSettingsService) EXPECT() *ScanossSettingsService_Expecter { - return &ScanossSettingsService_Expecter{mock: &_m.Mock} -} - -// HasUnsavedChanges provides a mock function with given fields: -func (_m *ScanossSettingsService) HasUnsavedChanges() (bool, error) { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for HasUnsavedChanges") - } - - var r0 bool - var r1 error - if rf, ok := ret.Get(0).(func() (bool, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() bool); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(bool) - } - - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// ScanossSettingsService_HasUnsavedChanges_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HasUnsavedChanges' -type ScanossSettingsService_HasUnsavedChanges_Call struct { - *mock.Call -} - -// HasUnsavedChanges is a helper method to define mock.On call -func (_e *ScanossSettingsService_Expecter) HasUnsavedChanges() *ScanossSettingsService_HasUnsavedChanges_Call { - return &ScanossSettingsService_HasUnsavedChanges_Call{Call: _e.mock.On("HasUnsavedChanges")} -} - -func (_c *ScanossSettingsService_HasUnsavedChanges_Call) Run(run func()) *ScanossSettingsService_HasUnsavedChanges_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *ScanossSettingsService_HasUnsavedChanges_Call) Return(_a0 bool, _a1 error) *ScanossSettingsService_HasUnsavedChanges_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *ScanossSettingsService_HasUnsavedChanges_Call) RunAndReturn(run func() (bool, error)) *ScanossSettingsService_HasUnsavedChanges_Call { - _c.Call.Return(run) - return _c -} - -// Save provides a mock function with given fields: -func (_m *ScanossSettingsService) Save() error { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Save") - } - - var r0 error - if rf, ok := ret.Get(0).(func() error); ok { - r0 = rf() - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// ScanossSettingsService_Save_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Save' -type ScanossSettingsService_Save_Call struct { - *mock.Call -} - -// Save is a helper method to define mock.On call -func (_e *ScanossSettingsService_Expecter) Save() *ScanossSettingsService_Save_Call { - return &ScanossSettingsService_Save_Call{Call: _e.mock.On("Save")} -} - -func (_c *ScanossSettingsService_Save_Call) Run(run func()) *ScanossSettingsService_Save_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *ScanossSettingsService_Save_Call) Return(_a0 error) *ScanossSettingsService_Save_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *ScanossSettingsService_Save_Call) RunAndReturn(run func() error) *ScanossSettingsService_Save_Call { - _c.Call.Return(run) - return _c -} - -// NewScanossSettingsService creates a new instance of ScanossSettingsService. 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 NewScanossSettingsService(t interface { - mock.TestingT - Cleanup(func()) -}) *ScanossSettingsService { - mock := &ScanossSettingsService{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/backend/main/pkg/common/scanoss_settings/service/mocks/mock_ScanossSettingsService.go b/backend/main/pkg/common/scanoss_settings/service/mocks/mock_ScanossSettingsService.go new file mode 100644 index 0000000..f06552f --- /dev/null +++ b/backend/main/pkg/common/scanoss_settings/service/mocks/mock_ScanossSettingsService.go @@ -0,0 +1,132 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// MockScanossSettingsService is an autogenerated mock type for the ScanossSettingsService type +type MockScanossSettingsService struct { + mock.Mock +} + +type MockScanossSettingsService_Expecter struct { + mock *mock.Mock +} + +func (_m *MockScanossSettingsService) EXPECT() *MockScanossSettingsService_Expecter { + return &MockScanossSettingsService_Expecter{mock: &_m.Mock} +} + +// HasUnsavedChanges provides a mock function with given fields: +func (_m *MockScanossSettingsService) HasUnsavedChanges() (bool, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for HasUnsavedChanges") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func() (bool, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockScanossSettingsService_HasUnsavedChanges_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HasUnsavedChanges' +type MockScanossSettingsService_HasUnsavedChanges_Call struct { + *mock.Call +} + +// HasUnsavedChanges is a helper method to define mock.On call +func (_e *MockScanossSettingsService_Expecter) HasUnsavedChanges() *MockScanossSettingsService_HasUnsavedChanges_Call { + return &MockScanossSettingsService_HasUnsavedChanges_Call{Call: _e.mock.On("HasUnsavedChanges")} +} + +func (_c *MockScanossSettingsService_HasUnsavedChanges_Call) Run(run func()) *MockScanossSettingsService_HasUnsavedChanges_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockScanossSettingsService_HasUnsavedChanges_Call) Return(_a0 bool, _a1 error) *MockScanossSettingsService_HasUnsavedChanges_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockScanossSettingsService_HasUnsavedChanges_Call) RunAndReturn(run func() (bool, error)) *MockScanossSettingsService_HasUnsavedChanges_Call { + _c.Call.Return(run) + return _c +} + +// Save provides a mock function with given fields: +func (_m *MockScanossSettingsService) Save() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Save") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockScanossSettingsService_Save_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Save' +type MockScanossSettingsService_Save_Call struct { + *mock.Call +} + +// Save is a helper method to define mock.On call +func (_e *MockScanossSettingsService_Expecter) Save() *MockScanossSettingsService_Save_Call { + return &MockScanossSettingsService_Save_Call{Call: _e.mock.On("Save")} +} + +func (_c *MockScanossSettingsService_Save_Call) Run(run func()) *MockScanossSettingsService_Save_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockScanossSettingsService_Save_Call) Return(_a0 error) *MockScanossSettingsService_Save_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockScanossSettingsService_Save_Call) RunAndReturn(run func() error) *MockScanossSettingsService_Save_Call { + _c.Call.Return(run) + return _c +} + +// NewMockScanossSettingsService creates a new instance of MockScanossSettingsService. 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 NewMockScanossSettingsService(t interface { + mock.TestingT + Cleanup(func()) +}) *MockScanossSettingsService { + mock := &MockScanossSettingsService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/common/scanoss_settings/service/scanoss_settings_service.go b/backend/main/pkg/common/scanoss_settings/service/scanoss_settings_service.go index 2be4442..262c4c7 100644 --- a/backend/main/pkg/common/scanoss_settings/service/scanoss_settings_service.go +++ b/backend/main/pkg/common/scanoss_settings/service/scanoss_settings_service.go @@ -1,6 +1,5 @@ package service -//go:generate mockery --name ScanossSettingsService --with-expecter type ScanossSettingsService interface { Save() error HasUnsavedChanges() (bool, error) diff --git a/backend/main/pkg/component/controllers/component_controller_impl_test.go b/backend/main/pkg/component/controllers/component_controller_impl_test.go index bde33d9..d280143 100644 --- a/backend/main/pkg/component/controllers/component_controller_impl_test.go +++ b/backend/main/pkg/component/controllers/component_controller_impl_test.go @@ -4,65 +4,42 @@ import ( "testing" "github.com/go-playground/validator" - internalTest "github.com/scanoss/scanoss.lui/backend/main/internal" - scanossSettingsRepository "github.com/scanoss/scanoss.lui/backend/main/pkg/common/scanoss_settings/repository" + scanossSettingsEntities "github.com/scanoss/scanoss.lui/backend/main/pkg/common/scanoss_settings/entities" "github.com/scanoss/scanoss.lui/backend/main/pkg/component/controllers" "github.com/scanoss/scanoss.lui/backend/main/pkg/component/entities" - "github.com/scanoss/scanoss.lui/backend/main/pkg/component/repository" - "github.com/scanoss/scanoss.lui/backend/main/pkg/component/service" - "github.com/scanoss/scanoss.lui/backend/main/pkg/utils" + serviceMocks "github.com/scanoss/scanoss.lui/backend/main/pkg/component/service/mocks" "github.com/stretchr/testify/assert" ) func TestFilterComponent_Integration(t *testing.T) { - cleanup := internalTest.InitializeTestEnvironment(t) - defer cleanup() - - fr := utils.NewDefaultFileReader() - repo := repository.NewJSONComponentRepository(fr) - ssRepo := scanossSettingsRepository.NewScanossSettingsJsonRepository(fr) - service := service.NewComponentService(repo, ssRepo) - controller := controllers.NewComponentController(service) - - dto := entities.ComponentFilterDTO{ - Path: "test/path", - Purl: "test:purl", - Usage: "file", - Action: entities.Include, - } - - var tests = []struct { - name string - expectedError error - dto entities.ComponentFilterDTO - }{ - { - name: "No errors", - dto: dto, - }, - { - name: "Wrong action", - expectedError: validator.ValidationErrors{}, - dto: entities.ComponentFilterDTO{ - Path: "test/path", - Purl: "pkg:purl.com/test", - Usage: "file", - Action: entities.FilterAction("unsupported"), - }, - }, - } - - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - err := controller.FilterComponent(tc.dto) - if tc.expectedError != nil { - assert.Error(t, err) - assert.IsType(t, err, tc.expectedError) - return - } - - assert.NoError(t, err) - }) - } - + mockService := serviceMocks.NewMockComponentService(t) + mockService.EXPECT().GetInitialFilters().Return([]scanossSettingsEntities.ComponentFilter{}, []scanossSettingsEntities.ComponentFilter{}) + + controller := controllers.NewComponentController(mockService) + + t.Run("No errors", func(t *testing.T) { + dto := entities.ComponentFilterDTO{ + Path: "test/path", + Purl: "test:purl", + Usage: "file", + Action: entities.Include, + } + mockService.EXPECT().FilterComponent(dto).Return(nil) + + err := controller.FilterComponent(dto) + + assert.NoError(t, err) + }) + + t.Run("Validation error", func(t *testing.T) { + dto := entities.ComponentFilterDTO{ + Path: "test/path", + Purl: "pkg:purl.com/test", + Usage: "file", + Action: entities.FilterAction("unsupported"), + } + err := controller.FilterComponent(dto) + assert.Error(t, err) + assert.IsType(t, err, validator.ValidationErrors{}) + }) } diff --git a/backend/main/pkg/component/controllers/mocks/mock_ComponentController.go b/backend/main/pkg/component/controllers/mocks/mock_ComponentController.go new file mode 100644 index 0000000..097382e --- /dev/null +++ b/backend/main/pkg/component/controllers/mocks/mock_ComponentController.go @@ -0,0 +1,337 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import ( + entities "github.com/scanoss/scanoss.lui/backend/main/pkg/component/entities" + mock "github.com/stretchr/testify/mock" +) + +// MockComponentController is an autogenerated mock type for the ComponentController type +type MockComponentController struct { + mock.Mock +} + +type MockComponentController_Expecter struct { + mock *mock.Mock +} + +func (_m *MockComponentController) EXPECT() *MockComponentController_Expecter { + return &MockComponentController_Expecter{mock: &_m.Mock} +} + +// CanRedo provides a mock function with given fields: +func (_m *MockComponentController) CanRedo() (bool, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for CanRedo") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func() (bool, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockComponentController_CanRedo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CanRedo' +type MockComponentController_CanRedo_Call struct { + *mock.Call +} + +// CanRedo is a helper method to define mock.On call +func (_e *MockComponentController_Expecter) CanRedo() *MockComponentController_CanRedo_Call { + return &MockComponentController_CanRedo_Call{Call: _e.mock.On("CanRedo")} +} + +func (_c *MockComponentController_CanRedo_Call) Run(run func()) *MockComponentController_CanRedo_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockComponentController_CanRedo_Call) Return(_a0 bool, _a1 error) *MockComponentController_CanRedo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockComponentController_CanRedo_Call) RunAndReturn(run func() (bool, error)) *MockComponentController_CanRedo_Call { + _c.Call.Return(run) + return _c +} + +// CanUndo provides a mock function with given fields: +func (_m *MockComponentController) CanUndo() (bool, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for CanUndo") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func() (bool, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockComponentController_CanUndo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CanUndo' +type MockComponentController_CanUndo_Call struct { + *mock.Call +} + +// CanUndo is a helper method to define mock.On call +func (_e *MockComponentController_Expecter) CanUndo() *MockComponentController_CanUndo_Call { + return &MockComponentController_CanUndo_Call{Call: _e.mock.On("CanUndo")} +} + +func (_c *MockComponentController_CanUndo_Call) Run(run func()) *MockComponentController_CanUndo_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockComponentController_CanUndo_Call) Return(_a0 bool, _a1 error) *MockComponentController_CanUndo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockComponentController_CanUndo_Call) RunAndReturn(run func() (bool, error)) *MockComponentController_CanUndo_Call { + _c.Call.Return(run) + return _c +} + +// FilterComponent provides a mock function with given fields: dto +func (_m *MockComponentController) FilterComponent(dto entities.ComponentFilterDTO) error { + ret := _m.Called(dto) + + if len(ret) == 0 { + panic("no return value specified for FilterComponent") + } + + var r0 error + if rf, ok := ret.Get(0).(func(entities.ComponentFilterDTO) error); ok { + r0 = rf(dto) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockComponentController_FilterComponent_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FilterComponent' +type MockComponentController_FilterComponent_Call struct { + *mock.Call +} + +// FilterComponent is a helper method to define mock.On call +// - dto entities.ComponentFilterDTO +func (_e *MockComponentController_Expecter) FilterComponent(dto interface{}) *MockComponentController_FilterComponent_Call { + return &MockComponentController_FilterComponent_Call{Call: _e.mock.On("FilterComponent", dto)} +} + +func (_c *MockComponentController_FilterComponent_Call) Run(run func(dto entities.ComponentFilterDTO)) *MockComponentController_FilterComponent_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(entities.ComponentFilterDTO)) + }) + return _c +} + +func (_c *MockComponentController_FilterComponent_Call) Return(_a0 error) *MockComponentController_FilterComponent_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockComponentController_FilterComponent_Call) RunAndReturn(run func(entities.ComponentFilterDTO) error) *MockComponentController_FilterComponent_Call { + _c.Call.Return(run) + return _c +} + +// GetComponentByPath provides a mock function with given fields: filePath +func (_m *MockComponentController) GetComponentByPath(filePath string) (entities.ComponentDTO, error) { + ret := _m.Called(filePath) + + if len(ret) == 0 { + panic("no return value specified for GetComponentByPath") + } + + var r0 entities.ComponentDTO + var r1 error + if rf, ok := ret.Get(0).(func(string) (entities.ComponentDTO, error)); ok { + return rf(filePath) + } + if rf, ok := ret.Get(0).(func(string) entities.ComponentDTO); ok { + r0 = rf(filePath) + } else { + r0 = ret.Get(0).(entities.ComponentDTO) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(filePath) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockComponentController_GetComponentByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetComponentByPath' +type MockComponentController_GetComponentByPath_Call struct { + *mock.Call +} + +// GetComponentByPath is a helper method to define mock.On call +// - filePath string +func (_e *MockComponentController_Expecter) GetComponentByPath(filePath interface{}) *MockComponentController_GetComponentByPath_Call { + return &MockComponentController_GetComponentByPath_Call{Call: _e.mock.On("GetComponentByPath", filePath)} +} + +func (_c *MockComponentController_GetComponentByPath_Call) Run(run func(filePath string)) *MockComponentController_GetComponentByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *MockComponentController_GetComponentByPath_Call) Return(_a0 entities.ComponentDTO, _a1 error) *MockComponentController_GetComponentByPath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockComponentController_GetComponentByPath_Call) RunAndReturn(run func(string) (entities.ComponentDTO, error)) *MockComponentController_GetComponentByPath_Call { + _c.Call.Return(run) + return _c +} + +// Redo provides a mock function with given fields: +func (_m *MockComponentController) Redo() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Redo") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockComponentController_Redo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Redo' +type MockComponentController_Redo_Call struct { + *mock.Call +} + +// Redo is a helper method to define mock.On call +func (_e *MockComponentController_Expecter) Redo() *MockComponentController_Redo_Call { + return &MockComponentController_Redo_Call{Call: _e.mock.On("Redo")} +} + +func (_c *MockComponentController_Redo_Call) Run(run func()) *MockComponentController_Redo_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockComponentController_Redo_Call) Return(_a0 error) *MockComponentController_Redo_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockComponentController_Redo_Call) RunAndReturn(run func() error) *MockComponentController_Redo_Call { + _c.Call.Return(run) + return _c +} + +// Undo provides a mock function with given fields: +func (_m *MockComponentController) Undo() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Undo") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockComponentController_Undo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Undo' +type MockComponentController_Undo_Call struct { + *mock.Call +} + +// Undo is a helper method to define mock.On call +func (_e *MockComponentController_Expecter) Undo() *MockComponentController_Undo_Call { + return &MockComponentController_Undo_Call{Call: _e.mock.On("Undo")} +} + +func (_c *MockComponentController_Undo_Call) Run(run func()) *MockComponentController_Undo_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockComponentController_Undo_Call) Return(_a0 error) *MockComponentController_Undo_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockComponentController_Undo_Call) RunAndReturn(run func() error) *MockComponentController_Undo_Call { + _c.Call.Return(run) + return _c +} + +// NewMockComponentController creates a new instance of MockComponentController. 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 NewMockComponentController(t interface { + mock.TestingT + Cleanup(func()) +}) *MockComponentController { + mock := &MockComponentController{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/component/entities/mocks/mock_License.go b/backend/main/pkg/component/entities/mocks/mock_License.go new file mode 100644 index 0000000..3e8df28 --- /dev/null +++ b/backend/main/pkg/component/entities/mocks/mock_License.go @@ -0,0 +1,32 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// MockLicense is an autogenerated mock type for the License type +type MockLicense struct { + mock.Mock +} + +type MockLicense_Expecter struct { + mock *mock.Mock +} + +func (_m *MockLicense) EXPECT() *MockLicense_Expecter { + return &MockLicense_Expecter{mock: &_m.Mock} +} + +// NewMockLicense creates a new instance of MockLicense. 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 NewMockLicense(t interface { + mock.TestingT + Cleanup(func()) +}) *MockLicense { + mock := &MockLicense{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/component/repository/mocks/mock_ComponentRepository.go b/backend/main/pkg/component/repository/mocks/mock_ComponentRepository.go new file mode 100644 index 0000000..9f661cd --- /dev/null +++ b/backend/main/pkg/component/repository/mocks/mock_ComponentRepository.go @@ -0,0 +1,91 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import ( + entities "github.com/scanoss/scanoss.lui/backend/main/pkg/component/entities" + mock "github.com/stretchr/testify/mock" +) + +// MockComponentRepository is an autogenerated mock type for the ComponentRepository type +type MockComponentRepository struct { + mock.Mock +} + +type MockComponentRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockComponentRepository) EXPECT() *MockComponentRepository_Expecter { + return &MockComponentRepository_Expecter{mock: &_m.Mock} +} + +// FindByFilePath provides a mock function with given fields: path +func (_m *MockComponentRepository) FindByFilePath(path string) (entities.Component, error) { + ret := _m.Called(path) + + if len(ret) == 0 { + panic("no return value specified for FindByFilePath") + } + + var r0 entities.Component + var r1 error + if rf, ok := ret.Get(0).(func(string) (entities.Component, error)); ok { + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) entities.Component); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(entities.Component) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockComponentRepository_FindByFilePath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByFilePath' +type MockComponentRepository_FindByFilePath_Call struct { + *mock.Call +} + +// FindByFilePath is a helper method to define mock.On call +// - path string +func (_e *MockComponentRepository_Expecter) FindByFilePath(path interface{}) *MockComponentRepository_FindByFilePath_Call { + return &MockComponentRepository_FindByFilePath_Call{Call: _e.mock.On("FindByFilePath", path)} +} + +func (_c *MockComponentRepository_FindByFilePath_Call) Run(run func(path string)) *MockComponentRepository_FindByFilePath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *MockComponentRepository_FindByFilePath_Call) Return(_a0 entities.Component, _a1 error) *MockComponentRepository_FindByFilePath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockComponentRepository_FindByFilePath_Call) RunAndReturn(run func(string) (entities.Component, error)) *MockComponentRepository_FindByFilePath_Call { + _c.Call.Return(run) + return _c +} + +// NewMockComponentRepository creates a new instance of MockComponentRepository. 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 NewMockComponentRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockComponentRepository { + mock := &MockComponentRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/component/service/mocks/mock_ComponentService.go b/backend/main/pkg/component/service/mocks/mock_ComponentService.go new file mode 100644 index 0000000..ea16928 --- /dev/null +++ b/backend/main/pkg/component/service/mocks/mock_ComponentService.go @@ -0,0 +1,243 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import ( + entities "github.com/scanoss/scanoss.lui/backend/main/pkg/component/entities" + mock "github.com/stretchr/testify/mock" + + scanoss_settingsentities "github.com/scanoss/scanoss.lui/backend/main/pkg/common/scanoss_settings/entities" +) + +// MockComponentService is an autogenerated mock type for the ComponentService type +type MockComponentService struct { + mock.Mock +} + +type MockComponentService_Expecter struct { + mock *mock.Mock +} + +func (_m *MockComponentService) EXPECT() *MockComponentService_Expecter { + return &MockComponentService_Expecter{mock: &_m.Mock} +} + +// ClearAllFilters provides a mock function with given fields: +func (_m *MockComponentService) ClearAllFilters() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for ClearAllFilters") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockComponentService_ClearAllFilters_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ClearAllFilters' +type MockComponentService_ClearAllFilters_Call struct { + *mock.Call +} + +// ClearAllFilters is a helper method to define mock.On call +func (_e *MockComponentService_Expecter) ClearAllFilters() *MockComponentService_ClearAllFilters_Call { + return &MockComponentService_ClearAllFilters_Call{Call: _e.mock.On("ClearAllFilters")} +} + +func (_c *MockComponentService_ClearAllFilters_Call) Run(run func()) *MockComponentService_ClearAllFilters_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockComponentService_ClearAllFilters_Call) Return(_a0 error) *MockComponentService_ClearAllFilters_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockComponentService_ClearAllFilters_Call) RunAndReturn(run func() error) *MockComponentService_ClearAllFilters_Call { + _c.Call.Return(run) + return _c +} + +// FilterComponent provides a mock function with given fields: dto +func (_m *MockComponentService) FilterComponent(dto entities.ComponentFilterDTO) error { + ret := _m.Called(dto) + + if len(ret) == 0 { + panic("no return value specified for FilterComponent") + } + + var r0 error + if rf, ok := ret.Get(0).(func(entities.ComponentFilterDTO) error); ok { + r0 = rf(dto) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockComponentService_FilterComponent_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FilterComponent' +type MockComponentService_FilterComponent_Call struct { + *mock.Call +} + +// FilterComponent is a helper method to define mock.On call +// - dto entities.ComponentFilterDTO +func (_e *MockComponentService_Expecter) FilterComponent(dto interface{}) *MockComponentService_FilterComponent_Call { + return &MockComponentService_FilterComponent_Call{Call: _e.mock.On("FilterComponent", dto)} +} + +func (_c *MockComponentService_FilterComponent_Call) Run(run func(dto entities.ComponentFilterDTO)) *MockComponentService_FilterComponent_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(entities.ComponentFilterDTO)) + }) + return _c +} + +func (_c *MockComponentService_FilterComponent_Call) Return(_a0 error) *MockComponentService_FilterComponent_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockComponentService_FilterComponent_Call) RunAndReturn(run func(entities.ComponentFilterDTO) error) *MockComponentService_FilterComponent_Call { + _c.Call.Return(run) + return _c +} + +// GetComponentByFilePath provides a mock function with given fields: filePath +func (_m *MockComponentService) GetComponentByFilePath(filePath string) (entities.Component, error) { + ret := _m.Called(filePath) + + if len(ret) == 0 { + panic("no return value specified for GetComponentByFilePath") + } + + var r0 entities.Component + var r1 error + if rf, ok := ret.Get(0).(func(string) (entities.Component, error)); ok { + return rf(filePath) + } + if rf, ok := ret.Get(0).(func(string) entities.Component); ok { + r0 = rf(filePath) + } else { + r0 = ret.Get(0).(entities.Component) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(filePath) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockComponentService_GetComponentByFilePath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetComponentByFilePath' +type MockComponentService_GetComponentByFilePath_Call struct { + *mock.Call +} + +// GetComponentByFilePath is a helper method to define mock.On call +// - filePath string +func (_e *MockComponentService_Expecter) GetComponentByFilePath(filePath interface{}) *MockComponentService_GetComponentByFilePath_Call { + return &MockComponentService_GetComponentByFilePath_Call{Call: _e.mock.On("GetComponentByFilePath", filePath)} +} + +func (_c *MockComponentService_GetComponentByFilePath_Call) Run(run func(filePath string)) *MockComponentService_GetComponentByFilePath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *MockComponentService_GetComponentByFilePath_Call) Return(_a0 entities.Component, _a1 error) *MockComponentService_GetComponentByFilePath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockComponentService_GetComponentByFilePath_Call) RunAndReturn(run func(string) (entities.Component, error)) *MockComponentService_GetComponentByFilePath_Call { + _c.Call.Return(run) + return _c +} + +// GetInitialFilters provides a mock function with given fields: +func (_m *MockComponentService) GetInitialFilters() ([]scanoss_settingsentities.ComponentFilter, []scanoss_settingsentities.ComponentFilter) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetInitialFilters") + } + + var r0 []scanoss_settingsentities.ComponentFilter + var r1 []scanoss_settingsentities.ComponentFilter + if rf, ok := ret.Get(0).(func() ([]scanoss_settingsentities.ComponentFilter, []scanoss_settingsentities.ComponentFilter)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []scanoss_settingsentities.ComponentFilter); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]scanoss_settingsentities.ComponentFilter) + } + } + + if rf, ok := ret.Get(1).(func() []scanoss_settingsentities.ComponentFilter); ok { + r1 = rf() + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).([]scanoss_settingsentities.ComponentFilter) + } + } + + return r0, r1 +} + +// MockComponentService_GetInitialFilters_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetInitialFilters' +type MockComponentService_GetInitialFilters_Call struct { + *mock.Call +} + +// GetInitialFilters is a helper method to define mock.On call +func (_e *MockComponentService_Expecter) GetInitialFilters() *MockComponentService_GetInitialFilters_Call { + return &MockComponentService_GetInitialFilters_Call{Call: _e.mock.On("GetInitialFilters")} +} + +func (_c *MockComponentService_GetInitialFilters_Call) Run(run func()) *MockComponentService_GetInitialFilters_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockComponentService_GetInitialFilters_Call) Return(_a0 []scanoss_settingsentities.ComponentFilter, _a1 []scanoss_settingsentities.ComponentFilter) *MockComponentService_GetInitialFilters_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockComponentService_GetInitialFilters_Call) RunAndReturn(run func() ([]scanoss_settingsentities.ComponentFilter, []scanoss_settingsentities.ComponentFilter)) *MockComponentService_GetInitialFilters_Call { + _c.Call.Return(run) + return _c +} + +// NewMockComponentService creates a new instance of MockComponentService. 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 NewMockComponentService(t interface { + mock.TestingT + Cleanup(func()) +}) *MockComponentService { + mock := &MockComponentService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/file/controllers/file_controller_impl_test.go b/backend/main/pkg/file/controllers/file_controller_impl_test.go new file mode 100644 index 0000000..1d0d2f3 --- /dev/null +++ b/backend/main/pkg/file/controllers/file_controller_impl_test.go @@ -0,0 +1,79 @@ +package controllers + +import ( + "errors" + "testing" + + componentEntities "github.com/scanoss/scanoss.lui/backend/main/pkg/component/entities" + componentMocks "github.com/scanoss/scanoss.lui/backend/main/pkg/component/service/mocks" + "github.com/scanoss/scanoss.lui/backend/main/pkg/file/entities" + "github.com/scanoss/scanoss.lui/backend/main/pkg/file/service/mocks" + "github.com/stretchr/testify/assert" +) + +func resetMocks(mockFileService *mocks.MockFileService, mockComponentService *componentMocks.MockComponentService) { + mockFileService.ExpectedCalls = nil + mockFileService.Calls = nil + mockComponentService.ExpectedCalls = nil + mockComponentService.Calls = nil +} + +func TestFileController(t *testing.T) { + mockFileService := mocks.NewMockFileService(t) + mockComponentService := componentMocks.NewMockComponentService(t) + controller := NewFileController(mockFileService, mockComponentService) + + filePath := "components/button.tsx" + fileHash := "hash" + fileContent := []byte("function main() {\n\tconsole.log('Hello, World!');\n}") + file := entities.NewFile("", filePath, fileContent) + + t.Run("GetRemoteFile", func(t *testing.T) { + mockComponentService.EXPECT().GetComponentByFilePath(filePath).Return(componentEntities.Component{ + FileHash: fileHash, + }, nil) + mockFileService.EXPECT().GetRemoteFileContent(filePath, fileHash).Return(*file, nil) + + response, err := controller.GetRemoteFile(filePath) + + assert.NoError(t, err) + assert.Equal(t, "button.tsx", response.Name) + assert.Equal(t, "components/button.tsx", response.Path) + assert.Equal(t, string(fileContent), response.Content) + + mockComponentService.AssertExpectations(t) + mockFileService.AssertExpectations(t) + + resetMocks(mockFileService, mockComponentService) + }) + + t.Run("ComponentServiceError", func(t *testing.T) { + path := "components/button.tsx" + mockComponentService.EXPECT().GetComponentByFilePath(path).Return(componentEntities.Component{}, errors.New("component service error")) + + result, err := controller.GetRemoteFile(path) + + assert.Error(t, err) + assert.Equal(t, entities.FileDTO{}, result) + + mockComponentService.AssertExpectations(t) + resetMocks(mockFileService, mockComponentService) + }) + + t.Run("GetLocalFile", func(t *testing.T) { + path := "components/button.tsx" + fileContent := []byte("function main() {\n\tconsole.log('Hello, World!');\n}") + file := entities.NewFile("", path, fileContent) + + mockFileService.EXPECT().GetLocalFileContent(path).Return(*file, nil) + + result, err := controller.GetLocalFile(path) + + assert.NoError(t, err) + assert.Equal(t, "button.tsx", result.Name) + assert.Equal(t, "components/button.tsx", result.Path) + assert.Equal(t, string(fileContent), result.Content) + + mockFileService.AssertExpectations(t) + }) +} diff --git a/backend/main/pkg/file/controllers/mocks/mock_FileController.go b/backend/main/pkg/file/controllers/mocks/mock_FileController.go new file mode 100644 index 0000000..83ec5f6 --- /dev/null +++ b/backend/main/pkg/file/controllers/mocks/mock_FileController.go @@ -0,0 +1,147 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import ( + entities "github.com/scanoss/scanoss.lui/backend/main/pkg/file/entities" + mock "github.com/stretchr/testify/mock" +) + +// MockFileController is an autogenerated mock type for the FileController type +type MockFileController struct { + mock.Mock +} + +type MockFileController_Expecter struct { + mock *mock.Mock +} + +func (_m *MockFileController) EXPECT() *MockFileController_Expecter { + return &MockFileController_Expecter{mock: &_m.Mock} +} + +// GetLocalFile provides a mock function with given fields: path +func (_m *MockFileController) GetLocalFile(path string) (entities.FileDTO, error) { + ret := _m.Called(path) + + if len(ret) == 0 { + panic("no return value specified for GetLocalFile") + } + + var r0 entities.FileDTO + var r1 error + if rf, ok := ret.Get(0).(func(string) (entities.FileDTO, error)); ok { + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) entities.FileDTO); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(entities.FileDTO) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockFileController_GetLocalFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLocalFile' +type MockFileController_GetLocalFile_Call struct { + *mock.Call +} + +// GetLocalFile is a helper method to define mock.On call +// - path string +func (_e *MockFileController_Expecter) GetLocalFile(path interface{}) *MockFileController_GetLocalFile_Call { + return &MockFileController_GetLocalFile_Call{Call: _e.mock.On("GetLocalFile", path)} +} + +func (_c *MockFileController_GetLocalFile_Call) Run(run func(path string)) *MockFileController_GetLocalFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *MockFileController_GetLocalFile_Call) Return(_a0 entities.FileDTO, _a1 error) *MockFileController_GetLocalFile_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockFileController_GetLocalFile_Call) RunAndReturn(run func(string) (entities.FileDTO, error)) *MockFileController_GetLocalFile_Call { + _c.Call.Return(run) + return _c +} + +// GetRemoteFile provides a mock function with given fields: path +func (_m *MockFileController) GetRemoteFile(path string) (entities.FileDTO, error) { + ret := _m.Called(path) + + if len(ret) == 0 { + panic("no return value specified for GetRemoteFile") + } + + var r0 entities.FileDTO + var r1 error + if rf, ok := ret.Get(0).(func(string) (entities.FileDTO, error)); ok { + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) entities.FileDTO); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(entities.FileDTO) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockFileController_GetRemoteFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRemoteFile' +type MockFileController_GetRemoteFile_Call struct { + *mock.Call +} + +// GetRemoteFile is a helper method to define mock.On call +// - path string +func (_e *MockFileController_Expecter) GetRemoteFile(path interface{}) *MockFileController_GetRemoteFile_Call { + return &MockFileController_GetRemoteFile_Call{Call: _e.mock.On("GetRemoteFile", path)} +} + +func (_c *MockFileController_GetRemoteFile_Call) Run(run func(path string)) *MockFileController_GetRemoteFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *MockFileController_GetRemoteFile_Call) Return(_a0 entities.FileDTO, _a1 error) *MockFileController_GetRemoteFile_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockFileController_GetRemoteFile_Call) RunAndReturn(run func(string) (entities.FileDTO, error)) *MockFileController_GetRemoteFile_Call { + _c.Call.Return(run) + return _c +} + +// NewMockFileController creates a new instance of MockFileController. 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 NewMockFileController(t interface { + mock.TestingT + Cleanup(func()) +}) *MockFileController { + mock := &MockFileController{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/file/repository/file_repository_impl_test.go b/backend/main/pkg/file/repository/file_repository_impl_test.go new file mode 100644 index 0000000..f868374 --- /dev/null +++ b/backend/main/pkg/file/repository/file_repository_impl_test.go @@ -0,0 +1,56 @@ +package repository + +import ( + "os" + "path/filepath" + "testing" + + internal_test "github.com/scanoss/scanoss.lui/backend/main/internal" + "github.com/scanoss/scanoss.lui/backend/main/pkg/common/config" + "github.com/scanoss/scanoss.lui/backend/main/pkg/file/entities" + "github.com/scanoss/scanoss.lui/backend/main/pkg/file/repository/mocks" + "github.com/stretchr/testify/assert" +) + +func TestFileRepositoryImpl(t *testing.T) { + cleanup := internal_test.InitializeTestEnvironment(t) + defer cleanup() + + t.Run("ReadLocalFile", func(t *testing.T) { + testFilePath := "test.js" + testContent := []byte("function main() {\n\tconsole.log('Hello, World!');\n}") + currentPath := t.TempDir() + absolutePath := filepath.Join(currentPath, testFilePath) + err := os.WriteFile(absolutePath, testContent, 0644) + assert.NoError(t, err) + + config.Get().ScanRoot = currentPath + + repo := NewFileRepositoryImpl() + + file, err := repo.ReadLocalFile(testFilePath) + assert.NoError(t, err) + assert.Equal(t, testContent, file.GetContent()) + }) + + t.Run("ReadRemoteFileByMD5", func(t *testing.T) { + testFilePath := "test.js" + testContent := []byte("function main() {\n\tconsole.log('Hello, World!');\n}") + md5 := "test-md5" + + repo := mocks.NewMockFileRepository(t) + + repo.EXPECT().ReadRemoteFileByMD5(testFilePath, md5).Return(*entities.NewFile( + "", + testFilePath, + testContent, + ), nil) + + file, err := repo.ReadRemoteFileByMD5(testFilePath, md5) + + assert.NoError(t, err) + assert.Equal(t, testContent, file.GetContent()) + + repo.AssertExpectations(t) + }) +} diff --git a/backend/main/pkg/file/repository/mocks/mock_FileRepository.go b/backend/main/pkg/file/repository/mocks/mock_FileRepository.go new file mode 100644 index 0000000..cea1071 --- /dev/null +++ b/backend/main/pkg/file/repository/mocks/mock_FileRepository.go @@ -0,0 +1,204 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import ( + entities "github.com/scanoss/scanoss.lui/backend/main/pkg/file/entities" + mock "github.com/stretchr/testify/mock" +) + +// MockFileRepository is an autogenerated mock type for the FileRepository type +type MockFileRepository struct { + mock.Mock +} + +type MockFileRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockFileRepository) EXPECT() *MockFileRepository_Expecter { + return &MockFileRepository_Expecter{mock: &_m.Mock} +} + +// GetComponentByFilePath provides a mock function with given fields: filePath +func (_m *MockFileRepository) GetComponentByFilePath(filePath string) (entities.Component, error) { + ret := _m.Called(filePath) + + if len(ret) == 0 { + panic("no return value specified for GetComponentByFilePath") + } + + var r0 entities.Component + var r1 error + if rf, ok := ret.Get(0).(func(string) (entities.Component, error)); ok { + return rf(filePath) + } + if rf, ok := ret.Get(0).(func(string) entities.Component); ok { + r0 = rf(filePath) + } else { + r0 = ret.Get(0).(entities.Component) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(filePath) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockFileRepository_GetComponentByFilePath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetComponentByFilePath' +type MockFileRepository_GetComponentByFilePath_Call struct { + *mock.Call +} + +// GetComponentByFilePath is a helper method to define mock.On call +// - filePath string +func (_e *MockFileRepository_Expecter) GetComponentByFilePath(filePath interface{}) *MockFileRepository_GetComponentByFilePath_Call { + return &MockFileRepository_GetComponentByFilePath_Call{Call: _e.mock.On("GetComponentByFilePath", filePath)} +} + +func (_c *MockFileRepository_GetComponentByFilePath_Call) Run(run func(filePath string)) *MockFileRepository_GetComponentByFilePath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *MockFileRepository_GetComponentByFilePath_Call) Return(_a0 entities.Component, _a1 error) *MockFileRepository_GetComponentByFilePath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockFileRepository_GetComponentByFilePath_Call) RunAndReturn(run func(string) (entities.Component, error)) *MockFileRepository_GetComponentByFilePath_Call { + _c.Call.Return(run) + return _c +} + +// ReadLocalFile provides a mock function with given fields: filePath +func (_m *MockFileRepository) ReadLocalFile(filePath string) (entities.File, error) { + ret := _m.Called(filePath) + + if len(ret) == 0 { + panic("no return value specified for ReadLocalFile") + } + + var r0 entities.File + var r1 error + if rf, ok := ret.Get(0).(func(string) (entities.File, error)); ok { + return rf(filePath) + } + if rf, ok := ret.Get(0).(func(string) entities.File); ok { + r0 = rf(filePath) + } else { + r0 = ret.Get(0).(entities.File) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(filePath) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockFileRepository_ReadLocalFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReadLocalFile' +type MockFileRepository_ReadLocalFile_Call struct { + *mock.Call +} + +// ReadLocalFile is a helper method to define mock.On call +// - filePath string +func (_e *MockFileRepository_Expecter) ReadLocalFile(filePath interface{}) *MockFileRepository_ReadLocalFile_Call { + return &MockFileRepository_ReadLocalFile_Call{Call: _e.mock.On("ReadLocalFile", filePath)} +} + +func (_c *MockFileRepository_ReadLocalFile_Call) Run(run func(filePath string)) *MockFileRepository_ReadLocalFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *MockFileRepository_ReadLocalFile_Call) Return(_a0 entities.File, _a1 error) *MockFileRepository_ReadLocalFile_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockFileRepository_ReadLocalFile_Call) RunAndReturn(run func(string) (entities.File, error)) *MockFileRepository_ReadLocalFile_Call { + _c.Call.Return(run) + return _c +} + +// ReadRemoteFileByMD5 provides a mock function with given fields: path, md5 +func (_m *MockFileRepository) ReadRemoteFileByMD5(path string, md5 string) (entities.File, error) { + ret := _m.Called(path, md5) + + if len(ret) == 0 { + panic("no return value specified for ReadRemoteFileByMD5") + } + + var r0 entities.File + var r1 error + if rf, ok := ret.Get(0).(func(string, string) (entities.File, error)); ok { + return rf(path, md5) + } + if rf, ok := ret.Get(0).(func(string, string) entities.File); ok { + r0 = rf(path, md5) + } else { + r0 = ret.Get(0).(entities.File) + } + + if rf, ok := ret.Get(1).(func(string, string) error); ok { + r1 = rf(path, md5) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockFileRepository_ReadRemoteFileByMD5_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReadRemoteFileByMD5' +type MockFileRepository_ReadRemoteFileByMD5_Call struct { + *mock.Call +} + +// ReadRemoteFileByMD5 is a helper method to define mock.On call +// - path string +// - md5 string +func (_e *MockFileRepository_Expecter) ReadRemoteFileByMD5(path interface{}, md5 interface{}) *MockFileRepository_ReadRemoteFileByMD5_Call { + return &MockFileRepository_ReadRemoteFileByMD5_Call{Call: _e.mock.On("ReadRemoteFileByMD5", path, md5)} +} + +func (_c *MockFileRepository_ReadRemoteFileByMD5_Call) Run(run func(path string, md5 string)) *MockFileRepository_ReadRemoteFileByMD5_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(string)) + }) + return _c +} + +func (_c *MockFileRepository_ReadRemoteFileByMD5_Call) Return(_a0 entities.File, _a1 error) *MockFileRepository_ReadRemoteFileByMD5_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockFileRepository_ReadRemoteFileByMD5_Call) RunAndReturn(run func(string, string) (entities.File, error)) *MockFileRepository_ReadRemoteFileByMD5_Call { + _c.Call.Return(run) + return _c +} + +// NewMockFileRepository creates a new instance of MockFileRepository. 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 NewMockFileRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockFileRepository { + mock := &MockFileRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/file/service/file_service_impl_test.go b/backend/main/pkg/file/service/file_service_impl_test.go new file mode 100644 index 0000000..a9db926 --- /dev/null +++ b/backend/main/pkg/file/service/file_service_impl_test.go @@ -0,0 +1,72 @@ +package service + +import ( + "errors" + "testing" + + "github.com/scanoss/scanoss.lui/backend/main/pkg/file/entities" + "github.com/scanoss/scanoss.lui/backend/main/pkg/file/repository/mocks" + "github.com/stretchr/testify/assert" +) + +func TestGetLocalFileContent(t *testing.T) { + mockRepo := mocks.NewMockFileRepository(t) + service := NewFileService(mockRepo) + + expectedFile := entities.NewFile( + "", + "test.js", + []byte("function main() {\n\tconsole.log('Hello, World!');\n}"), + ) + mockRepo.EXPECT().ReadLocalFile("test.js").Return(*expectedFile, nil) + file, err := service.GetLocalFileContent("test.js") + + assert.NoError(t, err) + assert.Equal(t, *expectedFile, file) + mockRepo.AssertExpectations(t) +} + +func TestGetLocalFileContent_Error(t *testing.T) { + mockRepo := mocks.NewMockFileRepository(t) + service := NewFileService(mockRepo) + + mockRepo.EXPECT().ReadLocalFile("test.js").Return(entities.File{}, errors.New("file not found")) + + file, err := service.GetLocalFileContent("test.js") + + assert.Error(t, err) + assert.Equal(t, entities.File{}, file) + mockRepo.AssertExpectations(t) +} + +func TestGetRemoteFileContent(t *testing.T) { + mockRepo := mocks.NewMockFileRepository(t) + service := NewFileService(mockRepo) + + expectedFile := entities.NewFile( + "", + "test.js", + []byte("function main() {\n\tconsole.log('Hello, World!');\n}"), + ) + + mockRepo.EXPECT().ReadRemoteFileByMD5("remote.js", "test-md5").Return(*expectedFile, nil) + + file, err := service.GetRemoteFileContent("remote.js", "test-md5") + + assert.NoError(t, err) + assert.Equal(t, *expectedFile, file) + mockRepo.AssertExpectations(t) +} + +func TestGetRemoteFileContent_Error(t *testing.T) { + mockRepo := mocks.NewMockFileRepository(t) + service := NewFileService(mockRepo) + + mockRepo.EXPECT().ReadRemoteFileByMD5("remote.js", "test-md5").Return(entities.File{}, errors.New("file not found")) + + file, err := service.GetRemoteFileContent("remote.js", "test-md5") + + assert.Error(t, err) + assert.Equal(t, entities.File{}, file) + mockRepo.AssertExpectations(t) +} diff --git a/backend/main/pkg/file/service/mocks/mock_FileService.go b/backend/main/pkg/file/service/mocks/mock_FileService.go new file mode 100644 index 0000000..5102e22 --- /dev/null +++ b/backend/main/pkg/file/service/mocks/mock_FileService.go @@ -0,0 +1,148 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import ( + entities "github.com/scanoss/scanoss.lui/backend/main/pkg/file/entities" + mock "github.com/stretchr/testify/mock" +) + +// MockFileService is an autogenerated mock type for the FileService type +type MockFileService struct { + mock.Mock +} + +type MockFileService_Expecter struct { + mock *mock.Mock +} + +func (_m *MockFileService) EXPECT() *MockFileService_Expecter { + return &MockFileService_Expecter{mock: &_m.Mock} +} + +// GetLocalFileContent provides a mock function with given fields: path +func (_m *MockFileService) GetLocalFileContent(path string) (entities.File, error) { + ret := _m.Called(path) + + if len(ret) == 0 { + panic("no return value specified for GetLocalFileContent") + } + + var r0 entities.File + var r1 error + if rf, ok := ret.Get(0).(func(string) (entities.File, error)); ok { + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) entities.File); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(entities.File) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockFileService_GetLocalFileContent_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLocalFileContent' +type MockFileService_GetLocalFileContent_Call struct { + *mock.Call +} + +// GetLocalFileContent is a helper method to define mock.On call +// - path string +func (_e *MockFileService_Expecter) GetLocalFileContent(path interface{}) *MockFileService_GetLocalFileContent_Call { + return &MockFileService_GetLocalFileContent_Call{Call: _e.mock.On("GetLocalFileContent", path)} +} + +func (_c *MockFileService_GetLocalFileContent_Call) Run(run func(path string)) *MockFileService_GetLocalFileContent_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *MockFileService_GetLocalFileContent_Call) Return(_a0 entities.File, _a1 error) *MockFileService_GetLocalFileContent_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockFileService_GetLocalFileContent_Call) RunAndReturn(run func(string) (entities.File, error)) *MockFileService_GetLocalFileContent_Call { + _c.Call.Return(run) + return _c +} + +// GetRemoteFileContent provides a mock function with given fields: path, md5 +func (_m *MockFileService) GetRemoteFileContent(path string, md5 string) (entities.File, error) { + ret := _m.Called(path, md5) + + if len(ret) == 0 { + panic("no return value specified for GetRemoteFileContent") + } + + var r0 entities.File + var r1 error + if rf, ok := ret.Get(0).(func(string, string) (entities.File, error)); ok { + return rf(path, md5) + } + if rf, ok := ret.Get(0).(func(string, string) entities.File); ok { + r0 = rf(path, md5) + } else { + r0 = ret.Get(0).(entities.File) + } + + if rf, ok := ret.Get(1).(func(string, string) error); ok { + r1 = rf(path, md5) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockFileService_GetRemoteFileContent_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRemoteFileContent' +type MockFileService_GetRemoteFileContent_Call struct { + *mock.Call +} + +// GetRemoteFileContent is a helper method to define mock.On call +// - path string +// - md5 string +func (_e *MockFileService_Expecter) GetRemoteFileContent(path interface{}, md5 interface{}) *MockFileService_GetRemoteFileContent_Call { + return &MockFileService_GetRemoteFileContent_Call{Call: _e.mock.On("GetRemoteFileContent", path, md5)} +} + +func (_c *MockFileService_GetRemoteFileContent_Call) Run(run func(path string, md5 string)) *MockFileService_GetRemoteFileContent_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(string)) + }) + return _c +} + +func (_c *MockFileService_GetRemoteFileContent_Call) Return(_a0 entities.File, _a1 error) *MockFileService_GetRemoteFileContent_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockFileService_GetRemoteFileContent_Call) RunAndReturn(run func(string, string) (entities.File, error)) *MockFileService_GetRemoteFileContent_Call { + _c.Call.Return(run) + return _c +} + +// NewMockFileService creates a new instance of MockFileService. 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 NewMockFileService(t interface { + mock.TestingT + Cleanup(func()) +}) *MockFileService { + mock := &MockFileService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/result/controllers/mocks/ResultController.go b/backend/main/pkg/result/controllers/mocks/ResultController.go deleted file mode 100644 index 302942b..0000000 --- a/backend/main/pkg/result/controllers/mocks/ResultController.go +++ /dev/null @@ -1,93 +0,0 @@ -// Code generated by mockery v2.46.1. DO NOT EDIT. - -package mocks - -import ( - entities "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities" - mock "github.com/stretchr/testify/mock" -) - -// ResultController is an autogenerated mock type for the ResultController type -type ResultController struct { - mock.Mock -} - -type ResultController_Expecter struct { - mock *mock.Mock -} - -func (_m *ResultController) EXPECT() *ResultController_Expecter { - return &ResultController_Expecter{mock: &_m.Mock} -} - -// GetAll provides a mock function with given fields: dto -func (_m *ResultController) GetAll(dto *entities.RequestResultDTO) ([]entities.ResultDTO, error) { - ret := _m.Called(dto) - - if len(ret) == 0 { - panic("no return value specified for GetAll") - } - - var r0 []entities.ResultDTO - var r1 error - if rf, ok := ret.Get(0).(func(*entities.RequestResultDTO) ([]entities.ResultDTO, error)); ok { - return rf(dto) - } - if rf, ok := ret.Get(0).(func(*entities.RequestResultDTO) []entities.ResultDTO); ok { - r0 = rf(dto) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]entities.ResultDTO) - } - } - - if rf, ok := ret.Get(1).(func(*entities.RequestResultDTO) error); ok { - r1 = rf(dto) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// ResultController_GetAll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAll' -type ResultController_GetAll_Call struct { - *mock.Call -} - -// GetAll is a helper method to define mock.On call -// - dto *entities.RequestResultDTO -func (_e *ResultController_Expecter) GetAll(dto interface{}) *ResultController_GetAll_Call { - return &ResultController_GetAll_Call{Call: _e.mock.On("GetAll", dto)} -} - -func (_c *ResultController_GetAll_Call) Run(run func(dto *entities.RequestResultDTO)) *ResultController_GetAll_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*entities.RequestResultDTO)) - }) - return _c -} - -func (_c *ResultController_GetAll_Call) Return(_a0 []entities.ResultDTO, _a1 error) *ResultController_GetAll_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *ResultController_GetAll_Call) RunAndReturn(run func(*entities.RequestResultDTO) ([]entities.ResultDTO, error)) *ResultController_GetAll_Call { - _c.Call.Return(run) - return _c -} - -// NewResultController creates a new instance of ResultController. 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 NewResultController(t interface { - mock.TestingT - Cleanup(func()) -}) *ResultController { - mock := &ResultController{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/backend/main/pkg/result/controllers/mocks/mock_ResultController.go b/backend/main/pkg/result/controllers/mocks/mock_ResultController.go new file mode 100644 index 0000000..cddc327 --- /dev/null +++ b/backend/main/pkg/result/controllers/mocks/mock_ResultController.go @@ -0,0 +1,93 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import ( + entities "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities" + mock "github.com/stretchr/testify/mock" +) + +// MockResultController is an autogenerated mock type for the ResultController type +type MockResultController struct { + mock.Mock +} + +type MockResultController_Expecter struct { + mock *mock.Mock +} + +func (_m *MockResultController) EXPECT() *MockResultController_Expecter { + return &MockResultController_Expecter{mock: &_m.Mock} +} + +// GetAll provides a mock function with given fields: dto +func (_m *MockResultController) GetAll(dto *entities.RequestResultDTO) ([]entities.ResultDTO, error) { + ret := _m.Called(dto) + + if len(ret) == 0 { + panic("no return value specified for GetAll") + } + + var r0 []entities.ResultDTO + var r1 error + if rf, ok := ret.Get(0).(func(*entities.RequestResultDTO) ([]entities.ResultDTO, error)); ok { + return rf(dto) + } + if rf, ok := ret.Get(0).(func(*entities.RequestResultDTO) []entities.ResultDTO); ok { + r0 = rf(dto) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]entities.ResultDTO) + } + } + + if rf, ok := ret.Get(1).(func(*entities.RequestResultDTO) error); ok { + r1 = rf(dto) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockResultController_GetAll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAll' +type MockResultController_GetAll_Call struct { + *mock.Call +} + +// GetAll is a helper method to define mock.On call +// - dto *entities.RequestResultDTO +func (_e *MockResultController_Expecter) GetAll(dto interface{}) *MockResultController_GetAll_Call { + return &MockResultController_GetAll_Call{Call: _e.mock.On("GetAll", dto)} +} + +func (_c *MockResultController_GetAll_Call) Run(run func(dto *entities.RequestResultDTO)) *MockResultController_GetAll_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*entities.RequestResultDTO)) + }) + return _c +} + +func (_c *MockResultController_GetAll_Call) Return(_a0 []entities.ResultDTO, _a1 error) *MockResultController_GetAll_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockResultController_GetAll_Call) RunAndReturn(run func(*entities.RequestResultDTO) ([]entities.ResultDTO, error)) *MockResultController_GetAll_Call { + _c.Call.Return(run) + return _c +} + +// NewMockResultController creates a new instance of MockResultController. 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 NewMockResultController(t interface { + mock.TestingT + Cleanup(func()) +}) *MockResultController { + mock := &MockResultController{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/result/controllers/result_controller.go b/backend/main/pkg/result/controllers/result_controller.go index cb139a1..1030a26 100644 --- a/backend/main/pkg/result/controllers/result_controller.go +++ b/backend/main/pkg/result/controllers/result_controller.go @@ -4,7 +4,6 @@ import ( "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities" ) -//go:generate mockery --name ResultController --with-expecter type ResultController interface { GetAll(dto *entities.RequestResultDTO) ([]entities.ResultDTO, error) } diff --git a/backend/main/pkg/result/controllers/result_controller_impl_test.go b/backend/main/pkg/result/controllers/result_controller_impl_test.go index 9ce26c2..558b057 100644 --- a/backend/main/pkg/result/controllers/result_controller_impl_test.go +++ b/backend/main/pkg/result/controllers/result_controller_impl_test.go @@ -3,7 +3,6 @@ package controllers_test import ( "testing" - internal_test "github.com/scanoss/scanoss.lui/backend/main/internal" "github.com/scanoss/scanoss.lui/backend/main/pkg/result/controllers" "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities" mapperMocks "github.com/scanoss/scanoss.lui/backend/main/pkg/result/mappers/mocks" @@ -12,11 +11,8 @@ import ( ) func TestGetAll(t *testing.T) { - cleanup := internal_test.InitializeTestEnvironment(t) - defer cleanup() - - mockService := serviceMocks.NewResultService(t) - mockMapper := mapperMocks.NewResultMapper(t) + mockService := serviceMocks.NewMockResultService(t) + mockMapper := mapperMocks.NewMockResultMapper(t) controller := controllers.NewResultController(mockService, mockMapper) t.Run("Valid request", func(t *testing.T) { diff --git a/backend/main/pkg/result/entities/mocks/ResultFilter.go b/backend/main/pkg/result/entities/mocks/ResultFilter.go deleted file mode 100644 index 212c704..0000000 --- a/backend/main/pkg/result/entities/mocks/ResultFilter.go +++ /dev/null @@ -1,81 +0,0 @@ -// Code generated by mockery v2.46.1. DO NOT EDIT. - -package mocks - -import ( - entities "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities" - mock "github.com/stretchr/testify/mock" -) - -// ResultFilter is an autogenerated mock type for the ResultFilter type -type ResultFilter struct { - mock.Mock -} - -type ResultFilter_Expecter struct { - mock *mock.Mock -} - -func (_m *ResultFilter) EXPECT() *ResultFilter_Expecter { - return &ResultFilter_Expecter{mock: &_m.Mock} -} - -// IsValid provides a mock function with given fields: result -func (_m *ResultFilter) IsValid(result entities.Result) bool { - ret := _m.Called(result) - - if len(ret) == 0 { - panic("no return value specified for IsValid") - } - - var r0 bool - if rf, ok := ret.Get(0).(func(entities.Result) bool); ok { - r0 = rf(result) - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// ResultFilter_IsValid_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsValid' -type ResultFilter_IsValid_Call struct { - *mock.Call -} - -// IsValid is a helper method to define mock.On call -// - result entities.Result -func (_e *ResultFilter_Expecter) IsValid(result interface{}) *ResultFilter_IsValid_Call { - return &ResultFilter_IsValid_Call{Call: _e.mock.On("IsValid", result)} -} - -func (_c *ResultFilter_IsValid_Call) Run(run func(result entities.Result)) *ResultFilter_IsValid_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(entities.Result)) - }) - return _c -} - -func (_c *ResultFilter_IsValid_Call) Return(_a0 bool) *ResultFilter_IsValid_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *ResultFilter_IsValid_Call) RunAndReturn(run func(entities.Result) bool) *ResultFilter_IsValid_Call { - _c.Call.Return(run) - return _c -} - -// NewResultFilter creates a new instance of ResultFilter. 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 NewResultFilter(t interface { - mock.TestingT - Cleanup(func()) -}) *ResultFilter { - mock := &ResultFilter{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/backend/main/pkg/result/entities/mocks/mock_ResultFilter.go b/backend/main/pkg/result/entities/mocks/mock_ResultFilter.go new file mode 100644 index 0000000..3d1290b --- /dev/null +++ b/backend/main/pkg/result/entities/mocks/mock_ResultFilter.go @@ -0,0 +1,81 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import ( + entities "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities" + mock "github.com/stretchr/testify/mock" +) + +// MockResultFilter is an autogenerated mock type for the ResultFilter type +type MockResultFilter struct { + mock.Mock +} + +type MockResultFilter_Expecter struct { + mock *mock.Mock +} + +func (_m *MockResultFilter) EXPECT() *MockResultFilter_Expecter { + return &MockResultFilter_Expecter{mock: &_m.Mock} +} + +// IsValid provides a mock function with given fields: result +func (_m *MockResultFilter) IsValid(result entities.Result) bool { + ret := _m.Called(result) + + if len(ret) == 0 { + panic("no return value specified for IsValid") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(entities.Result) bool); ok { + r0 = rf(result) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// MockResultFilter_IsValid_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsValid' +type MockResultFilter_IsValid_Call struct { + *mock.Call +} + +// IsValid is a helper method to define mock.On call +// - result entities.Result +func (_e *MockResultFilter_Expecter) IsValid(result interface{}) *MockResultFilter_IsValid_Call { + return &MockResultFilter_IsValid_Call{Call: _e.mock.On("IsValid", result)} +} + +func (_c *MockResultFilter_IsValid_Call) Run(run func(result entities.Result)) *MockResultFilter_IsValid_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(entities.Result)) + }) + return _c +} + +func (_c *MockResultFilter_IsValid_Call) Return(_a0 bool) *MockResultFilter_IsValid_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockResultFilter_IsValid_Call) RunAndReturn(run func(entities.Result) bool) *MockResultFilter_IsValid_Call { + _c.Call.Return(run) + return _c +} + +// NewMockResultFilter creates a new instance of MockResultFilter. 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 NewMockResultFilter(t interface { + mock.TestingT + Cleanup(func()) +}) *MockResultFilter { + mock := &MockResultFilter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/result/entities/result.go b/backend/main/pkg/result/entities/result.go index 42c3b9c..c5847af 100644 --- a/backend/main/pkg/result/entities/result.go +++ b/backend/main/pkg/result/entities/result.go @@ -35,7 +35,6 @@ func (r *Result) GetFileName() string { return fileName } -//go:generate mockery --name ResultFilter --with-expecter type ResultFilter interface { IsValid(result Result) bool } diff --git a/backend/main/pkg/result/mappers/mocks/ResultMapper.go b/backend/main/pkg/result/mappers/mocks/ResultMapper.go deleted file mode 100644 index 6072443..0000000 --- a/backend/main/pkg/result/mappers/mocks/ResultMapper.go +++ /dev/null @@ -1,130 +0,0 @@ -// Code generated by mockery v2.46.1. DO NOT EDIT. - -package mocks - -import ( - entities "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities" - - mock "github.com/stretchr/testify/mock" -) - -// ResultMapper is an autogenerated mock type for the ResultMapper type -type ResultMapper struct { - mock.Mock -} - -type ResultMapper_Expecter struct { - mock *mock.Mock -} - -func (_m *ResultMapper) EXPECT() *ResultMapper_Expecter { - return &ResultMapper_Expecter{mock: &_m.Mock} -} - -// MapToResultDTO provides a mock function with given fields: result -func (_m *ResultMapper) MapToResultDTO(result entities.Result) entities.ResultDTO { - ret := _m.Called(result) - - if len(ret) == 0 { - panic("no return value specified for MapToResultDTO") - } - - var r0 entities.ResultDTO - if rf, ok := ret.Get(0).(func(entities.Result) entities.ResultDTO); ok { - r0 = rf(result) - } else { - r0 = ret.Get(0).(entities.ResultDTO) - } - - return r0 -} - -// ResultMapper_MapToResultDTO_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MapToResultDTO' -type ResultMapper_MapToResultDTO_Call struct { - *mock.Call -} - -// MapToResultDTO is a helper method to define mock.On call -// - result entities.Result -func (_e *ResultMapper_Expecter) MapToResultDTO(result interface{}) *ResultMapper_MapToResultDTO_Call { - return &ResultMapper_MapToResultDTO_Call{Call: _e.mock.On("MapToResultDTO", result)} -} - -func (_c *ResultMapper_MapToResultDTO_Call) Run(run func(result entities.Result)) *ResultMapper_MapToResultDTO_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(entities.Result)) - }) - return _c -} - -func (_c *ResultMapper_MapToResultDTO_Call) Return(_a0 entities.ResultDTO) *ResultMapper_MapToResultDTO_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *ResultMapper_MapToResultDTO_Call) RunAndReturn(run func(entities.Result) entities.ResultDTO) *ResultMapper_MapToResultDTO_Call { - _c.Call.Return(run) - return _c -} - -// MapToResultDTOList provides a mock function with given fields: results -func (_m *ResultMapper) MapToResultDTOList(results []entities.Result) []entities.ResultDTO { - ret := _m.Called(results) - - if len(ret) == 0 { - panic("no return value specified for MapToResultDTOList") - } - - var r0 []entities.ResultDTO - if rf, ok := ret.Get(0).(func([]entities.Result) []entities.ResultDTO); ok { - r0 = rf(results) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]entities.ResultDTO) - } - } - - return r0 -} - -// ResultMapper_MapToResultDTOList_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MapToResultDTOList' -type ResultMapper_MapToResultDTOList_Call struct { - *mock.Call -} - -// MapToResultDTOList is a helper method to define mock.On call -// - results []entities.Result -func (_e *ResultMapper_Expecter) MapToResultDTOList(results interface{}) *ResultMapper_MapToResultDTOList_Call { - return &ResultMapper_MapToResultDTOList_Call{Call: _e.mock.On("MapToResultDTOList", results)} -} - -func (_c *ResultMapper_MapToResultDTOList_Call) Run(run func(results []entities.Result)) *ResultMapper_MapToResultDTOList_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].([]entities.Result)) - }) - return _c -} - -func (_c *ResultMapper_MapToResultDTOList_Call) Return(_a0 []entities.ResultDTO) *ResultMapper_MapToResultDTOList_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *ResultMapper_MapToResultDTOList_Call) RunAndReturn(run func([]entities.Result) []entities.ResultDTO) *ResultMapper_MapToResultDTOList_Call { - _c.Call.Return(run) - return _c -} - -// NewResultMapper creates a new instance of ResultMapper. 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 NewResultMapper(t interface { - mock.TestingT - Cleanup(func()) -}) *ResultMapper { - mock := &ResultMapper{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/backend/main/pkg/result/mappers/mocks/mock_ResultMapper.go b/backend/main/pkg/result/mappers/mocks/mock_ResultMapper.go new file mode 100644 index 0000000..2c64374 --- /dev/null +++ b/backend/main/pkg/result/mappers/mocks/mock_ResultMapper.go @@ -0,0 +1,130 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import ( + entities "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities" + + mock "github.com/stretchr/testify/mock" +) + +// MockResultMapper is an autogenerated mock type for the ResultMapper type +type MockResultMapper struct { + mock.Mock +} + +type MockResultMapper_Expecter struct { + mock *mock.Mock +} + +func (_m *MockResultMapper) EXPECT() *MockResultMapper_Expecter { + return &MockResultMapper_Expecter{mock: &_m.Mock} +} + +// MapToResultDTO provides a mock function with given fields: result +func (_m *MockResultMapper) MapToResultDTO(result entities.Result) entities.ResultDTO { + ret := _m.Called(result) + + if len(ret) == 0 { + panic("no return value specified for MapToResultDTO") + } + + var r0 entities.ResultDTO + if rf, ok := ret.Get(0).(func(entities.Result) entities.ResultDTO); ok { + r0 = rf(result) + } else { + r0 = ret.Get(0).(entities.ResultDTO) + } + + return r0 +} + +// MockResultMapper_MapToResultDTO_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MapToResultDTO' +type MockResultMapper_MapToResultDTO_Call struct { + *mock.Call +} + +// MapToResultDTO is a helper method to define mock.On call +// - result entities.Result +func (_e *MockResultMapper_Expecter) MapToResultDTO(result interface{}) *MockResultMapper_MapToResultDTO_Call { + return &MockResultMapper_MapToResultDTO_Call{Call: _e.mock.On("MapToResultDTO", result)} +} + +func (_c *MockResultMapper_MapToResultDTO_Call) Run(run func(result entities.Result)) *MockResultMapper_MapToResultDTO_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(entities.Result)) + }) + return _c +} + +func (_c *MockResultMapper_MapToResultDTO_Call) Return(_a0 entities.ResultDTO) *MockResultMapper_MapToResultDTO_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockResultMapper_MapToResultDTO_Call) RunAndReturn(run func(entities.Result) entities.ResultDTO) *MockResultMapper_MapToResultDTO_Call { + _c.Call.Return(run) + return _c +} + +// MapToResultDTOList provides a mock function with given fields: results +func (_m *MockResultMapper) MapToResultDTOList(results []entities.Result) []entities.ResultDTO { + ret := _m.Called(results) + + if len(ret) == 0 { + panic("no return value specified for MapToResultDTOList") + } + + var r0 []entities.ResultDTO + if rf, ok := ret.Get(0).(func([]entities.Result) []entities.ResultDTO); ok { + r0 = rf(results) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]entities.ResultDTO) + } + } + + return r0 +} + +// MockResultMapper_MapToResultDTOList_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MapToResultDTOList' +type MockResultMapper_MapToResultDTOList_Call struct { + *mock.Call +} + +// MapToResultDTOList is a helper method to define mock.On call +// - results []entities.Result +func (_e *MockResultMapper_Expecter) MapToResultDTOList(results interface{}) *MockResultMapper_MapToResultDTOList_Call { + return &MockResultMapper_MapToResultDTOList_Call{Call: _e.mock.On("MapToResultDTOList", results)} +} + +func (_c *MockResultMapper_MapToResultDTOList_Call) Run(run func(results []entities.Result)) *MockResultMapper_MapToResultDTOList_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]entities.Result)) + }) + return _c +} + +func (_c *MockResultMapper_MapToResultDTOList_Call) Return(_a0 []entities.ResultDTO) *MockResultMapper_MapToResultDTOList_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockResultMapper_MapToResultDTOList_Call) RunAndReturn(run func([]entities.Result) []entities.ResultDTO) *MockResultMapper_MapToResultDTOList_Call { + _c.Call.Return(run) + return _c +} + +// NewMockResultMapper creates a new instance of MockResultMapper. 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 NewMockResultMapper(t interface { + mock.TestingT + Cleanup(func()) +}) *MockResultMapper { + mock := &MockResultMapper{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/result/mappers/result_mapper.go b/backend/main/pkg/result/mappers/result_mapper.go index 2acba25..1de6a2a 100644 --- a/backend/main/pkg/result/mappers/result_mapper.go +++ b/backend/main/pkg/result/mappers/result_mapper.go @@ -2,7 +2,6 @@ package mappers import "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities" -//go:generate mockery --name ResultMapper --with-expecter type ResultMapper interface { MapToResultDTO(result entities.Result) entities.ResultDTO MapToResultDTOList(results []entities.Result) []entities.ResultDTO diff --git a/backend/main/pkg/result/repository/mocks/ResultRepository.go b/backend/main/pkg/result/repository/mocks/ResultRepository.go deleted file mode 100644 index 67849a5..0000000 --- a/backend/main/pkg/result/repository/mocks/ResultRepository.go +++ /dev/null @@ -1,93 +0,0 @@ -// Code generated by mockery v2.46.1. DO NOT EDIT. - -package mocks - -import ( - entities "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities" - mock "github.com/stretchr/testify/mock" -) - -// ResultRepository is an autogenerated mock type for the ResultRepository type -type ResultRepository struct { - mock.Mock -} - -type ResultRepository_Expecter struct { - mock *mock.Mock -} - -func (_m *ResultRepository) EXPECT() *ResultRepository_Expecter { - return &ResultRepository_Expecter{mock: &_m.Mock} -} - -// GetResults provides a mock function with given fields: filters -func (_m *ResultRepository) GetResults(filters entities.ResultFilter) ([]entities.Result, error) { - ret := _m.Called(filters) - - if len(ret) == 0 { - panic("no return value specified for GetResults") - } - - var r0 []entities.Result - var r1 error - if rf, ok := ret.Get(0).(func(entities.ResultFilter) ([]entities.Result, error)); ok { - return rf(filters) - } - if rf, ok := ret.Get(0).(func(entities.ResultFilter) []entities.Result); ok { - r0 = rf(filters) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]entities.Result) - } - } - - if rf, ok := ret.Get(1).(func(entities.ResultFilter) error); ok { - r1 = rf(filters) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// ResultRepository_GetResults_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetResults' -type ResultRepository_GetResults_Call struct { - *mock.Call -} - -// GetResults is a helper method to define mock.On call -// - filters entities.ResultFilter -func (_e *ResultRepository_Expecter) GetResults(filters interface{}) *ResultRepository_GetResults_Call { - return &ResultRepository_GetResults_Call{Call: _e.mock.On("GetResults", filters)} -} - -func (_c *ResultRepository_GetResults_Call) Run(run func(filters entities.ResultFilter)) *ResultRepository_GetResults_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(entities.ResultFilter)) - }) - return _c -} - -func (_c *ResultRepository_GetResults_Call) Return(_a0 []entities.Result, _a1 error) *ResultRepository_GetResults_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *ResultRepository_GetResults_Call) RunAndReturn(run func(entities.ResultFilter) ([]entities.Result, error)) *ResultRepository_GetResults_Call { - _c.Call.Return(run) - return _c -} - -// NewResultRepository creates a new instance of ResultRepository. 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 NewResultRepository(t interface { - mock.TestingT - Cleanup(func()) -}) *ResultRepository { - mock := &ResultRepository{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/backend/main/pkg/result/repository/mocks/mock_ResultRepository.go b/backend/main/pkg/result/repository/mocks/mock_ResultRepository.go new file mode 100644 index 0000000..f384151 --- /dev/null +++ b/backend/main/pkg/result/repository/mocks/mock_ResultRepository.go @@ -0,0 +1,93 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import ( + entities "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities" + mock "github.com/stretchr/testify/mock" +) + +// MockResultRepository is an autogenerated mock type for the ResultRepository type +type MockResultRepository struct { + mock.Mock +} + +type MockResultRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockResultRepository) EXPECT() *MockResultRepository_Expecter { + return &MockResultRepository_Expecter{mock: &_m.Mock} +} + +// GetResults provides a mock function with given fields: filters +func (_m *MockResultRepository) GetResults(filters entities.ResultFilter) ([]entities.Result, error) { + ret := _m.Called(filters) + + if len(ret) == 0 { + panic("no return value specified for GetResults") + } + + var r0 []entities.Result + var r1 error + if rf, ok := ret.Get(0).(func(entities.ResultFilter) ([]entities.Result, error)); ok { + return rf(filters) + } + if rf, ok := ret.Get(0).(func(entities.ResultFilter) []entities.Result); ok { + r0 = rf(filters) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]entities.Result) + } + } + + if rf, ok := ret.Get(1).(func(entities.ResultFilter) error); ok { + r1 = rf(filters) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockResultRepository_GetResults_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetResults' +type MockResultRepository_GetResults_Call struct { + *mock.Call +} + +// GetResults is a helper method to define mock.On call +// - filters entities.ResultFilter +func (_e *MockResultRepository_Expecter) GetResults(filters interface{}) *MockResultRepository_GetResults_Call { + return &MockResultRepository_GetResults_Call{Call: _e.mock.On("GetResults", filters)} +} + +func (_c *MockResultRepository_GetResults_Call) Run(run func(filters entities.ResultFilter)) *MockResultRepository_GetResults_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(entities.ResultFilter)) + }) + return _c +} + +func (_c *MockResultRepository_GetResults_Call) Return(_a0 []entities.Result, _a1 error) *MockResultRepository_GetResults_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockResultRepository_GetResults_Call) RunAndReturn(run func(entities.ResultFilter) ([]entities.Result, error)) *MockResultRepository_GetResults_Call { + _c.Call.Return(run) + return _c +} + +// NewMockResultRepository creates a new instance of MockResultRepository. 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 NewMockResultRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockResultRepository { + mock := &MockResultRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/result/repository/result_repository.go b/backend/main/pkg/result/repository/result_repository.go index a7442dc..d6c8d90 100644 --- a/backend/main/pkg/result/repository/result_repository.go +++ b/backend/main/pkg/result/repository/result_repository.go @@ -4,7 +4,6 @@ import ( "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities" ) -//go:generate mockery --name ResultRepository --with-expecter type ResultRepository interface { GetResults(filters entities.ResultFilter) ([]entities.Result, error) } diff --git a/backend/main/pkg/result/repository/result_repository_json_impl_test.go b/backend/main/pkg/result/repository/result_repository_json_impl_test.go index 2741b98..9abe047 100644 --- a/backend/main/pkg/result/repository/result_repository_json_impl_test.go +++ b/backend/main/pkg/result/repository/result_repository_json_impl_test.go @@ -34,7 +34,7 @@ func TestGetResults(t *testing.T) { mu := internal_test.NewMockUtils() mu.On("ReadFile", config.Get().ResultFilePath).Return([]byte(`{"path/to/file": [{"ID": "file", "Purl": ["pkg:example/package"]}]}`), nil) - filter := mocks.ResultFilter{} + filter := mocks.MockResultFilter{} filter.EXPECT().IsValid(mock.Anything).Return(true) repo := repository.NewResultRepositoryJsonImpl(mu) @@ -74,7 +74,7 @@ func TestGetResults(t *testing.T) { mu := internal_test.NewMockUtils() mu.On("ReadFile", config.Get().ResultFilePath).Return([]byte(`{"path/to/file": [{"ID": "file", "Purl": ["pkg:example/package"]}]}`), nil) - filter := mocks.ResultFilter{} + filter := mocks.MockResultFilter{} filter.EXPECT().IsValid(mock.Anything).Return(false) repo := repository.NewResultRepositoryJsonImpl(mu) diff --git a/backend/main/pkg/result/service/mocks/ResultService.go b/backend/main/pkg/result/service/mocks/ResultService.go deleted file mode 100644 index 1e02922..0000000 --- a/backend/main/pkg/result/service/mocks/ResultService.go +++ /dev/null @@ -1,93 +0,0 @@ -// Code generated by mockery v2.46.1. DO NOT EDIT. - -package mocks - -import ( - entities "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities" - mock "github.com/stretchr/testify/mock" -) - -// ResultService is an autogenerated mock type for the ResultService type -type ResultService struct { - mock.Mock -} - -type ResultService_Expecter struct { - mock *mock.Mock -} - -func (_m *ResultService) EXPECT() *ResultService_Expecter { - return &ResultService_Expecter{mock: &_m.Mock} -} - -// GetResults provides a mock function with given fields: filters -func (_m *ResultService) GetResults(filters entities.ResultFilter) ([]entities.Result, error) { - ret := _m.Called(filters) - - if len(ret) == 0 { - panic("no return value specified for GetResults") - } - - var r0 []entities.Result - var r1 error - if rf, ok := ret.Get(0).(func(entities.ResultFilter) ([]entities.Result, error)); ok { - return rf(filters) - } - if rf, ok := ret.Get(0).(func(entities.ResultFilter) []entities.Result); ok { - r0 = rf(filters) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]entities.Result) - } - } - - if rf, ok := ret.Get(1).(func(entities.ResultFilter) error); ok { - r1 = rf(filters) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// ResultService_GetResults_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetResults' -type ResultService_GetResults_Call struct { - *mock.Call -} - -// GetResults is a helper method to define mock.On call -// - filters entities.ResultFilter -func (_e *ResultService_Expecter) GetResults(filters interface{}) *ResultService_GetResults_Call { - return &ResultService_GetResults_Call{Call: _e.mock.On("GetResults", filters)} -} - -func (_c *ResultService_GetResults_Call) Run(run func(filters entities.ResultFilter)) *ResultService_GetResults_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(entities.ResultFilter)) - }) - return _c -} - -func (_c *ResultService_GetResults_Call) Return(_a0 []entities.Result, _a1 error) *ResultService_GetResults_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *ResultService_GetResults_Call) RunAndReturn(run func(entities.ResultFilter) ([]entities.Result, error)) *ResultService_GetResults_Call { - _c.Call.Return(run) - return _c -} - -// NewResultService creates a new instance of ResultService. 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 NewResultService(t interface { - mock.TestingT - Cleanup(func()) -}) *ResultService { - mock := &ResultService{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/backend/main/pkg/result/service/mocks/mock_ResultService.go b/backend/main/pkg/result/service/mocks/mock_ResultService.go new file mode 100644 index 0000000..9324534 --- /dev/null +++ b/backend/main/pkg/result/service/mocks/mock_ResultService.go @@ -0,0 +1,93 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import ( + entities "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities" + mock "github.com/stretchr/testify/mock" +) + +// MockResultService is an autogenerated mock type for the ResultService type +type MockResultService struct { + mock.Mock +} + +type MockResultService_Expecter struct { + mock *mock.Mock +} + +func (_m *MockResultService) EXPECT() *MockResultService_Expecter { + return &MockResultService_Expecter{mock: &_m.Mock} +} + +// GetResults provides a mock function with given fields: filters +func (_m *MockResultService) GetResults(filters entities.ResultFilter) ([]entities.Result, error) { + ret := _m.Called(filters) + + if len(ret) == 0 { + panic("no return value specified for GetResults") + } + + var r0 []entities.Result + var r1 error + if rf, ok := ret.Get(0).(func(entities.ResultFilter) ([]entities.Result, error)); ok { + return rf(filters) + } + if rf, ok := ret.Get(0).(func(entities.ResultFilter) []entities.Result); ok { + r0 = rf(filters) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]entities.Result) + } + } + + if rf, ok := ret.Get(1).(func(entities.ResultFilter) error); ok { + r1 = rf(filters) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockResultService_GetResults_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetResults' +type MockResultService_GetResults_Call struct { + *mock.Call +} + +// GetResults is a helper method to define mock.On call +// - filters entities.ResultFilter +func (_e *MockResultService_Expecter) GetResults(filters interface{}) *MockResultService_GetResults_Call { + return &MockResultService_GetResults_Call{Call: _e.mock.On("GetResults", filters)} +} + +func (_c *MockResultService_GetResults_Call) Run(run func(filters entities.ResultFilter)) *MockResultService_GetResults_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(entities.ResultFilter)) + }) + return _c +} + +func (_c *MockResultService_GetResults_Call) Return(_a0 []entities.Result, _a1 error) *MockResultService_GetResults_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockResultService_GetResults_Call) RunAndReturn(run func(entities.ResultFilter) ([]entities.Result, error)) *MockResultService_GetResults_Call { + _c.Call.Return(run) + return _c +} + +// NewMockResultService creates a new instance of MockResultService. 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 NewMockResultService(t interface { + mock.TestingT + Cleanup(func()) +}) *MockResultService { + mock := &MockResultService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/backend/main/pkg/result/service/result_service.go b/backend/main/pkg/result/service/result_service.go index e297038..c5e8229 100644 --- a/backend/main/pkg/result/service/result_service.go +++ b/backend/main/pkg/result/service/result_service.go @@ -4,7 +4,6 @@ import ( "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities" ) -//go:generate mockery --name ResultService --with-expecter type ResultService interface { GetResults(filters entities.ResultFilter) ([]entities.Result, error) } diff --git a/backend/main/pkg/result/service/result_service_impl_test.go b/backend/main/pkg/result/service/result_service_impl_test.go index 0f345cf..673f51e 100644 --- a/backend/main/pkg/result/service/result_service_impl_test.go +++ b/backend/main/pkg/result/service/result_service_impl_test.go @@ -7,8 +7,8 @@ import ( "github.com/scanoss/scanoss.lui/backend/main/pkg/common/config" "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities" entitiesMocks "github.com/scanoss/scanoss.lui/backend/main/pkg/result/entities/mocks" - "github.com/scanoss/scanoss.lui/backend/main/pkg/result/repository/mocks" "github.com/scanoss/scanoss.lui/backend/main/pkg/result/service" + mocks "github.com/scanoss/scanoss.lui/backend/main/pkg/result/service/mocks" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -20,10 +20,10 @@ func TestGetResults(t *testing.T) { mu := internal_test.NewMockUtils() mu.On("ReadFile", config.Get().ResultFilePath).Return([]byte(`{"path/to/file": [{"ID": "file", "Purl": ["pkg:example/package"]}]}`), nil) - filter := entitiesMocks.ResultFilter{} + filter := entitiesMocks.MockResultFilter{} filter.EXPECT().IsValid(mock.Anything).Return(true) - mockRepo := mocks.NewResultRepository(t) + mockRepo := mocks.NewMockResultService(t) mockRepo.EXPECT().GetResults(&filter).Return([]entities.Result{ { Path: "path/to/file", diff --git a/backend/main/pkg/utils/mocks/mock_FileReader.go b/backend/main/pkg/utils/mocks/mock_FileReader.go new file mode 100644 index 0000000..dc933bd --- /dev/null +++ b/backend/main/pkg/utils/mocks/mock_FileReader.go @@ -0,0 +1,90 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// MockFileReader is an autogenerated mock type for the FileReader type +type MockFileReader struct { + mock.Mock +} + +type MockFileReader_Expecter struct { + mock *mock.Mock +} + +func (_m *MockFileReader) EXPECT() *MockFileReader_Expecter { + return &MockFileReader_Expecter{mock: &_m.Mock} +} + +// ReadFile provides a mock function with given fields: filePath +func (_m *MockFileReader) ReadFile(filePath string) ([]byte, error) { + ret := _m.Called(filePath) + + if len(ret) == 0 { + panic("no return value specified for ReadFile") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(string) ([]byte, error)); ok { + return rf(filePath) + } + if rf, ok := ret.Get(0).(func(string) []byte); ok { + r0 = rf(filePath) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(filePath) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockFileReader_ReadFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReadFile' +type MockFileReader_ReadFile_Call struct { + *mock.Call +} + +// ReadFile is a helper method to define mock.On call +// - filePath string +func (_e *MockFileReader_Expecter) ReadFile(filePath interface{}) *MockFileReader_ReadFile_Call { + return &MockFileReader_ReadFile_Call{Call: _e.mock.On("ReadFile", filePath)} +} + +func (_c *MockFileReader_ReadFile_Call) Run(run func(filePath string)) *MockFileReader_ReadFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *MockFileReader_ReadFile_Call) Return(_a0 []byte, _a1 error) *MockFileReader_ReadFile_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockFileReader_ReadFile_Call) RunAndReturn(run func(string) ([]byte, error)) *MockFileReader_ReadFile_Call { + _c.Call.Return(run) + return _c +} + +// NewMockFileReader creates a new instance of MockFileReader. 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 NewMockFileReader(t interface { + mock.TestingT + Cleanup(func()) +}) *MockFileReader { + mock := &MockFileReader{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +}