github.com/safedep/dry@v0.0.0-20241016050132-a15651f0548b/adapters/http/router_echo_test.go (about) 1 package http 2 3 import ( 4 "net/http" 5 "net/http/httptest" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestEchoRouterHealthCheck(t *testing.T) { 12 router, err := NewEchoRouter(EchoRouterConfig{ 13 ServiceName: "test", 14 SkipMetricsEndpoint: true, 15 }) 16 17 assert.NoError(t, err) 18 19 req := httptest.NewRequest(http.MethodGet, HealthPath, nil) 20 rec := httptest.NewRecorder() 21 22 router.Handler().ServeHTTP(rec, req) 23 24 assert.Equal(t, http.StatusOK, rec.Code) 25 } 26 27 func TestMetricsWithInvalidServiceName(t *testing.T) { 28 _, err := NewEchoRouter(EchoRouterConfig{ 29 ServiceName: "test", 30 MetricsSubsystem: "test$", 31 }) 32 33 assert.Error(t, err) 34 } 35 36 // Need to be careful. Can't register prometheus metrics multiple times. 37 func TestEchoRouterMetrics(t *testing.T) { 38 router, err := NewEchoRouter(EchoRouterConfig{ 39 ServiceName: "test_sample_service", 40 }) 41 42 assert.NoError(t, err) 43 44 req := httptest.NewRequest(http.MethodGet, MetricsPath, nil) 45 rec := httptest.NewRecorder() 46 47 router.Handler().ServeHTTP(rec, req) 48 49 assert.Equal(t, http.StatusOK, rec.Code) 50 }