fix: delete instance data and remove legacy shared workspace support
This commit is contained in:
@@ -23,10 +23,10 @@ func TestUpgradeWorkspaceCompatibility(t *testing.T) {
|
||||
name, recipe, target string
|
||||
shared, reject bool
|
||||
}{
|
||||
{"legacy-to-seven", "7", "/data/dsh-home", true, false},
|
||||
{"legacy-to-seven", "7", "/data/dsh-home", true, true},
|
||||
{"single-to-seven", "7", "/workspace", false, false},
|
||||
{"migrated-to-seven", "7", "/workspace", true, false},
|
||||
{"legacy-to-six", "6", "/data/dsh-home", true, false},
|
||||
{"migrated-to-seven", "7", "/workspace", true, true},
|
||||
{"legacy-to-six", "6", "/data/dsh-home", true, true},
|
||||
{"legacy-to-unknown", "", "/data/dsh-home", true, true},
|
||||
{"single-to-six", "6", "/workspace", false, true},
|
||||
{"single-to-unknown", "", "/workspace", false, true},
|
||||
@@ -44,16 +44,10 @@ func TestUpgradeWorkspaceCompatibility(t *testing.T) {
|
||||
host := map[string]json.RawMessage{"Mounts": raw}
|
||||
config := map[string]json.RawMessage{"Env": json.RawMessage(`["CUSTOM=yes","DSH_HOME=/data/dsh-home","HOME=/data/dsh-home","XDG_DATA_HOME=/old/data","XDG_CONFIG_HOME=/old/config"]`)}
|
||||
before := string(config["Env"])
|
||||
err := upgradeWorkspace(config, host, tc.recipe, "/instance/home", "/user/files")
|
||||
err := upgradeWorkspace(config, host, tc.recipe, "/instance/home")
|
||||
if (err != nil) != tc.reject {
|
||||
t.Fatalf("error=%v", err)
|
||||
}
|
||||
if !tc.reject && tc.recipe != "7" {
|
||||
if !strings.Contains(string(config["Env"]), "XDG_DATA_HOME=/data/dsh-home/.local/share") || string(host["Mounts"]) != string(raw) {
|
||||
t.Fatal(config, host)
|
||||
}
|
||||
return
|
||||
}
|
||||
if tc.reject {
|
||||
if string(host["Mounts"]) != string(raw) || string(config["Env"]) != before {
|
||||
t.Fatal("legacy or rejected config changed")
|
||||
@@ -71,7 +65,7 @@ func TestUpgradeWorkspaceCompatibility(t *testing.T) {
|
||||
t.Fatal(got)
|
||||
}
|
||||
first, _ := json.Marshal([]any{config, host})
|
||||
if err := upgradeWorkspace(config, host, tc.recipe, "/instance/home", "/user/files"); err != nil {
|
||||
if err := upgradeWorkspace(config, host, tc.recipe, "/instance/home"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
second, _ := json.Marshal([]any{config, host})
|
||||
@@ -90,9 +84,9 @@ func TestUpgradeWorkspaceRejectsAmbiguousMounts(t *testing.T) {
|
||||
`{"Type":"bind","Source":"/instance/home","Target":"/workspace"}`,
|
||||
} {
|
||||
config := map[string]json.RawMessage{"Env": json.RawMessage(`["CUSTOM=yes"]`)}
|
||||
host := map[string]json.RawMessage{"Mounts": json.RawMessage(`[{"Type":"bind","Source":"/instance/home","Target":"/data/dsh-home"},` + extra + `]`)}
|
||||
host := map[string]json.RawMessage{"Mounts": json.RawMessage(`[{"Type":"bind","Source":"/instance/home","Target":"/workspace"},` + extra + `]`)}
|
||||
before, _ := json.Marshal([]any{config, host})
|
||||
if err := upgradeWorkspace(config, host, "7", "/instance/home", "/user/files"); err == nil {
|
||||
if err := upgradeWorkspace(config, host, "7", "/instance/home"); err == nil {
|
||||
t.Fatal("accepted ambiguous mounts", extra)
|
||||
}
|
||||
after, _ := json.Marshal([]any{config, host})
|
||||
@@ -106,7 +100,7 @@ func TestUpgradeLifecycle(t *testing.T) {
|
||||
if os.Geteuid() != 0 {
|
||||
t.Skip("requires chown")
|
||||
}
|
||||
for _, mode := range []string{"success", "start-failure", "readiness-failure", "cleanup-failure", "running", "running-failure", "restart-failure", "delete-failure", "invalid-image", "unverified-image", "failed-build", "version-mismatch", "image-id-mismatch", "db-failure"} {
|
||||
for _, mode := range []string{"success", "legacy-layout", "shared-layout", "start-failure", "readiness-failure", "cleanup-failure", "running", "running-failure", "restart-failure", "delete-failure", "invalid-image", "unverified-image", "failed-build", "version-mismatch", "image-id-mismatch", "db-failure"} {
|
||||
t.Run(mode, func(t *testing.T) {
|
||||
image := "sha256:" + strings.Repeat("b", 64)
|
||||
var a *API
|
||||
@@ -149,7 +143,15 @@ func TestUpgradeLifecycle(t *testing.T) {
|
||||
if running {
|
||||
state = "running"
|
||||
}
|
||||
writeJSON(w, map[string]any{"Config": map[string]any{"Hostname": "old", "Cmd": []string{"obsolete-flag"}, "Image": "old-image", "Env": []string{"CUSTOM=yes"}, "User": "1000:1000"}, "HostConfig": map[string]any{"NetworkMode": "dsh-inst-one", "Memory": 9007199254740993, "Mounts": []map[string]string{{"Type": "bind", "Source": home, "Target": "/data/dsh-home"}, {"Type": "bind", "Source": shared, "Target": "/workspace"}}}, "State": map[string]any{"Status": state, "Running": running && !stopped}, "NetworkSettings": map[string]any{"Networks": map[string]any{"dsh-inst-one": map[string]any{"IPAddress": "172.18.0.3", "Aliases": []string{"old"}}}}})
|
||||
mounts := []map[string]string{{"Type": "bind", "Source": home, "Target": "/workspace"}}
|
||||
if mode == "legacy-layout" {
|
||||
mounts[0]["Target"] = "/data/dsh-home"
|
||||
mounts = append(mounts, map[string]string{"Type": "bind", "Source": shared, "Target": "/workspace"})
|
||||
}
|
||||
if mode == "shared-layout" {
|
||||
mounts = append(mounts, map[string]string{"Type": "bind", "Source": shared, "Target": "/shared"})
|
||||
}
|
||||
writeJSON(w, map[string]any{"Config": map[string]any{"Hostname": "old", "Cmd": []string{"obsolete-flag"}, "Image": "old-image", "Env": []string{"CUSTOM=yes"}, "User": "1000:1000"}, "HostConfig": map[string]any{"NetworkMode": "dsh-inst-one", "Memory": 9007199254740993, "Mounts": mounts}, "State": map[string]any{"Status": state, "Running": running && !stopped}, "NetworkSettings": map[string]any{"Networks": map[string]any{"dsh-inst-one": map[string]any{"IPAddress": "172.18.0.3", "Aliases": []string{"old"}}}}})
|
||||
case strings.HasPrefix(p, "/images/"):
|
||||
role := "runtime"
|
||||
if mode == "invalid-image" {
|
||||
@@ -273,8 +275,11 @@ func TestUpgradeLifecycle(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if mode == "invalid-image" || mode == "unverified-image" || mode == "failed-build" || mode == "version-mismatch" || mode == "image-id-mismatch" {
|
||||
if mode == "legacy-layout" || mode == "shared-layout" || mode == "invalid-image" || mode == "unverified-image" || mode == "failed-build" || mode == "version-mismatch" || mode == "image-id-mismatch" {
|
||||
want := 400
|
||||
if mode == "legacy-layout" || mode == "shared-layout" {
|
||||
want = 409
|
||||
}
|
||||
if w.Code != want {
|
||||
t.Fatalf("%d %s", w.Code, w.Body.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user