49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package app
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/Nwflower/reims-go/internal/config"
|
|
)
|
|
|
|
func TestRuntimeConfigFollowsExternalSelection(t *testing.T) {
|
|
dir := t.TempDir()
|
|
a := &App{cfg: &config.Config{DataRoot: dir, ActiveRuntime: "current"}}
|
|
stored := *a.cfg
|
|
stored.ActiveRuntime, stored.QEMUASLR = "backup", true
|
|
if err := config.Save("", &stored); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := a.runtimeConfig()
|
|
if got.ActiveRuntime != "backup" || !got.QEMUASLR {
|
|
t.Fatalf("desktop reads stale selection: %+v", got)
|
|
}
|
|
if err := a.SetSyncHostMemorySMBIOS(true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
saved, err := config.LoadExisting(filepath.Join(dir, "reims-go.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if saved.ActiveRuntime != "backup" || !saved.QEMUASLR || !saved.SyncHostMemorySMBIOS {
|
|
t.Fatalf("saving an unrelated setting lost the selection: %+v", saved)
|
|
}
|
|
}
|
|
|
|
func TestPreferencesDoNotOverwriteDamagedConfig(t *testing.T) {
|
|
dir := t.TempDir()
|
|
a := &App{cfg: &config.Config{DataRoot: dir}}
|
|
path := filepath.Join(dir, "reims-go.json")
|
|
if err := os.WriteFile(path, []byte("{"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.SetSyncHostMemorySMBIOS(true); err == nil {
|
|
t.Fatal("saved preferences over an unreadable selection")
|
|
}
|
|
if data, err := os.ReadFile(path); err != nil || string(data) != "{" {
|
|
t.Fatalf("damaged config replaced: %q, %v", data, err)
|
|
}
|
|
}
|