mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-06-17 23:33:49 +08:00
- 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.
52 lines
1.2 KiB
Go
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)
|
|
}
|
|
}
|
|
}
|