X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/f5c601f1801aaa276f8c335fcb51c373edc0b50c..80e348724041a694002fc38f57e8868b9b9a2be9:/telegram_fake_helper_test.go diff --git a/telegram_fake_helper_test.go b/telegram_fake_helper_test.go index b71eee0..6082d7d 100644 --- a/telegram_fake_helper_test.go +++ b/telegram_fake_helper_test.go @@ -50,6 +50,42 @@ type TelegramFake struct { images map[string][]byte } +// newTelegramFake starts a fake Bot API server that stops at the end of the +// test. +func newTelegramFake(t *testing.T) *TelegramFake { + t.Helper() + + f := &TelegramFake{ + added: make(chan struct{}, 1), + stopped: make(chan struct{}), + } + + f.Server = httptest.NewServer(http.HandlerFunc(f.serve)) + t.Cleanup(f.Close) + t.Cleanup(func() { + close(f.stopped) + }) + + return f +} + +// newTelegramLocalFake returns the same fake API without network goroutines. +// Its RoundTrip handles requests directly for tests with fake time. +func newTelegramLocalFake(t *testing.T) *TelegramFake { + t.Helper() + + f := &TelegramFake{ + Server: &httptest.Server{URL: "https://example.com"}, + added: make(chan struct{}, 1), + stopped: make(chan struct{}), + } + t.Cleanup(func() { + close(f.stopped) + }) + + return f +} + // Add makes update available to getUpdates. func (f *TelegramFake) Add(update TelegramUpdate) { f.mutex.Lock() @@ -283,42 +319,6 @@ func (f *TelegramFake) from(offset int64) []TelegramUpdate { return updates } -// newTelegramFake starts a fake Bot API server that stops at the end of the -// test. -func newTelegramFake(t *testing.T) *TelegramFake { - t.Helper() - - f := &TelegramFake{ - added: make(chan struct{}, 1), - stopped: make(chan struct{}), - } - - f.Server = httptest.NewServer(http.HandlerFunc(f.serve)) - t.Cleanup(f.Close) - t.Cleanup(func() { - close(f.stopped) - }) - - return f -} - -// newTelegramLocalFake returns the same fake API without network goroutines. -// Its RoundTrip handles requests directly for tests with fake time. -func newTelegramLocalFake(t *testing.T) *TelegramFake { - t.Helper() - - f := &TelegramFake{ - Server: &httptest.Server{URL: "https://example.com"}, - added: make(chan struct{}, 1), - stopped: make(chan struct{}), - } - t.Cleanup(func() { - close(f.stopped) - }) - - return f -} - // telegramOwnerMessage returns a text message of the owner in the private chat. func telegramOwnerMessage(text string) *TelegramMessage { return &TelegramMessage{