Files
browser/platform/service/scum_deployment_test.go

57 lines
2.9 KiB
Go

package service
import (
"testing"
"browser.local/platform/domain"
)
func scumDeploymentTestPlugin() domain.GamePlugin {
return domain.GamePlugin{
ID: "game.scum",
CreateFields: []domain.PluginCreateField{
{Key: "serverName", Type: "text", DefaultValue: "SCUM Test"},
{Key: "gamePort", Type: "port", DefaultValue: "7779"},
{Key: "queryPort", Type: "port", DefaultValue: "27015"},
{Key: "maxPlayers", Type: "number", DefaultValue: "128"},
},
}
}
func requireManualSCUMRuntimeBindings(plugin *domain.GamePlugin, profileKey string) {
plugin.RuntimeProfiles.Discovery = []domain.RuntimeDiscoveryProbe{
{Key: "steamcmd", Kind: "command.version", TargetKey: "steamcmd", Required: true},
{Key: "scum-install", Kind: "file.exists", TargetKey: "server/install-root", Required: true, Platforms: []string{"windows"}},
}
plugin.RuntimeProfiles.DependencyProbes = []domain.RuntimeDependencyProbe{{Key: "steamcmd", Kind: "command.version", TargetKey: "steamcmd", Required: true, Platforms: []string{"windows"}}}
plugin.RuntimeProfiles.LogSources = []domain.RuntimeLogSource{
{Key: "scum-console-stdout", Kind: "process.stdout", TargetKey: "scum/server-process", StreamKey: "scum.console.stdout", CursorKind: "sequence", RetentionDays: 30},
{Key: "scum-server-events", Kind: "file.tail", TargetKey: "logs/server", StreamKey: "scum.server", CursorKind: "fingerprint", RetentionDays: 90},
}
plugin.RuntimeProfiles.TransportProfiles = []domain.RuntimeTransportProfile{{Key: "server-files", Kind: "file", TargetKey: "server-root", Capabilities: []string{domain.JobCapabilityRemoteRunFilesRead, domain.JobCapabilityRemoteRunFilesWrite}}}
for i := range plugin.RuntimeProfiles.LifecycleProfiles {
if plugin.RuntimeProfiles.LifecycleProfiles[i].Key == profileKey {
plugin.RuntimeProfiles.LifecycleProfiles[i].TransportKeys = []string{"server-files"}
}
}
}
func TestApplyPluginCreateDefaultsUsesPluginFields(t *testing.T) {
plugin := scumDeploymentTestPlugin()
definition := applyPluginCreateDefaults(plugin, domain.ServerDeploymentDefinition{Mode: domain.ServerDeploymentModeGuided, CreateInputs: map[string]string{"serverName": "Moon"}})
if definition.CreateInputs["serverName"] != "Moon" || definition.CreateInputs["gamePort"] != "7779" || definition.CreateInputs["queryPort"] != "27015" || definition.CreateInputs["maxPlayers"] != "128" {
t.Fatalf("expected plugin defaults to fill missing guided inputs: %+v", definition.CreateInputs)
}
}
func TestDeploymentDefinitionsUsePluginOwnedLifecycleWithoutRuntimeBinding(t *testing.T) {
plugin := scumDeploymentTestPlugin()
if deploymentNeedsCompleteRuntimeBinding(plugin, domain.ServerDeploymentDefinition{Mode: domain.ServerDeploymentModeGuided}) {
t.Fatal("guided plugin-owned lifecycle should not require a complete runtime binding")
}
if !deploymentNeedsCompleteRuntimeBinding(plugin, domain.ServerDeploymentDefinition{}) {
t.Fatal("non-deployment runtime lifecycle still requires a complete runtime binding")
}
}