feat: add diagnostics and safe reset maintenance
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package profile_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"proxyctl/internal/profile"
|
||||
)
|
||||
|
||||
func TestReadOnlyLoadValidatesWithoutRepairingOrCreatingStorage(t *testing.T) {
|
||||
directory := filepath.Join(t.TempDir(), "proxyctl")
|
||||
if err := os.MkdirAll(directory, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
path := filepath.Join(directory, "profiles.json")
|
||||
if err := os.WriteFile(path, []byte(`{"profiles":[{"name":"office","mode":"single","singleUrl":"http://proxy.test:8080","httpUrl":"http://proxy.test:8080","httpsUrl":"http://proxy.test:8080","allUrl":"http://proxy.test:8080"}],"activeProfile":"office"}`), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store := profile.NewFileStore(path)
|
||||
state, err := store.ReadOnlyLoad()
|
||||
if err != nil || state.ActiveProfile != "office" {
|
||||
t.Fatalf("read-only load state=%#v err=%v", state, err)
|
||||
}
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if info.Mode().Perm() != 0o644 {
|
||||
t.Fatalf("read-only load changed mode to %o", info.Mode().Perm())
|
||||
}
|
||||
if _, err := os.Stat(path + ".lock"); !os.IsNotExist(err) {
|
||||
t.Fatalf("read-only load created lock: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user