Skip to content

Commit

Permalink
refactor: starting refactors in scrappy
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Oct 30, 2023
1 parent 497fc64 commit 1c5515a
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion scrappy/base/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ type basesAPI struct {
api.APIrequest
}

func (a basesAPI) New() api.APIinterface {
func NewBaseApi() api.APIinterface {
a := basesAPI{}
a.Init(settings.Config.ScrappyBaseUrl)
return a
}
2 changes: 1 addition & 1 deletion scrappy/base/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestRegenerateBaseData(t *testing.T) {
utils.RegenerativeTest(func() error {
data, _ := basesAPI{}.New().GetData()
data, _ := NewBaseApi().GetData()
path_testdata := tests.FixtureCreateTestDataFolder()
path_testfile := path.Join(path_testdata, "basedata.json")
err := ioutil.WriteFile(path_testfile, data, os.ModePerm)
Expand Down
2 changes: 1 addition & 1 deletion scrappy/base/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ func (b *BaseStorage) Update() {

func (b *BaseStorage) New() *BaseStorage {
b.parser = baseParser{}
b.Api = basesAPI{}.New()
b.Api = NewBaseApi()
return b
}
3 changes: 2 additions & 1 deletion scrappy/player/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ type PlayerAPI struct {
api.APIrequest
}

func (a PlayerAPI) New() api.APIinterface {
func NewPlayerAPI() api.APIinterface {
a := PlayerAPI{}
a.Init(settings.Config.ScrappyPlayerUrl)
return a
}
9 changes: 5 additions & 4 deletions scrappy/player/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ package player
import (
"darkbot/scrappy/shared/api"
"darkbot/scrappy/tests"
"darkbot/settings/logus"
"darkbot/settings/utils"
"darkbot/settings/utils/logger"
"io/ioutil"
"os"
"path"
"testing"
)

func TestRegeneratePlayerData(t *testing.T) {
utils.RegenerativeTest(func() error {
data, err := PlayerAPI{}.New().GetData()
data, err := NewPlayerAPI().GetData()
logus.CheckError(err, "new player api get data errored")
path_testdata := tests.FixtureCreateTestDataFolder()
path_testfile := path.Join(path_testdata, "playerdata.json")
err = ioutil.WriteFile(path_testfile, data, os.ModePerm)
err = os.WriteFile(path_testfile, data, os.ModePerm)
logger.CheckPanic(err, "unable to write file")
return nil
})
Expand All @@ -34,7 +35,7 @@ func (a APIPlayerSpy) New() api.APIinterface {
func (a APIPlayerSpy) GetData() ([]byte, error) {
path_testdata := tests.FixtureCreateTestDataFolder()
path_testfile := path.Join(path_testdata, "playerdata.json")
data, err := ioutil.ReadFile(path_testfile)
data, err := os.ReadFile(path_testfile)
logger.CheckPanic(err, "unable to read file")
return data, nil
}
2 changes: 1 addition & 1 deletion scrappy/player/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ func (b *PlayerStorage) Update() {

func (b *PlayerStorage) New() *PlayerStorage {
b.parser = playerParser{}
b.Api = PlayerAPI{}.New()
b.Api = NewPlayerAPI()
return b
}
1 change: 0 additions & 1 deletion scrappy/shared/api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ package api

type APIinterface interface {
GetData() ([]byte, error)
New() APIinterface
}

0 comments on commit 1c5515a

Please sign in to comment.