mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-06-22 06:57:37 +08:00
90 lines
2.0 KiB
Go
90 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/router-for-me/CLIProxyAPI/v7/internal/config"
|
|
)
|
|
|
|
func TestShouldStartExampleAPIKeyWarningServer(t *testing.T) {
|
|
cfgWithExampleKey := &config.Config{
|
|
SDKConfig: config.SDKConfig{
|
|
APIKeys: []string{"real-key", " your-api-key-1 "},
|
|
},
|
|
}
|
|
cfgWithRealKey := &config.Config{
|
|
SDKConfig: config.SDKConfig{
|
|
APIKeys: []string{"real-key"},
|
|
},
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
cfg *config.Config
|
|
commandMode bool
|
|
tuiMode bool
|
|
standalone bool
|
|
cloudConfigMissing bool
|
|
homeMode bool
|
|
want bool
|
|
}{
|
|
{
|
|
name: "normal server with example key",
|
|
cfg: cfgWithExampleKey,
|
|
want: true,
|
|
},
|
|
{
|
|
name: "standalone tui with example key",
|
|
cfg: cfgWithExampleKey,
|
|
tuiMode: true,
|
|
standalone: true,
|
|
want: true,
|
|
},
|
|
{
|
|
name: "pure tui client is not blocked",
|
|
cfg: cfgWithExampleKey,
|
|
tuiMode: true,
|
|
standalone: false,
|
|
commandMode: false,
|
|
want: false,
|
|
},
|
|
{
|
|
name: "one-shot command is not blocked",
|
|
cfg: cfgWithExampleKey,
|
|
commandMode: true,
|
|
want: false,
|
|
},
|
|
{
|
|
name: "home mode is not blocked",
|
|
cfg: cfgWithExampleKey,
|
|
homeMode: true,
|
|
want: false,
|
|
},
|
|
{
|
|
name: "cloud standby without config is not blocked",
|
|
cfg: cfgWithExampleKey,
|
|
cloudConfigMissing: true,
|
|
want: false,
|
|
},
|
|
{
|
|
name: "normal server with real key",
|
|
cfg: cfgWithRealKey,
|
|
want: false,
|
|
},
|
|
{
|
|
name: "nil config",
|
|
cfg: nil,
|
|
want: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := shouldStartExampleAPIKeyWarningServer(tt.cfg, tt.commandMode, tt.tuiMode, tt.standalone, tt.cloudConfigMissing, tt.homeMode)
|
|
if got != tt.want {
|
|
t.Fatalf("shouldStartExampleAPIKeyWarningServer() = %t, want %t", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|