settings.RedactModelName holds the pick ("" for none, read by
pii.Choose), this computer's own like RedactModel, kept by KeepOwn and
by the GUI's settings save. /api/privacy-model returns the chosen
model's status and every model's, and takes {do: pick, model}: picked
while off it is saved for the next On; picked while on it is
downloaded, and once on disk it is saved and the other model stopped.
Remove deletes both. masking runs the picked model.
TestPrivacyModelPick and TestMaskingUsesThePickedModel fail on the old
code (no pick; Privacy Filter always).
Run: go test ./internal/settings ./internal/gui ./internal/masking
./internal/gateway -run 'Mask|Redact|Privacy|PII|Unmasked'
./internal/gwmw at the pushed head.
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package settings
|
|
|
|
import "testing"
|
|
|
|
// The masking model is downloaded on one computer: a sync never turns it
|
|
// on on another, nor off on this one.
|
|
func TestRedactModelIsThisComputers(t *testing.T) {
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
from := Settings{RedactModel: true, RedactModelName: "astrlink-guard"}
|
|
from.KeepOwn(Settings{})
|
|
if from.RedactModel || from.RedactModelName != "" {
|
|
t.Fatal("a sync turned the model on")
|
|
}
|
|
from.KeepOwn(Settings{RedactModel: true, RedactModelName: "privacy-filter"})
|
|
if !from.RedactModel || from.RedactModelName != "privacy-filter" {
|
|
t.Fatal("a sync turned the model off, or changed it")
|
|
}
|
|
if err := SetRedactModel(true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !Load().RedactModel {
|
|
t.Fatal("not saved")
|
|
}
|
|
if err := SetRedactModel(false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if Load().RedactModel {
|
|
t.Fatal("not turned off")
|
|
}
|
|
if err := UseRedactModel("astrlink-guard"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if st := Load(); !st.RedactModel || st.RedactModelName != "astrlink-guard" {
|
|
t.Fatalf("not saved: %v %q", st.RedactModel, st.RedactModelName)
|
|
}
|
|
// turned off, the model picked is kept for turning it on again
|
|
if err := SetRedactModel(false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if st := Load(); st.RedactModel || st.RedactModelName != "astrlink-guard" {
|
|
t.Fatalf("off: %v %q", st.RedactModel, st.RedactModelName)
|
|
}
|
|
}
|