MCPcopy Index your code
hub / github.com/go-telegram/bot / TestWebhookHandler_ReadBodyError

Function TestWebhookHandler_ReadBodyError

webhook_handler_test.go:84–110  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

82}
83
84func TestWebhookHandler_ReadBodyError(t *testing.T) {
85 debugHandler := &mockDebugHandler{}
86 errorsHandler := &mockErrorsHandler{}
87
88 bot := &Bot{
89 debugHandler: func(format string, args ...any) {
90 debugHandler.Handle(format, args...)
91 },
92 errorsHandler: func(err error) {
93 errorsHandler.Handle(err)
94 },
95 }
96
97 req := httptest.NewRequest(http.MethodPost, "/", errReader(errors.New("read error")))
98 w := httptest.NewRecorder()
99
100 handler := bot.WebhookHandler()
101 handler(w, req)
102
103 if len(errorsHandler.errors) == 0 {
104 t.Fatal("Expected an error, but none occurred")
105 }
106
107 if capturedError := errorsHandler.errors[0]; capturedError == nil || !containsString(capturedError.Error(), "read error") {
108 t.Fatalf("Expected read body error, got %v", capturedError)
109 }
110}
111
112func TestWebhookHandler_DecodeError(t *testing.T) {
113 debugHandler := &mockDebugHandler{}

Callers

nothing calls this directly

Calls 7

HandleMethod · 0.95
HandleMethod · 0.95
WebhookHandlerMethod · 0.95
errReaderFunction · 0.85
containsStringFunction · 0.85
handlerStruct · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected