| 1 | package workbench |
| 2 | |
| 3 | import ( |
| 4 | "github.com/google/uuid" |
| 5 | "github.com/sylvinus/agent-vm/internal/guestos" |
| 6 | "net/http" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | func TestUnsupportedGuestSystemCannotStartDebian(t *testing.T) { |
| 12 | s := testServer(t) |
| 13 | for _, system := range []string{"macos", "windows-11", "debian-12", "ubuntu-22.04", "ubuntu-24.04", "unknown"} { |
| 14 | response := request(s, http.MethodPost, "/api/start", s.origin, `{"guest_system":"`+system+`"}`, true) |
| 15 | if response.Code != http.StatusConflict || s.jobs.snapshot().ID != "" { |
| 16 | t.Fatalf("%s: got %d, job %v", system, response.Code, s.jobs.snapshot()) |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | func TestIncompleteInstallationPreventsImplicitLinuxStart(t *testing.T) { |
| 22 | s := testServer(t) |
| 23 | if err := guestos.SaveInstallation(s.profile, guestos.Installation{Version: 1, System: guestos.MacOS, ID: uuid.New()}); err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | for _, body := range []string{"{}", `{"guest_system":"debian-13"}`} { |
| 27 | w := request(s, "POST", "/api/start", s.origin, body, true) |
| 28 | if w.Code != http.StatusConflict || s.jobs.snapshot().ID != "" { |
| 29 | t.Fatalf("created a Linux job from pending macOS (%s): %d", body, w.Code) |
| 30 | } |
| 31 | } |
| 32 | if err := s.startEnvironment(false); err == nil || !strings.Contains(err.Error(), "原生客户机") { |
| 33 | t.Fatalf("indirect Linux start: %v", err) |
| 34 | } |
| 35 | } |