49 lines
3.0 KiB
Go
49 lines
3.0 KiB
Go
package protocol
|
|
|
|
import "testing"
|
|
|
|
func TestValidateRunAutonomousLifecyclePlanAllowsSQLiteSnapshotDataTarget(t *testing.T) {
|
|
plan := validAutonomousLifecyclePlanForTest()
|
|
plan.DataTargets = []RunAutonomousDataTarget{{Key: "world-db", Kind: "sqlite.snapshot", TransportKey: "world-db", SourceRootKey: "server-root", SourcePath: "Saved/SaveFiles/world.db", WorkspaceKey: "databases/world-db", RefreshPolicy: "on-demand-snapshot", MaxBytes: 128 * 1024 * 1024, Platforms: []string{"windows"}}}
|
|
|
|
if err := ValidateRunAutonomousLifecyclePlan(plan); err != nil {
|
|
t.Fatalf("expected valid data target plan: %v", err)
|
|
}
|
|
|
|
plan.DataTargets[0].WorkspaceKey = "state/world-db"
|
|
if err := ValidateRunAutonomousLifecyclePlan(plan); err == nil {
|
|
t.Fatal("expected non-database workspace target to be rejected")
|
|
}
|
|
}
|
|
|
|
func TestValidateRunAutonomousLifecyclePlanRejectsUnsafeDataTargets(t *testing.T) {
|
|
for name, mutate := range map[string]func(*RunAutonomousDataTarget){
|
|
"kind": func(target *RunAutonomousDataTarget) { target.Kind = "scum.sqlite" },
|
|
"source-path": func(target *RunAutonomousDataTarget) { target.SourcePath = "../current.db" },
|
|
"refresh-policy": func(target *RunAutonomousDataTarget) { target.RefreshPolicy = "startup" },
|
|
"max-bytes": func(target *RunAutonomousDataTarget) { target.MaxBytes = maxAutonomousDataTargetBytes + 1 },
|
|
"platform": func(target *RunAutonomousDataTarget) { target.Platforms = []string{"plan9"} },
|
|
} {
|
|
plan := validAutonomousLifecyclePlanForTest()
|
|
target := RunAutonomousDataTarget{Key: "world-db", Kind: "sqlite.snapshot", TransportKey: "world-db", SourceRootKey: "server-root", SourcePath: "Saved/SaveFiles/world.db", WorkspaceKey: "databases/world-db", RefreshPolicy: "on-demand-snapshot", MaxBytes: 128 * 1024 * 1024, Platforms: []string{"windows"}}
|
|
mutate(&target)
|
|
plan.DataTargets = []RunAutonomousDataTarget{target}
|
|
if err := ValidateRunAutonomousLifecyclePlan(plan); err == nil {
|
|
t.Fatalf("expected invalid data target %s to be rejected", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestValidateRunAutonomousLifecyclePlanRejectsLegacySteamCMDAppStep(t *testing.T) {
|
|
plan := validAutonomousLifecyclePlanForTest()
|
|
plan.InstallPlans = []DependencyInstallPlan{{Key: "install-game", Title: "Install game", Steps: []DependencyInstallStep{{Type: "steamcmd-app", TargetKey: "server/install-root", PackageManager: "steamcmd", PackageName: "123456"}}}}
|
|
|
|
if err := ValidateRunAutonomousLifecyclePlan(plan); err == nil {
|
|
t.Fatal("expected legacy steamcmd-app install step to be rejected")
|
|
}
|
|
}
|
|
|
|
func validAutonomousLifecyclePlanForTest() RunAutonomousLifecyclePlan {
|
|
return RunAutonomousLifecyclePlan{SchemaVersion: "1", ServerInstanceID: "server-1", PluginID: "game.example", PluginVersion: "1.0.0", RunEndpointID: "run-1", ProfileKey: "run-local", TargetOS: "windows", TargetArch: "amd64", TargetRelease: "release-1", Bootstrap: &RunAutonomousLifecycleAction{Action: "start", Operation: "start", Capability: RunCapabilityProcessStart, TargetKey: "actions/start.json"}}
|
|
}
|