feat: add persistent proxy profile management
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package app_test
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"proxyctl/internal/app"
|
||||
"proxyctl/internal/profile"
|
||||
)
|
||||
|
||||
func TestUserCanCreateAndActivatePersistentSingleProxyProfile(t *testing.T) {
|
||||
configFile := filepath.Join(t.TempDir(), "proxyctl", "profiles.json")
|
||||
application, err := app.New(profile.NewFileStore(configFile))
|
||||
if err != nil {
|
||||
t.Fatalf("start application: %v", err)
|
||||
}
|
||||
|
||||
result := application.Dispatch(app.Intent{
|
||||
Kind: app.CreateProfile,
|
||||
Profile: profile.Profile{
|
||||
Name: "office",
|
||||
Mode: profile.SingleMode,
|
||||
SingleURL: "http://proxy.example:8080",
|
||||
Bypass: []string{"LOCALHOST", ".Example.com", "localhost"},
|
||||
},
|
||||
})
|
||||
if result.Err != nil {
|
||||
t.Fatalf("create Profile: %v", result.Err)
|
||||
}
|
||||
|
||||
result = application.Dispatch(app.Intent{Kind: app.ActivateProfile, Name: "office"})
|
||||
if result.Err != nil {
|
||||
t.Fatalf("activate Profile: %v", result.Err)
|
||||
}
|
||||
if result.Snapshot.ActiveProfile != "office" {
|
||||
t.Fatalf("Active Profile = %q, want office", result.Snapshot.ActiveProfile)
|
||||
}
|
||||
got := result.Snapshot.Profiles[0]
|
||||
if got.SingleURL != "http://proxy.example:8080" {
|
||||
t.Fatalf("single proxy value = %q", got.SingleURL)
|
||||
}
|
||||
if want := []string{"localhost", ".example.com"}; !equalStrings(got.Bypass, want) {
|
||||
t.Fatalf("normalized Bypass = %#v, want %#v", got.Bypass, want)
|
||||
}
|
||||
if got.HTTPURL != "http://proxy.example:8080" || got.HTTPSURL != "http://proxy.example:8080" || got.AllURL != "http://proxy.example:8080" {
|
||||
t.Fatalf("Single proxy was not expanded: %#v", got)
|
||||
}
|
||||
|
||||
restarted, err := app.New(profile.NewFileStore(configFile))
|
||||
if err != nil {
|
||||
t.Fatalf("restart application: %v", err)
|
||||
}
|
||||
persisted := restarted.Snapshot()
|
||||
if persisted.ActiveProfile != "office" || len(persisted.Profiles) != 1 {
|
||||
t.Fatalf("persisted snapshot = %#v", persisted)
|
||||
}
|
||||
}
|
||||
|
||||
func equalStrings(got, want []string) bool {
|
||||
if len(got) != len(want) {
|
||||
return false
|
||||
}
|
||||
for i := range got {
|
||||
if got[i] != want[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user