feat: implemented test poller

This commit is contained in:
abelith committed 2026-10-06 13:51:00 +03:00
1 parent 6af79d8cda
commit a78e9927bc
3 files changed
+29 -7

No files matched your search

+25 -3
View File
@@ -4,12 +4,12 @@ import (
"context"
"crypto/tls"
"errors"
"fmt"
maxbot "github.com/max-messenger/max-bot-api-client-go/v2"
"github.com/max-messenger/max-bot-api-client-go/v2/model"
"github.com/rs/zerolog/log"
"net"
"net/http"
"sync"
"time"
)
@@ -36,7 +36,10 @@ type LongPoller struct {
pollInterval time.Duration
}
type TestPoller struct{}
type TestPoller struct {
ch chan model.Update
mu sync.Mutex
}
type webhookOptions struct {
addr string
@@ -185,8 +188,27 @@ func (lp *LongPoller) Start(ctx context.Context) (<-chan model.Update, error) {
return ch, nil
}
func (tp *TestPoller) Inject(ctx context.Context, updates []model.Update) {
ch := make(chan model.Update, 1)
go func() {
defer close(ch)
for _, upd := range updates {
select {
case <-ctx.Done():
case ch <- upd:
}
}
}()
tp.mu.Lock()
tp.ch = ch
defer tp.mu.Unlock()
}
func (tp *TestPoller) Start(_ context.Context) (<-chan model.Update, error) {
return nil, fmt.Errorf("unimplemented")
return tp.ch, nil
}
func WithAddress(addr string) WebhookOption {
+3 -3
View File
@@ -1,16 +1,16 @@
package errors
type GomaxError struct {
type GoMaxError struct {
Message string
Err error
}
func (ge *GomaxError) Error() string {
func (ge *GoMaxError) Error() string {
return ge.Err.Error()
}
func New(parent error, text string) error {
return &GomaxError{
return &GoMaxError{
Message: text,
Err: parent,
}
+1 -1
View File
@@ -27,7 +27,7 @@ func MwErrorResponder(defaultMsg string) core.Middleware {
return func(next core.HandlerFunc) core.HandlerFunc {
return func(c *mcontext.Context) error {
err := next(c)
var maxErr *merrors.GomaxError
var maxErr *merrors.GoMaxError
if errors.As(err, &maxErr) {
return c.Respond(maxErr.Message)