T0.1: Add test scripts and documentation

Add scripts/test.sh and scripts/test.bat to run go vet and go test -race.
Update docs/TESTS.md with test script usage and reorganized manual test commands.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
mixeme
2026-06-18 20:13:46 +03:00
parent f653b1e484
commit 0038975adc
3 changed files with 90 additions and 37 deletions
+51 -37
View File
@@ -2,6 +2,57 @@
All tests are located alongside source code in the `src/core/` package. Tests follow Go conventions with `*_test.go` filename patterns. All tests are located alongside source code in the `src/core/` package. Tests follow Go conventions with `*_test.go` filename patterns.
## Running Tests
### Using the test scripts
The repository provides convenience scripts to run all tests with static analysis:
**Unix/Linux/macOS:**
```bash
./scripts/test.sh
```
**Windows:**
```bash
scripts\test.bat
```
Both scripts run:
1. `go vet ./...` — static analysis for common errors and suspicious code patterns
2. `go test -race ./...` — tests with race condition detection enabled
### Manual test commands
Run all tests:
```bash
go test ./...
```
Run all tests with race detection:
```bash
go test -race ./...
```
Run tests with verbose output:
```bash
go test -v ./...
```
Run a specific test by name:
```bash
go test -run TestRunJobWritesLogFile ./src/core
```
Run tests with code coverage:
```bash
go test -cover ./src/core
go test -coverprofile=coverage.out ./src/core
go tool cover -html=coverage.out
```
---
## Test Files Overview ## Test Files Overview
### store_test.go ### store_test.go
@@ -107,43 +158,6 @@ Tests Linux autostart entry creation via XDG Desktop Entry files.
--- ---
## Running Tests
### Run all tests in the package
```bash
cd D:\Local\Git\gosentry
go test ./src/core
```
### Run tests with verbose output
```bash
go test -v ./src/core
```
### Run specific test by name
```bash
go test -run TestRunJobWritesLogFile ./src/core
```
### Run Windows-only tests (on Windows)
```bash
go test -v ./src/core # Windows build tags are active
```
### Run Linux-only tests (on Linux)
```bash
go test -v ./src/core # Linux build tags are active
```
### Run with code coverage
```bash
go test -cover ./src/core
go test -coverprofile=coverage.out ./src/core
go tool cover -html=coverage.out
```
---
## Test Design Principles ## Test Design Principles
1. **Isolation** — Tests use `t.TempDir()` for file operations and `t.Setenv()` for environment variables to avoid affecting system state. 1. **Isolation** — Tests use `t.TempDir()` for file operations and `t.Setenv()` for environment variables to avoid affecting system state.
+23
View File
@@ -0,0 +1,23 @@
@echo off
REM GoSentry test runner
REM Runs go vet and go test with race detection
echo Running go vet...
go vet ./...
if errorlevel 1 (
echo.
echo ✗ go vet failed
exit /b 1
)
echo.
echo Running go test with race detection...
go test -race ./...
if errorlevel 1 (
echo.
echo ✗ go test failed
exit /b 1
)
echo.
echo ✓ All tests passed
+16
View File
@@ -0,0 +1,16 @@
#!/bin/bash
# GoSentry test runner
# Runs go vet and go test with race detection
set -e
echo "Running go vet..."
go vet ./...
echo ""
echo "Running go test with race detection..."
go test -race ./...
echo ""
echo "✓ All tests passed"