package config import ( "path/filepath" "testing" "chub/internal/domain" ) func TestStoreRoundTripAndCreatesPrivateFile(t *testing.T) { path := filepath.Join(t.TempDir(), "nested", "config.json") store, err := New(path) if err != nil { t.Fatal(err) } want := File{Settings: Settings{ChromePath: "chrome.exe", CloseOnExit: true}, Instances: []Instance{{ID: "a", Name: "运营", Launch: domain.LaunchSpec{Kind: domain.BrowserChrome, UserDataDir: `C:\profiles\a`}}}} if err := store.Save(want); err != nil { t.Fatal(err) } got, err := store.Load() if err != nil { t.Fatal(err) } if got.Version != currentVersion || got.Settings != want.Settings || len(got.Instances) != 1 || got.Instances[0].ID != "a" { t.Fatalf("round trip mismatch: %#v", got) } } func TestStoreMissingFileReturnsDefaults(t *testing.T) { store, err := New(filepath.Join(t.TempDir(), "config.json")) if err != nil { t.Fatal(err) } got, err := store.Load() if err != nil { t.Fatal(err) } if got.Version != currentVersion || len(got.Instances) != 0 { t.Fatalf("unexpected defaults: %#v", got) } }