From 5a2cdcacb93a4829f97d6f68fcbc2d3aa89bada8 Mon Sep 17 00:00:00 2001 From: dd84ai Date: Mon, 30 Oct 2023 01:07:50 +0100 Subject: [PATCH] refactor: scrappy further in creating instances --- management/run.go | 4 ++-- scrappy/base/mock.go | 8 ++++---- scrappy/base/storage_test.go | 2 +- scrappy/player/mock.go | 8 ++++---- scrappy/player/storage_test.go | 2 +- viewer/templ/base_test.go | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/management/run.go b/management/run.go index b296008..346135b 100644 --- a/management/run.go +++ b/management/run.go @@ -33,8 +33,8 @@ var runCmd = &cobra.Command{ configurator.NewConfigurator(settings.Dbpath).Migrate() if settings.Config.DevEnvMockApi == "true" { - scrappy.Storage.BaseStorage.Api = base.APIBasespy{}.New() - scrappy.Storage.PlayerStorage.Api = player.APIPlayerSpy{}.New() + scrappy.Storage.BaseStorage.Api = base.NewBaseApiMock() + scrappy.Storage.PlayerStorage.Api = player.NewPlayerAPI() scrappy.Storage.Update() } diff --git a/scrappy/base/mock.go b/scrappy/base/mock.go index 088d13d..08216f8 100644 --- a/scrappy/base/mock.go +++ b/scrappy/base/mock.go @@ -14,19 +14,19 @@ type APIspy struct { Filename string } -type APIBasespy struct { +type apiBaseSpy struct { APIspy } func NewMock(filename string) api.APIinterface { - return APIBasespy{APIspy{Filename: filename}} + return apiBaseSpy{APIspy{Filename: filename}} } -func (a APIBasespy) New() api.APIinterface { +func NewBaseApiMock() api.APIinterface { return NewMock("basedata.json") } -func (a APIBasespy) GetData() ([]byte, error) { +func (a apiBaseSpy) GetData() ([]byte, error) { path_testdata := tests.FixtureCreateTestDataFolder() path_testfile := path.Join(path_testdata, a.Filename) data, err := ioutil.ReadFile(path_testfile) diff --git a/scrappy/base/storage_test.go b/scrappy/base/storage_test.go index c4291c4..ec8d068 100644 --- a/scrappy/base/storage_test.go +++ b/scrappy/base/storage_test.go @@ -10,7 +10,7 @@ import ( func FixtureBaseStorageMockified() *BaseStorage { storage := (&BaseStorage{}).New() - storage.Api = APIBasespy{}.New() + storage.Api = NewBaseApiMock() return storage } diff --git a/scrappy/player/mock.go b/scrappy/player/mock.go index ea76bd3..53069b6 100644 --- a/scrappy/player/mock.go +++ b/scrappy/player/mock.go @@ -25,14 +25,14 @@ func TestRegeneratePlayerData(t *testing.T) { // SPY -type APIPlayerSpy struct { +type apiPlayerSpy struct { } -func (a APIPlayerSpy) New() api.APIinterface { - return a +func NewPlayerMockAPI() api.APIinterface { + return apiPlayerSpy{} } -func (a APIPlayerSpy) GetData() ([]byte, error) { +func (a apiPlayerSpy) GetData() ([]byte, error) { path_testdata := tests.FixtureCreateTestDataFolder() path_testfile := path.Join(path_testdata, "playerdata.json") data, err := os.ReadFile(path_testfile) diff --git a/scrappy/player/storage_test.go b/scrappy/player/storage_test.go index e7ba064..65eaa37 100644 --- a/scrappy/player/storage_test.go +++ b/scrappy/player/storage_test.go @@ -10,7 +10,7 @@ import ( func FixturePlayerStorageMockified() *PlayerStorage { storage := (&PlayerStorage{}).New() - storage.Api = APIPlayerSpy{} + storage.Api = NewPlayerMockAPI() return storage } diff --git a/viewer/templ/base_test.go b/viewer/templ/base_test.go index 3beeaac..f68ccc3 100644 --- a/viewer/templ/base_test.go +++ b/viewer/templ/base_test.go @@ -142,7 +142,7 @@ func TestGetDerivative(t *testing.T) { scrappy.Storage.PlayerStorage = (&player.PlayerStorage{}).New() scrappy.Storage.BaseStorage.Api = base.NewMock("basedata.json") logger.Debug("2.1") - scrappy.Storage.PlayerStorage.Api = player.APIPlayerSpy{}.New() + scrappy.Storage.PlayerStorage.Api = player.NewPlayerMockAPI() logger.Debug("2.2") scrappy.Storage.Update() logger.Debug("2.3") @@ -190,8 +190,8 @@ func TestDetectAttackOnLPBase(t *testing.T) { scrappy.Storage = (&scrappy.ScrappyStorage{}).New() - scrappy.Storage.BaseStorage.Api = base.APIBasespy{}.New() - scrappy.Storage.PlayerStorage.Api = player.APIPlayerSpy{}.New() + scrappy.Storage.BaseStorage.Api = base.NewBaseApiMock() + scrappy.Storage.PlayerStorage.Api = player.NewPlayerMockAPI() scrappy.Storage.BaseAttackStorage.Api = baseattack.NewMock("data_lp.json") scrappy.Storage.Update()