Skip to content

Commit

Permalink
Ensure tests run only in a testing environment with a clean database.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo committed Dec 1, 2024
1 parent fb625e7 commit e2d5fcc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,31 @@ import (
"net"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"

"github.com/jasonlovesdoggo/abacus/utils"

"github.com/goccy/go-json"

"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)

func init() {
utils.LoadEnv()

if os.Getenv("TESTING") != "true" {
fmt.Println("Running tests in non-testing mode. Exiting...")
os.Exit(0)
}
if Client.Get(context.Background(), "K:stats:Total") != nil {
fmt.Println("Running tests on a non-empty database. Exiting...")
os.Exit(0)
}
}

// mockResponseWriter wraps httptest.ResponseRecorder to implement http.CloseNotifier.
type mockResponseWriter struct {
*httptest.ResponseRecorder
Expand Down

0 comments on commit e2d5fcc

Please sign in to comment.