From 4d8fea4da40cacc4705f13e6a8755881953eb0e1 Mon Sep 17 00:00:00 2001 From: Chris Quigley Date: Fri, 6 Dec 2024 16:53:54 -0500 Subject: [PATCH] Adjusted tests --- http/handler_extras_test.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/http/handler_extras_test.go b/http/handler_extras_test.go index d7d1398e90..870cad02d3 100644 --- a/http/handler_extras_test.go +++ b/http/handler_extras_test.go @@ -20,8 +20,11 @@ import ( "github.com/stretchr/testify/require" ) -func TestPurge(t *testing.T) { +func TestPurgeDevModeTrue(t *testing.T) { cdb := setupDatabase(t) + + IsDevMode = true + url := "http://localhost:9181/api/v0/purge" req := httptest.NewRequest(http.MethodPost, url, nil) @@ -40,3 +43,27 @@ func TestPurge(t *testing.T) { // test will timeout if purge never received <-purgeSub.Message() } + +func TestPurgeDevModeFalse(t *testing.T) { + cdb := setupDatabase(t) + + IsDevMode = false + + url := "http://localhost:9181/api/v0/purge" + + req := httptest.NewRequest(http.MethodPost, url, nil) + rec := httptest.NewRecorder() + + purgeSub, err := cdb.Events().Subscribe(event.PurgeName) + require.NoError(t, err) + + handler, err := NewHandler(cdb) + require.NoError(t, err) + handler.ServeHTTP(rec, req) + + res := rec.Result() + require.Equal(t, 400, res.StatusCode) + + // test will timeout if purge never received + <-purgeSub.Message() +}