From d1c46901367a4cc2d63fad5e55c5c8cb0ef243c8 Mon Sep 17 00:00:00 2001 From: ajatprabha Date: Mon, 15 Apr 2024 13:36:22 +0530 Subject: [PATCH] add specs for infoHandler error cases --- otelcourier/info_handler_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/otelcourier/info_handler_test.go b/otelcourier/info_handler_test.go index 1818164..ac88cf9 100644 --- a/otelcourier/info_handler_test.go +++ b/otelcourier/info_handler_test.go @@ -2,6 +2,7 @@ package otelcourier import ( "context" + "net/http" "os" "os/signal" "strconv" @@ -112,3 +113,15 @@ func Test_boolInt64(t *testing.T) { }) } } + +func TestInfoHandler_callback_error(t *testing.T) { + ih := infoHandler(func(w http.ResponseWriter, r *http.Request) { + _, _ = w.Write([]byte("invalid json")) + }) + + cb := ih.callback() + err := cb(context.Background(), nil) + assert.EqualError(t, err, "invalid character 'i' looking for beginning of value") + + assert.EqualError(t, cb(nil, nil), "net/http: nil Context") +}