Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
et-nik committed Feb 14, 2024
1 parent 70708df commit 337f89d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
11 changes: 3 additions & 8 deletions internal/processmanager/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,11 @@ func (pm *Simple) SendInput(
func (pm *Simple) execCommand(
ctx context.Context, server *domain.Server, command string, out io.Writer,
) (domain.Result, error) {
options, err := pm.executeOptions(server)
if err != nil {
return domain.ErrorResult, errors.WithMessage(err, "invalid server configuration")
}

result, err := pm.executor.ExecWithWriter(
ctx,
command,
out,
options,
pm.executeOptions(server),
)
if err != nil {
return domain.ErrorResult, errors.WithMessage(err, "failed to exec command")
Expand All @@ -109,9 +104,9 @@ func (pm *Simple) execCommand(
return domain.Result(result), nil
}

func (pm *Simple) executeOptions(server *domain.Server) (contracts.ExecutorOptions, error) {
func (pm *Simple) executeOptions(server *domain.Server) contracts.ExecutorOptions {
return contracts.ExecutorOptions{
WorkDir: server.WorkDir(pm.cfg),
FallbackWorkDir: pm.cfg.WorkDir(),
}, nil
}
}
4 changes: 4 additions & 0 deletions test/functional/gdtasks/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
gameservercommands "github.com/gameap/daemon/internal/app/game_server_commands"
gdaemonscheduler "github.com/gameap/daemon/internal/app/gdaemon_scheduler"
"github.com/gameap/daemon/internal/app/services"
"github.com/gameap/daemon/internal/processmanager"
"github.com/gameap/daemon/test/functional"
"github.com/gameap/daemon/test/mocks"
)
Expand All @@ -28,6 +29,7 @@ type Suite struct {
GDTaskRepository *mocks.GDTaskRepository
ServerRepository *mocks.ServerRepository
Executor contracts.Executor
ProcessManager contracts.ProcessManager
Cache contracts.Cache
Cfg *config.Config

Expand All @@ -42,6 +44,7 @@ func (suite *Suite) SetupTest() {
suite.Cfg,
suite.ServerRepository,
suite.Executor,
suite.ProcessManager,
),
suite.Executor,
suite.Cfg,
Expand All @@ -62,6 +65,7 @@ func (suite *Suite) SetupSuite() {
}

suite.Executor = components.NewDefaultExtendableExecutor(suite.Cfg)
suite.ProcessManager = processmanager.NewSimple(suite.Cfg, suite.Executor)

suite.Cache, err = services.NewLocalCache(suite.Cfg)
if err != nil {
Expand Down
12 changes: 8 additions & 4 deletions test/functional/server_tasks/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/gameap/daemon/internal/app/domain"
gameservercommands "github.com/gameap/daemon/internal/app/game_server_commands"
serversscheduler "github.com/gameap/daemon/internal/app/servers_scheduler"
"github.com/gameap/daemon/internal/processmanager"
"github.com/gameap/daemon/test/functional"
"github.com/gameap/daemon/test/mocks"
"github.com/otiai10/copy"
Expand All @@ -25,6 +26,7 @@ type Suite struct {
ServerTaskRepository *mocks.ServerTaskRepository
ServerRepository *mocks.ServerRepository
Executor contracts.Executor
ProcessManager contracts.ProcessManager
Cfg *config.Config

WorkPath string
Expand All @@ -35,16 +37,17 @@ func TestSuite(t *testing.T) {
}

func (suite *Suite) SetupSuite() {
suite.ServerRepository = mocks.NewServerRepository()
suite.ServerTaskRepository = mocks.NewServerTaskRepository()
suite.Executor = components.NewExecutor()

suite.Cfg = &config.Config{
Scripts: config.Scripts{
Start: "{command}",
Stop: "{command}",
},
}

suite.ServerRepository = mocks.NewServerRepository()
suite.ServerTaskRepository = mocks.NewServerTaskRepository()
suite.Executor = components.NewExecutor()
suite.ProcessManager = processmanager.NewSimple(suite.Cfg, suite.Executor)
}

func (suite *Suite) SetupTest() {
Expand All @@ -60,6 +63,7 @@ func (suite *Suite) SetupTest() {
suite.Cfg,
suite.ServerRepository,
suite.Executor,
suite.ProcessManager,
),
)

Expand Down
5 changes: 4 additions & 1 deletion test/functional/serverscommand/notinstalled_server_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/gameap/daemon/internal/app/contracts"
"github.com/gameap/daemon/internal/app/domain"
gameservercommands "github.com/gameap/daemon/internal/app/game_server_commands"
"github.com/gameap/daemon/internal/processmanager"
"github.com/gameap/daemon/test/functional"
"github.com/gameap/daemon/test/mocks"
)
Expand All @@ -19,6 +20,7 @@ type NotInstalledServerSuite struct {
Cfg *config.Config
ServerRepository domain.ServerRepository
Executor contracts.Executor
ProcessManager contracts.ProcessManager
WorkPath string
}

Expand All @@ -32,8 +34,9 @@ func (suite *NotInstalledServerSuite) SetupSuite() {

suite.ServerRepository = mocks.NewServerRepository()
suite.Executor = components.NewCleanExecutor()
suite.ProcessManager = processmanager.NewSimple(suite.Cfg, suite.Executor)

suite.CommandFactory = gameservercommands.NewFactory(suite.Cfg, suite.ServerRepository, suite.Executor)
suite.CommandFactory = gameservercommands.NewFactory(suite.Cfg, suite.ServerRepository, suite.Executor, suite.ProcessManager)
}

func (suite *NotInstalledServerSuite) SetupTest() {
Expand Down

0 comments on commit 337f89d

Please sign in to comment.