init
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
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 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"}}
|
||||
}
|
||||
Reference in New Issue
Block a user