(new): expand runtime APIs
(fix): harden concurrent lifecycle (tests): add regression coverage (doc): update v1.2 guidance
This commit is contained in:
@@ -157,6 +157,43 @@ func TestRequireChatAdminUsesNormalizedIDs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequireChatAdminUsesMessageContextCancellation(t *testing.T) {
|
||||
api := tgapi.NewAPI(
|
||||
tgapi.NewAPIOpts("token").
|
||||
SetAPIURL("https://example.test").
|
||||
SetHTTPClient(&http.Client{Transport: roundTripFunc(func(req *http.Request) (*http.Response, error) {
|
||||
if err := req.Context().Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Header: http.Header{"Content-Type": []string{"application/json"}},
|
||||
Body: io.NopCloser(strings.NewReader(`{"ok":true,"result":{"status":"administrator","user":{"id":55,"is_bot":false,"first_name":"tester"}}}`)),
|
||||
}, nil
|
||||
})}),
|
||||
)
|
||||
t.Cleanup(func() {
|
||||
if err := api.Close(); err != nil {
|
||||
t.Fatalf("Close returned error: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
requestCtx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
ctx := &MessageContext{
|
||||
API: api,
|
||||
ChatID: -2001,
|
||||
FromID: 55,
|
||||
Logger: sneklog.NewLogger(),
|
||||
ctx: requestCtx,
|
||||
}
|
||||
|
||||
err := RequireChatAdmin[NoData]()(ctx, NoData{})
|
||||
if !errors.Is(err, context.Canceled) || !IsInternalError(err) {
|
||||
t.Fatalf("RequireChatAdmin error = %v, want internal context.Canceled", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAllPoliciesReturnsFirstError(t *testing.T) {
|
||||
want := AsUserError(errors.New("blocked"))
|
||||
policy := AllPolicies(
|
||||
|
||||
Reference in New Issue
Block a user