This commit is contained in:
2025-11-17 15:39:44 +08:00
parent abfa51f12e
commit 1ddda89499
46 changed files with 2185 additions and 751 deletions

View File

@@ -2,8 +2,16 @@ package main
import (
"bytes"
"fmt"
"strings"
"testing"
"time"
"github.com/gofiber/fiber/v3"
"github.com/any-hub/any-hub/internal/hubmodule"
"github.com/any-hub/any-hub/internal/proxy/hooks"
"github.com/any-hub/any-hub/internal/server"
)
func TestParseCLIFlagsPriority(t *testing.T) {
@@ -52,3 +60,24 @@ func TestRunVersionOutput(t *testing.T) {
t.Fatalf("version 输出应包含 any-hub 标识")
}
}
func TestRegisterModuleHandlersFailsWithoutHook(t *testing.T) {
useBufferWriters(t)
key := fmt.Sprintf("missing-hook-%d", time.Now().UnixNano())
hubmodule.MustRegister(hubmodule.ModuleMetadata{
Key: key,
Description: "test module without hooks",
MigrationState: hubmodule.MigrationStateBeta,
SupportedProtocols: []string{
"custom",
},
})
defer hooks.MustRegister(key, hooks.Hooks{})
err := registerModuleHandlers(server.ProxyHandlerFunc(func(ctx fiber.Ctx, route *server.HubRoute) error {
return nil
}))
if err == nil || !strings.Contains(err.Error(), "missing hook") {
t.Fatalf("expected missing hook error, got %v", err)
}
}