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 {