| 1 | package vm |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "os" |
| 6 | "path/filepath" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | |
| 10 | "github.com/lima-vm/lima/v2/pkg/limatype/dirnames" |
| 11 | "github.com/sylvinus/agent-vm/internal/cage" |
| 12 | ) |
| 13 | |
| 14 | func TestStorageMoveKeepsLimaIdentityAndSocketPaths(t *testing.T) { |
| 15 | root, err := filepath.EvalSymlinks(t.TempDir()) |
| 16 | if err != nil { |
| 17 | t.Fatal(err) |
| 18 | } |
| 19 | profile := filepath.Join(root, "profile") |
| 20 | home := filepath.Join(profile, "state", "lima") |
| 21 | if err := os.MkdirAll(filepath.Join(home, "guest"), 0700); err != nil { |
| 22 | t.Fatal(err) |
| 23 | } |
| 24 | t.Setenv("LIMA_HOME", home) |
| 25 | t.Setenv("CAGE_LOGICAL_LIMA_HOME", "") |
| 26 | before, err := dirnames.InstanceDir("guest") |
| 27 | if err != nil { |
| 28 | t.Fatal(err) |
| 29 | } |
| 30 | limit := MaxName(home) |
| 31 | expected, err := cage.GetStorageLocation(profile) |
| 32 | if err != nil { |
| 33 | t.Fatal(err) |
| 34 | } |
| 35 | target := filepath.Join(root, strings.Repeat("physical-path-", 4)) |
| 36 | if _, err := cage.MoveStorage(context.Background(), profile, target, expected, nil); err != nil { |
| 37 | t.Fatal(err) |
| 38 | } |
| 39 | t.Setenv("CAGE_LOGICAL_LIMA_HOME", home) |
| 40 | after, err := dirnames.InstanceDir("guest") |
| 41 | if err != nil { |
| 42 | t.Fatal(err) |
| 43 | } |
| 44 | if after != before || MaxName(home) != limit { |
| 45 | t.Fatalf("migration changed the instance path/name limit: before %s/%d, after %s/%d", before, limit, after, MaxName(home)) |
| 46 | } |
| 47 | } |