Apply managed DNS mode in the macOS package

This commit is contained in:
Dev Scribe
2026-08-21 15:12:32 +07:00
committed by Cuong Manh Le
parent 1f001a559a
commit 6615e431dc
13 changed files with 432 additions and 64 deletions
+38
View File
@@ -0,0 +1,38 @@
package cli
import (
"testing"
"github.com/Control-D-Inc/ctrld"
)
func TestUpdateConfigInterceptMode(t *testing.T) {
tests := []struct {
name string
current string
mode string
want string
wantUpdated bool
}{
{name: "empty flag preserves config", current: "dns", mode: "", want: "dns"},
{name: "dns is persisted", mode: "dns", want: "dns", wantUpdated: true},
{name: "hard is persisted", current: "dns", mode: "hard", want: "hard", wantUpdated: true},
{name: "off clears persisted mode", current: "dns", mode: "off", want: "", wantUpdated: true},
{name: "off is idempotent", mode: "off", want: ""},
{name: "invalid flag preserves config", current: "hard", mode: "invalid", want: "hard"},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
cfg := &ctrld.Config{}
cfg.Service.InterceptMode = tc.current
updated := updateConfigInterceptMode(cfg, tc.mode)
if updated != tc.wantUpdated {
t.Fatalf("updateConfigInterceptMode() updated = %v, want %v", updated, tc.wantUpdated)
}
if cfg.Service.InterceptMode != tc.want {
t.Fatalf("service.intercept_mode = %q, want %q", cfg.Service.InterceptMode, tc.want)
}
})
}
}