REPOSITORY / ScuroNeko/Laniakea
Pull Requests
v1.0.0 #9
+2
-2
@@ -362,9 +362,9 @@ func statusHandler[T any](bot *Bot[T], opts *BotWebHookOpts) http.HandlerFunc {
|
||||
func (bot *Bot[T]) newWebHookMux(ctx context.Context, opts *BotWebHookOpts) *http.ServeMux {
|
||||
r := http.NewServeMux()
|
||||
if opts.UseStatusPath {
|
||||
r.HandleFunc("/status", statusHandler[T](bot, opts))
|
||||
r.HandleFunc("/status", statusHandler(bot, opts))
|
||||
}
|
||||
r.HandleFunc(opts.Path, updateHandler[T](ctx, bot, opts.SecretToken))
|
||||
r.HandleFunc(opts.Path, updateHandler(ctx, bot, opts.SecretToken))
|
||||
return r
|
||||
}
|
||||
func (bot *Bot[T]) runWebHook(ctx context.Context, opts *BotWebHookOpts) error {
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func TestValidateArgsRequiresFullMatch(t *testing.T) {
|
||||
intCmd := NewCommand[NoData](func(ctx *MsgContext, db NoData) error { return nil }, "int", NewCommandArg("n").SetValueType(CommandValueIntType).SetRequired())
|
||||
intCmd := NewCommand(func(ctx *MsgContext, db NoData) error { return nil }, "int", NewCommandArg("n").SetValueType(CommandValueIntType).SetRequired())
|
||||
if err := intCmd.validateArgs([]string{"123"}); err != nil {
|
||||
t.Fatalf("expected valid integer argument, got %v", err)
|
||||
}
|
||||
@@ -14,7 +14,7 @@ func TestValidateArgsRequiresFullMatch(t *testing.T) {
|
||||
t.Fatalf("expected ErrCmdArgRegexpMismatch for partial int match, got %v", err)
|
||||
}
|
||||
|
||||
boolCmd := NewCommand[NoData](func(ctx *MsgContext, db NoData) error { return nil }, "bool", NewCommandArg("flag").SetValueType(CommandValueBoolType).SetRequired())
|
||||
boolCmd := NewCommand(func(ctx *MsgContext, db NoData) error { return nil }, "bool", NewCommandArg("flag").SetValueType(CommandValueBoolType).SetRequired())
|
||||
if err := boolCmd.validateArgs([]string{"false"}); err != nil {
|
||||
t.Fatalf("expected valid bool argument, got %v", err)
|
||||
}
|
||||
@@ -24,7 +24,7 @@ func TestValidateArgsRequiresFullMatch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateArgsEnforcesRequiredArgIndex(t *testing.T) {
|
||||
cmd := NewCommand[NoData](
|
||||
cmd := NewCommand(
|
||||
func(ctx *MsgContext, db NoData) error { return nil },
|
||||
"mixed",
|
||||
NewCommandArg("optional"),
|
||||
|
||||
+9
-9
@@ -53,7 +53,7 @@ func TestRequirePolicyStopsExecutionOnDeniedPolicy(t *testing.T) {
|
||||
errorTemplate: "Error: %s",
|
||||
}
|
||||
|
||||
mw := RequirePolicy[NoData]("deny", func(ctx *MsgContext, data NoData) error {
|
||||
mw := RequirePolicy("deny", func(ctx *MsgContext, data NoData) error {
|
||||
return AsUserError(errors.New("blocked"))
|
||||
})
|
||||
|
||||
@@ -159,7 +159,7 @@ func TestRequireChatAdminUsesNormalizedIDs(t *testing.T) {
|
||||
|
||||
func TestAllPoliciesReturnsFirstError(t *testing.T) {
|
||||
want := AsUserError(errors.New("blocked"))
|
||||
policy := AllPolicies[NoData](
|
||||
policy := AllPolicies(
|
||||
func(ctx *MsgContext, data NoData) error { return nil },
|
||||
func(ctx *MsgContext, data NoData) error { return want },
|
||||
func(ctx *MsgContext, data NoData) error {
|
||||
@@ -175,7 +175,7 @@ func TestAllPoliciesReturnsFirstError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAnyPolicyAllowsLaterSuccessAfterInternalError(t *testing.T) {
|
||||
policy := AnyPolicy[NoData](
|
||||
policy := AnyPolicy(
|
||||
func(ctx *MsgContext, data NoData) error { return AsInternalError(errors.New("temporary")) },
|
||||
func(ctx *MsgContext, data NoData) error { return nil },
|
||||
)
|
||||
@@ -187,7 +187,7 @@ func TestAnyPolicyAllowsLaterSuccessAfterInternalError(t *testing.T) {
|
||||
|
||||
func TestAnyPolicyReturnsInternalErrorWhenNonePass(t *testing.T) {
|
||||
internal := AsInternalError(errors.New("temporary"))
|
||||
policy := AnyPolicy[NoData](
|
||||
policy := AnyPolicy(
|
||||
func(ctx *MsgContext, data NoData) error { return AsUserError(errors.New("denied")) },
|
||||
func(ctx *MsgContext, data NoData) error { return internal },
|
||||
)
|
||||
@@ -200,7 +200,7 @@ func TestAnyPolicyReturnsInternalErrorWhenNonePass(t *testing.T) {
|
||||
|
||||
func TestAnyPolicyReturnsFirstDenyWhenNoPolicyPasses(t *testing.T) {
|
||||
first := AsUserError(errors.New("first deny"))
|
||||
policy := AnyPolicy[NoData](
|
||||
policy := AnyPolicy(
|
||||
func(ctx *MsgContext, data NoData) error { return first },
|
||||
func(ctx *MsgContext, data NoData) error { return AsUserError(errors.New("second deny")) },
|
||||
)
|
||||
@@ -212,7 +212,7 @@ func TestAnyPolicyReturnsFirstDenyWhenNoPolicyPasses(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNotPolicyInvertsUserDenyButPreservesInternalErrors(t *testing.T) {
|
||||
inverted := NotPolicy[NoData](func(ctx *MsgContext, data NoData) error {
|
||||
inverted := NotPolicy(func(ctx *MsgContext, data NoData) error {
|
||||
return AsUserError(errors.New("denied"))
|
||||
})
|
||||
if err := inverted(&MsgContext{Logger: slog.CreateLogger()}, NoData{}); err != nil {
|
||||
@@ -220,7 +220,7 @@ func TestNotPolicyInvertsUserDenyButPreservesInternalErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
internal := AsInternalError(errors.New("temporary"))
|
||||
preserve := NotPolicy[NoData](func(ctx *MsgContext, data NoData) error {
|
||||
preserve := NotPolicy(func(ctx *MsgContext, data NoData) error {
|
||||
return internal
|
||||
})
|
||||
err := preserve(&MsgContext{Logger: slog.CreateLogger()}, NoData{})
|
||||
@@ -240,7 +240,7 @@ func TestRequirePolicyEmitsObserverEvents(t *testing.T) {
|
||||
ChatID: 20,
|
||||
}
|
||||
|
||||
mw := RequirePolicy[NoData]("allow", func(ctx *MsgContext, data NoData) error {
|
||||
mw := RequirePolicy("allow", func(ctx *MsgContext, data NoData) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -264,7 +264,7 @@ func TestRequirePolicyEmitsObserverEvents(t *testing.T) {
|
||||
errorTemplate: "%s",
|
||||
}
|
||||
|
||||
mw := RequirePolicy[NoData]("deny", func(ctx *MsgContext, data NoData) error {
|
||||
mw := RequirePolicy("deny", func(ctx *MsgContext, data NoData) error {
|
||||
return AsInternalError(errors.New("blocked"))
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user