Files
CLIProxyAPI/internal/pluginhost/config_test.go
Luis Pater d625caddd9 feat(pluginhost): add capabilities for command-line flag handling and plugin execution
- Implemented command-line flag registration and execution for plugins with priority-based conflict resolution.
- Enabled plugin-owned command-line flag execution and persistence of plugin-auth data.
- Added new `Host` methods to support command-line capabilities, including flag normalization, validation, and execution state management.
- Introduced unit tests to ensure coverage for command-line plugin functionality, including auth data persistence.
- Updated configs to normalize plugins during initialization.
2026-06-06 18:35:17 +08:00

36 lines
846 B
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)
}
}
}