feat: migrate config beside executable

This commit is contained in:
QiuSW
2026-07-27 11:33:22 +08:00
parent 206794f78c
commit eeb7950806
9 changed files with 307 additions and 42 deletions
+28
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"errors"
"path/filepath"
"strings"
"testing"
"time"
@@ -21,6 +22,33 @@ func TestRunCLIRejectsUnknownCommandWithStableCode(t *testing.T) {
}
}
func TestRunCLIUsesPortableDefaultStore(t *testing.T) {
store, err := config.New(filepath.Join(t.TempDir(), "config.json"))
if err != nil {
t.Fatal(err)
}
if err := store.Save(config.File{Instances: []config.Instance{{ID: "portable", Name: "便携实例", PreferredRemoteDebugPort: 9666}}}); err != nil {
t.Fatal(err)
}
restore := openDefaultConfig
openDefaultConfig = func() (*config.Store, error) { return store, nil }
t.Cleanup(func() { openDefaultConfig = restore })
var out bytes.Buffer
if code := runCLI([]string{"list"}, &out, &out); code != 0 || !strings.Contains(out.String(), `"portable"`) {
t.Fatalf("code=%d output=%s", code, out.String())
}
}
func TestRunCLIReportsUnavailablePortableConfigWithoutDetails(t *testing.T) {
restore := openDefaultConfig
openDefaultConfig = func() (*config.Store, error) { return nil, config.ErrDefaultConfigUnavailable }
t.Cleanup(func() { openDefaultConfig = restore })
var out bytes.Buffer
if code := runCLI([]string{"list"}, &out, &out); code != 6 || !strings.Contains(out.String(), `"default configuration is unavailable"`) {
t.Fatalf("code=%d output=%s", code, out.String())
}
}
func TestInstanceStarterBuildsLaunchSpecFromInstanceAndSettings(t *testing.T) {
launcher := &fakeProcessLauncher{handle: fakeProcessHandle{pid: 4242}}
resolver := &fakeExecutableResolver{path: `C:\Browser\msedge.exe`}