Adapt Intel VM suspend/resume to driver.SuspendDriver and lifecycle.Service, move native VM close confirmation into internal/host, migrate vm-suspend legacy capability detection, drop moved runtime build tooling, and regenerate i18n and Wails bindings.
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package startprep
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/Nwflower/reims-go/internal/qmp"
|
|
)
|
|
|
|
func TestForceStopDoesNotWaitForVMInspectionOrLock(t *testing.T) {
|
|
// A forced stop must not ask reims-ctl to show the VM before it can
|
|
// invoke stop --force. A stalled owner may also be holding its lock.
|
|
release, err := LockVMForStop(context.Background(), nil, "stalled", true)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
release()
|
|
}
|
|
|
|
func TestCleanupSuspendAttempt(t *testing.T) {
|
|
for _, tt := range []struct {
|
|
name string
|
|
err error
|
|
keep bool
|
|
}{
|
|
{"migration failed", fmt.Errorf("%w: disk full", qmp.ErrIncompleteSuspend), false},
|
|
{"seal failed", errors.New("could not publish suspend metadata"), true},
|
|
{"unknown outcome", errors.New("connection closed"), true},
|
|
} {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
tmp := filepath.Join(t.TempDir(), "suspend.vmstate.tmp")
|
|
if err := os.WriteFile(tmp, []byte("snapshot data"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := cleanupSuspendAttempt(tmp, tt.err); !errors.Is(err, tt.err) {
|
|
t.Fatalf("cleanup lost the save error: %v", err)
|
|
}
|
|
_, err := os.Stat(tmp)
|
|
if tt.keep && err != nil || !tt.keep && !os.IsNotExist(err) {
|
|
t.Fatalf("stat after cleanup = %v, want keep=%t", err, tt.keep)
|
|
}
|
|
})
|
|
}
|
|
}
|