Files
CLIProxyAPI/internal/pluginhost/config_test.go
Luis Pater 8d2c00c107 feat(plugin-config): update default plugin Enabled behavior to false and expand test coverage
- Changed default plugin `Enabled` state from `true` to `false` across configurations, runtime logic, and YAML defaults.
- Added helper function `enabledPluginConfigs` for generating plugin configs with `Enabled` set explicitly.
- Expanded unit tests in `pluginhost`, `config`, and `management` to validate behavior changes for disabled plugins, default settings, and skipped load scenarios.
2026-06-17 03:46:30 +08:00

52 lines
1.2 KiB
Go

package pluginhost
import (
"strings"
"testing"
"github.com/router-for-me/CLIProxyAPI/v7/internal/config"
"gopkg.in/yaml.v3"
)
func TestRuntimeConfigYAMLAddsHostDefaultsToRawPluginConfig(t *testing.T) {
var node yaml.Node
if errDecode := yaml.Unmarshal([]byte("config1: true\nconfig2: value\n"), &node); errDecode != nil {
t.Fatalf("yaml.Unmarshal() error = %v", errDecode)
}
if len(node.Content) != 1 {
t.Fatalf("yaml node content length = %d, want 1", len(node.Content))
}
item := config.PluginInstanceConfig{
Priority: 3,
Raw: *node.Content[0],
}
got := string(runtimeConfigYAML(item, true))
for _, want := range []string{
"config1: true",
"config2: value",
"enabled: true",
"priority: 3",
} {
if !strings.Contains(got, want) {
t.Fatalf("runtimeConfigYAML() missing %q in:\n%s", want, got)
}
}
}
func TestRuntimeConfigYAMLDefaultsEnabledFalse(t *testing.T) {
item := config.PluginInstanceConfig{
Priority: 3,
}
got := string(runtimeConfigYAML(item, false))
for _, want := range []string{
"enabled: false",
"priority: 3",
} {
if !strings.Contains(got, want) {
t.Fatalf("runtimeConfigYAML() missing %q in:\n%s", want, got)
}
}
}