]> git.giacomolli.uk - onechat/blobdiff - telegram_fake_helper_test.go
Order model and chat declarations
[onechat] / telegram_fake_helper_test.go
index b71eee038ebf084da3481bd63c3643cda8600c0d..6082d7ddac1b87190475bb6bb583692207b0c293 100644 (file)
@@ -50,6 +50,42 @@ type TelegramFake struct {
        images  map[string][]byte
 }
 
        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()
 // 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
 }
 
        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{
 // telegramOwnerMessage returns a text message of the owner in the private chat.
 func telegramOwnerMessage(text string) *TelegramMessage {
        return &TelegramMessage{