diff --git a/.gitignore b/.gitignore index dcf1b8e..be5cc25 100644 --- a/.gitignore +++ b/.gitignore @@ -195,4 +195,4 @@ fabric.properties /events.db /events.db.wal /duckdb-driver -/GeoLite2-City.mmdb +/GeoLite2-City.mmdb \ No newline at end of file diff --git a/Makefile b/Makefile index d834191..20f74a3 100644 --- a/Makefile +++ b/Makefile @@ -41,11 +41,20 @@ build_all: $(BUILDDEPS) @echo "Building windows amd64 binary..." @GOOS=windows GOARCH=amd64 go build -o "bin/$(BINARY_NAME)-windows-amd64.exe" src/main.go -test_unit: +test_clean: + @echo "Cleaning test databases..." + @rm -f app.db + @rm -f events.db + @rm -f events.db.wal + @echo "Cleaning test results..." + @rm -f coverage.unit.out + @rm -f coverage.e2e.out + +test_unit: test_clean @echo "Running unit tests..." @@GOOS=$(OS) GOARCH=$(ARCH) ENV=test go test -count 1 -timeout 10s -race -coverprofile=coverage.unit.out -covermode=atomic -v -coverpkg=./src/... ./src/... -test_e2e: +test_e2e: test_clean @echo "Running end-to-end tests..." @@GOOS=$(OS) GOARCH=$(ARCH) ENV=test go test -count 1 -timeout 10s -race -coverprofile=coverage.e2e.out -covermode=atomic -v -coverpkg=./src/... ./tests/... diff --git a/src/security/jwt_test.go b/src/security/jwt_test.go index f6ce401..28a6c9c 100644 --- a/src/security/jwt_test.go +++ b/src/security/jwt_test.go @@ -3,7 +3,6 @@ package security import ( "onepixel_backend/src/db/models" "onepixel_backend/src/utils/applogger" - _ "onepixel_backend/tests/providers" "testing" "github.com/stretchr/testify/assert" diff --git a/tests/providers/test_db_providers.go b/tests/providers/test_db_providers.go index 4a56ce4..5a0c961 100644 --- a/tests/providers/test_db_providers.go +++ b/tests/providers/test_db_providers.go @@ -15,22 +15,23 @@ import ( "time" ) -var removeDbOnce sync.Once +var warnDbExistOnce sync.Once func init() { db.InjectDBProvider("sqlite", ProvideSqliteDB) db.InjectDBProvider("duckdb", ProvideDuckDB) // Remove existing test databases - removeDbOnce.Do(func() { + warnDbExistOnce.Do(func() { cwd := lo.Must(os.Getwd()) appDbPath := path.Join(cwd, config.DBUrl) eventDbPath := path.Join(cwd, config.EventDBUrl) - applogger.Debug("App: Removing existing test database file at", appDbPath) - lo.Must0(os.RemoveAll(appDbPath)) - applogger.Debug("Events: Removing existing test database file at", eventDbPath) - lo.Must0(os.RemoveAll(eventDbPath)) - lo.Must0(os.RemoveAll(eventDbPath + ".wal")) + if _, err := os.Stat(appDbPath); err == nil { + applogger.Error("Test: app.db already exists") + } + if _, err := os.Stat(eventDbPath); err == nil { + applogger.Error("Test: event.db already exists") + } time.Sleep(1 * time.Second) })