Skip to content

Commit

Permalink
refactor: types to sub folder
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Oct 29, 2023
1 parent acbb761 commit 497fc64
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 51 deletions.
6 changes: 3 additions & 3 deletions configurator/alerts_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package configurator

import (
"darkbot/dtypes"
"darkbot/settings/types"
"darkbot/settings/utils"
"fmt"
"testing"
Expand All @@ -10,7 +10,7 @@ import (
)

func TestAlertTreshold(t *testing.T) {
FixtureMigrator(func(dbpath dtypes.Dbpath) {
FixtureMigrator(func(dbpath types.Dbpath) {
channelID, _ := FixtureChannel(dbpath)
genericCfg := NewConfigurator(dbpath).Migrate()
_ = channelID
Expand All @@ -33,7 +33,7 @@ func TestAlertTreshold(t *testing.T) {
}

func TestAlertBool(t *testing.T) {
FixtureMigrator(func(dbpath dtypes.Dbpath) {
FixtureMigrator(func(dbpath types.Dbpath) {
channelID, _ := FixtureChannel(dbpath)
genericCfg := NewConfigurator(dbpath).Migrate()
_ = channelID
Expand Down
4 changes: 2 additions & 2 deletions configurator/channel_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package configurator

import (
"darkbot/dtypes"
"darkbot/settings/types"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
)

func TestChannels(t *testing.T) {
FixtureMigrator(func(dbpath dtypes.Dbpath) {
FixtureMigrator(func(dbpath types.Dbpath) {
channelID, cg := FixtureChannel(dbpath)
cg.Remove(channelID)

Expand Down
4 changes: 2 additions & 2 deletions configurator/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package configurator

import (
"darkbot/configurator/models"
"darkbot/dtypes"
"darkbot/settings"
"darkbot/settings/types"
"darkbot/settings/utils/logger"

"gorm.io/driver/sqlite"
Expand All @@ -22,7 +22,7 @@ func (cg Configurator) GetClient() *gorm.DB {
return cg.db
}

func NewConfigurator(dbpath dtypes.Dbpath) Configurator {
func NewConfigurator(dbpath types.Dbpath) Configurator {
db, err := gorm.Open(
sqlite.Open(string(dbpath)+"?cache=shared&mode=rwc&_journal_mode=WAL"), &gorm.Config{},
)
Expand Down
10 changes: 5 additions & 5 deletions configurator/fixtures.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package configurator

import (
"darkbot/dtypes"
"darkbot/settings"
"darkbot/settings/types"
"darkbot/settings/utils"
"fmt"
"os"
)

func FixtureConfigurator(dbpath dtypes.Dbpath) Configurator {
func FixtureConfigurator(dbpath types.Dbpath) Configurator {
cfg := NewConfigurator(dbpath)
return cfg
}

func FixtureMigrator(callback func(dbpath dtypes.Dbpath)) Configurator {
func FixtureMigrator(callback func(dbpath types.Dbpath)) Configurator {
dbname := utils.TokenHex(8)
dbpath := dtypes.Dbpath(settings.NewDBPath(dbname))
dbpath := types.Dbpath(settings.NewDBPath(dbname))
// setup
fmt.Println(dbpath)
os.Remove(string(dbpath))
Expand All @@ -34,7 +34,7 @@ func FixtureMigrator(callback func(dbpath dtypes.Dbpath)) Configurator {
return cfg
}

func FixtureChannel(dbpath dtypes.Dbpath) (string, ConfiguratorChannel) {
func FixtureChannel(dbpath types.Dbpath) (string, ConfiguratorChannel) {
channelID := "123"
configurator_ := FixtureConfigurator(dbpath)
cfg_channel := ConfiguratorChannel{Configurator: configurator_}
Expand Down
8 changes: 4 additions & 4 deletions configurator/tags_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package configurator

import (
"darkbot/dtypes"
"darkbot/settings/types"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
)

func TestTags(t *testing.T) {
FixtureMigrator(func(dbname dtypes.Dbpath) {
FixtureMigrator(func(dbname types.Dbpath) {
channelID, _ := FixtureChannel(dbname)

cg := ConfiguratorBase{Configurator: NewConfigurator(dbname).Migrate()}
Expand All @@ -26,7 +26,7 @@ func TestTags(t *testing.T) {
}

func TestCanWriteRepeatedTagsPerChannels(t *testing.T) {
FixtureMigrator(func(dbname dtypes.Dbpath) {
FixtureMigrator(func(dbname types.Dbpath) {
configur := FixtureConfigurator(dbname)
cg := ConfiguratorBase{Configurator: configur}

Expand All @@ -52,7 +52,7 @@ func TestCanWriteRepeatedTagsPerChannels(t *testing.T) {
}

func TestDoNotInputRepeatedTags(t *testing.T) {
FixtureMigrator(func(dbname dtypes.Dbpath) {
FixtureMigrator(func(dbname types.Dbpath) {
configur := FixtureConfigurator(dbname)
cg := ConfiguratorBase{Configurator: configur}

Expand Down
10 changes: 5 additions & 5 deletions consoler/consoler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ package consoler
import (
"darkbot/configurator"
"darkbot/consoler/helper"
"darkbot/dtypes"
"darkbot/settings"
"darkbot/settings/types"
"testing"

"github.com/stretchr/testify/assert"
)

func TestGettingOutput(t *testing.T) {
configurator.FixtureMigrator(func(dbpath dtypes.Dbpath) {
configurator.FixtureMigrator(func(dbpath types.Dbpath) {
channelID, _ := configurator.FixtureChannel(dbpath)
assert.Contains(t, Consoler{}.New(settings.Config.ConsolerPrefix+" ping").Execute(helper.ChannelInfo{ChannelID: channelID, Dbpath: dbpath}).String(), "Pong!")
})
}

func TestGrabStdout(t *testing.T) {
configurator.FixtureMigrator(func(dbpath dtypes.Dbpath) {
configurator.FixtureMigrator(func(dbpath types.Dbpath) {
channelID, _ := configurator.FixtureChannel(dbpath)
c := Consoler{}.New(settings.Config.ConsolerPrefix + " ping --help")
result := c.Execute(helper.ChannelInfo{ChannelID: channelID, Dbpath: dbpath}).String()
Expand All @@ -28,14 +28,14 @@ func TestGrabStdout(t *testing.T) {
}

func TestAddBaseTag(t *testing.T) {
configurator.FixtureMigrator(func(dbpath dtypes.Dbpath) {
configurator.FixtureMigrator(func(dbpath types.Dbpath) {
channelID, _ := configurator.FixtureChannel(dbpath)
assert.Contains(t, Consoler{}.New(settings.Config.ConsolerPrefix+` base add "bla bla" sdf`).Execute(helper.ChannelInfo{ChannelID: channelID, Dbpath: dbpath}).String(), "OK tags are added")
})
}

func TestSystemCommands(t *testing.T) {
configurator.FixtureMigrator(func(dbpath dtypes.Dbpath) {
configurator.FixtureMigrator(func(dbpath types.Dbpath) {
channelID, _ := configurator.FixtureChannel(dbpath)
cons := Consoler{}.New(settings.Config.ConsolerPrefix + ` player --help`)
result := cons.Execute(helper.ChannelInfo{ChannelID: channelID, Dbpath: dbpath}).String()
Expand Down
4 changes: 2 additions & 2 deletions consoler/helper/channelInfo.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package helper

import "darkbot/dtypes"
import "darkbot/settings/types"

type ChannelInfo struct {
ChannelID string
Dbpath dtypes.Dbpath
Dbpath types.Dbpath
}
3 changes: 0 additions & 3 deletions dtypes/dtypes.go

This file was deleted.

11 changes: 5 additions & 6 deletions settings/main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package settings

import (
"darkbot/settings/types"
"darkbot/settings/utils"
"darkbot/settings/utils/logger"
"path/filepath"
"strconv"

"darkbot/dtypes"

"github.com/caarlos0/env/v6"
"github.com/joho/godotenv"
)
Expand Down Expand Up @@ -36,13 +35,13 @@ type ConfigScheme struct {
var LoopDelay int
var Config ConfigScheme

type dbpath dtypes.Dbpath
type dbpath types.Dbpath

var Dbpath dtypes.Dbpath
var Dbpath types.Dbpath
var Workdir string

func NewDBPath(dbname string) dtypes.Dbpath {
return dtypes.Dbpath(filepath.Join(Workdir, "data", dbname+".sqlite3"))
func NewDBPath(dbname string) types.Dbpath {
return types.Dbpath(filepath.Join(Workdir, "data", dbname+".sqlite3"))
}

func load() {
Expand Down
2 changes: 2 additions & 0 deletions settings/types/types.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package types

type LogLevel string

type Dbpath string
4 changes: 2 additions & 2 deletions viewer/apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package apis
import (
"darkbot/configurator"
"darkbot/discorder"
"darkbot/dtypes"
"darkbot/scrappy"
"darkbot/settings/types"
)

type Players struct {
Expand All @@ -31,7 +31,7 @@ type API struct {
Alerts Alerts
}

func NewAPI(channelID string, dbpath dtypes.Dbpath) API {
func NewAPI(channelID string, dbpath types.Dbpath) API {
dbconnection := configurator.NewConfigurator(dbpath)
return API{
Discorder: discorder.NewClient(),
Expand Down
4 changes: 2 additions & 2 deletions viewer/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package viewer

import (
"darkbot/discorder"
"darkbot/dtypes"
"darkbot/settings/types"
"darkbot/settings/utils/logger"
"darkbot/viewer/apis"
"darkbot/viewer/templ"
Expand All @@ -18,7 +18,7 @@ type ChannelView struct {
ChannelID string
}

func NewChannelView(dbpath dtypes.Dbpath) ChannelView {
func NewChannelView(dbpath types.Dbpath) ChannelView {
view := ChannelView{}
view.ChannelID = ""
view.api = apis.NewAPI(view.ChannelID, dbpath)
Expand Down
4 changes: 2 additions & 2 deletions viewer/templ/base.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package templ

import (
"darkbot/dtypes"
"darkbot/scrappy/base"
"darkbot/settings/types"
"darkbot/settings/utils"
"darkbot/viewer/apis"
_ "embed"
Expand Down Expand Up @@ -32,7 +32,7 @@ type TemplateBase struct {
API apis.API
}

func NewTemplateBase(channelID string, dbpath dtypes.Dbpath) TemplateBase {
func NewTemplateBase(channelID string, dbpath types.Dbpath) TemplateBase {
base := TemplateBase{}
base.API = apis.NewAPI(channelID, dbpath)
base.main.Header = "#darkbot-base-view"
Expand Down
10 changes: 5 additions & 5 deletions viewer/templ/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package templ

import (
"darkbot/configurator"
"darkbot/dtypes"
"darkbot/scrappy"
"darkbot/scrappy/base"
"darkbot/scrappy/baseattack"
"darkbot/scrappy/player"
"darkbot/scrappy/shared/records"
"darkbot/settings/types"
"darkbot/settings/utils/logger"
"darkbot/viewer/apis"
"fmt"
Expand All @@ -19,7 +19,7 @@ import (
)

func TestBaseViewerMocked(t *testing.T) {
configurator.FixtureMigrator(func(dbpath dtypes.Dbpath) {
configurator.FixtureMigrator(func(dbpath types.Dbpath) {
channelID, _ := configurator.FixtureChannel(dbpath)

cg := configurator.ConfiguratorBase{Configurator: configurator.NewConfigurator(dbpath)}
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestBaseViewerMocked(t *testing.T) {

// TODO fix those tests... for some reason memory ref error :smile:
// func TestBaseViewerRealData(t *testing.T) {
// configurator.FixtureMigrator(func(dbpath dtypes.Dbpath) {
// configurator.FixtureMigrator(func(dbpath types.Dbpath) {
// channelID, _ := configurator.FixtureChannel(dbpath)

// cg := configurator.ConfiguratorBase{Configurator: configurator.NewConfigurator(dbpath)}
Expand All @@ -131,7 +131,7 @@ func TestBaseViewerMocked(t *testing.T) {

// TEST TO FIND OUT derivative of base health
func TestGetDerivative(t *testing.T) {
configurator.FixtureMigrator(func(dbpath dtypes.Dbpath) {
configurator.FixtureMigrator(func(dbpath types.Dbpath) {
logger.Debug("1")
channelID, _ := configurator.FixtureChannel(dbpath)
api := apis.NewAPI(channelID, dbpath)
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestGetDerivative(t *testing.T) {

func TestDetectAttackOnLPBase(t *testing.T) {

configurator.FixtureMigrator(func(dbpath dtypes.Dbpath) {
configurator.FixtureMigrator(func(dbpath types.Dbpath) {
channelID, _ := configurator.FixtureChannel(dbpath)

cg := configurator.ConfiguratorBase{Configurator: configurator.NewConfigurator(dbpath)}
Expand Down
4 changes: 2 additions & 2 deletions viewer/templ/player.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package templ

import (
"darkbot/dtypes"
"darkbot/scrappy/player"
"darkbot/settings/types"
"darkbot/settings/utils"
"darkbot/settings/utils/logger"
"darkbot/viewer/apis"
Expand Down Expand Up @@ -42,7 +42,7 @@ type PlayersTemplates struct {
API apis.API
}

func NewTemplatePlayers(channelID string, dbpath dtypes.Dbpath) PlayersTemplates {
func NewTemplatePlayers(channelID string, dbpath types.Dbpath) PlayersTemplates {
templator := PlayersTemplates{}
templator.API = apis.NewAPI(channelID, dbpath)
templator.friends.MainTable.Header = "#darkbot-players-friends-table"
Expand Down
6 changes: 3 additions & 3 deletions viewer/templ/player_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ package templ

import (
"darkbot/configurator"
"darkbot/dtypes"
"darkbot/scrappy"
"darkbot/scrappy/player"
"darkbot/scrappy/shared/records"
"darkbot/settings/types"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
)

func TestPlayerViewerMadeUpData(t *testing.T) {
configurator.FixtureMigrator(func(dbpath dtypes.Dbpath) {
configurator.FixtureMigrator(func(dbpath types.Dbpath) {
channelID, _ := configurator.FixtureChannel(dbpath)

configurator.ConfiguratorRegion{Configurator: configurator.NewConfigurator(dbpath)}.TagsAdd(channelID, []string{"region1", "region0"}...)
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestPlayerViewerMadeUpData(t *testing.T) {

// TODO fix those tests... for some reason memory ref error :smile:
// func TestPlayerViewerRealData(t *testing.T) {
// configurator.FixtureMigrator(func(dbpath dtypes.Dbpath) {
// configurator.FixtureMigrator(func(dbpath types.Dbpath) {
// channelID, _ := configurator.FixtureChannel(dbpath)

// scrappy.Storage.BaseStorage.Api = base.APIBasespy{}
Expand Down
Loading

0 comments on commit 497fc64

Please sign in to comment.