60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/Nwflower/reims-go/internal/config"
|
|
"github.com/Nwflower/reims-go/internal/driver"
|
|
"github.com/Nwflower/reims-go/internal/i18n"
|
|
)
|
|
|
|
func TestStambhaCLIUsesPreviewMediaWithoutAnIntelRuntime(t *testing.T) {
|
|
if runtime.GOOS != "windows" || runtime.GOARCH != "amd64" {
|
|
t.Skip("the built-in Stambha driver runs on Windows x86-64")
|
|
}
|
|
dir := t.TempDir()
|
|
cfg := &config.Config{DataRoot: filepath.Join(dir, "data-root")}
|
|
boot := filepath.Join(dir, "boot")
|
|
bootConfig := filepath.Join(boot, "EFI", "stela", "stela.cfg")
|
|
if err := os.MkdirAll(filepath.Dir(bootConfig), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(bootConfig, []byte("--system\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
disk := filepath.Join(dir, "system.qcow2")
|
|
if err := os.WriteFile(disk, []byte("fixture"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ctx := context.Background()
|
|
args := []string{"--driver", driver.BuiltinStambhaDriverID, "--boot-volume", boot, "--disk", disk, "arm"}
|
|
if err := vmCreate(ctx, cfg, i18n.Detect(), args, false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
args = []string{"--driver", driver.BuiltinStambhaDriverID, "--hosted-gpu=false", "--headless", "arm"}
|
|
if err := vmSet(ctx, cfg, args); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
raw, err := os.ReadFile(filepath.Join(cfg.XDGDataDir(), "stambha", "vms", "arm", "stambha.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var profile struct {
|
|
Disk string `json:"raw_disk"`
|
|
Display bool `json:"display"`
|
|
HostedGPU bool `json:"hosted_gpu"`
|
|
Accelerator string `json:"accelerator"`
|
|
}
|
|
if err := json.Unmarshal(raw, &profile); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if profile.Disk != disk || profile.Display || profile.HostedGPU || profile.Accelerator != "whpx" {
|
|
t.Fatalf("unexpected preview profile %+v", profile)
|
|
}
|
|
}
|