35 lines
1.3 KiB
Go
35 lines
1.3 KiB
Go
package plugin
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestRuleEnvironmentUsesVisiblePluginSettings(t *testing.T) {
|
|
reg := NewRegistry(nil)
|
|
reg.ruleSettings = func(pluginID, vmName string, maskSecrets bool) map[string]any {
|
|
if pluginID != "local.capture-shortcut" || vmName != "test-vm" || !maskSecrets {
|
|
t.Fatalf("unexpected settings lookup: %q %q %v", pluginID, vmName, maskSecrets)
|
|
}
|
|
return map[string]any{"shortcut": "Ctrl+F12", "autoRelease": false, "token": "private"}
|
|
}
|
|
intent := StartIntent{PluginID: "local.capture-shortcut"}
|
|
schema := &SettingsSchema{Scope: "vm", Properties: map[string]SettingProperty{
|
|
"shortcut": {}, "autoRelease": {}, "token": {Secret: true},
|
|
}}
|
|
rule := RuleHook{Actions: []RuleAction{{Kind: "set_env", EnvFromSettings: map[string]string{
|
|
"REIMS_PLUGIN_LOCAL_CAPTURE_SHORTCUT_KEYS": "shortcut",
|
|
"REIMS_PLUGIN_LOCAL_CAPTURE_SHORTCUT_RELEASE_ON_LEAVE": "autoRelease",
|
|
"REIMS_PLUGIN_LOCAL_CAPTURE_SHORTCUT_TOKEN": "token",
|
|
"PATH": "shortcut",
|
|
}}}}
|
|
reg.applyRuleEnvSettings(&intent, rule, schema, "test-vm")
|
|
want := map[string]string{
|
|
"REIMS_PLUGIN_LOCAL_CAPTURE_SHORTCUT_KEYS": "Ctrl+F12",
|
|
"REIMS_PLUGIN_LOCAL_CAPTURE_SHORTCUT_RELEASE_ON_LEAVE": "false",
|
|
}
|
|
if !reflect.DeepEqual(intent.Env, want) {
|
|
t.Fatalf("unexpected environment: %#v", intent.Env)
|
|
}
|
|
}
|