Skip to content

Commit

Permalink
refactor: scrappy further in creating instances
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Oct 30, 2023
1 parent 1c5515a commit 5a2cdca
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions management/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
8 changes: 4 additions & 4 deletions scrappy/base/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion scrappy/base/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func FixtureBaseStorageMockified() *BaseStorage {
storage := (&BaseStorage{}).New()
storage.Api = APIBasespy{}.New()
storage.Api = NewBaseApiMock()
return storage
}

Expand Down
8 changes: 4 additions & 4 deletions scrappy/player/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion scrappy/player/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func FixturePlayerStorageMockified() *PlayerStorage {
storage := (&PlayerStorage{}).New()
storage.Api = APIPlayerSpy{}
storage.Api = NewPlayerMockAPI()
return storage
}

Expand Down
6 changes: 3 additions & 3 deletions viewer/templ/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 5a2cdca

Please sign in to comment.