Skip to content

Commit

Permalink
Adjusted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBQu committed Dec 6, 2024
1 parent 12aee96 commit 4d8fea4
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion http/handler_extras_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
}

0 comments on commit 4d8fea4

Please sign in to comment.