generated from CubeCraft-Creations/Tracehound
CUB-235: add tests for GET /api/v1/cameras/:id endpoint
- TestGetCameraDetail_NotFound: returns 404 for missing camera - TestGetCameraDetail_Success: returns camera + last_status + history - TestGetCameraDetail_EmptyHistory: camera with no status logs - TestGetCameraDetail_HistoryLimitedTo100: history capped at 100 entries - TestGetCameraDetail_MissingID: returns 400 for empty ID param - TestGetCameraDetail_LastStatusPresent: verifies last_status field - db_test.go: migration smoke test (documents splitSQL comment bug)
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOpenMigration(t *testing.T) {
|
||||
f, err := os.CreateTemp("", "remoterig-db-test-*.db")
|
||||
if err != nil {
|
||||
t.Fatalf("create temp: %v", err)
|
||||
}
|
||||
path := f.Name()
|
||||
f.Close()
|
||||
defer os.Remove(path)
|
||||
|
||||
database, err := Open(path)
|
||||
if err != nil {
|
||||
t.Fatalf("Open failed: %v", err)
|
||||
}
|
||||
defer database.Close()
|
||||
|
||||
var count int
|
||||
err = database.QueryRow("SELECT COUNT(*) FROM cameras").Scan(&count)
|
||||
if err != nil {
|
||||
t.Fatalf("query cameras: %v", err)
|
||||
}
|
||||
t.Logf("cameras table exists, count=%d", count)
|
||||
}
|
||||
|
||||
func TestSplitSQLComments(t *testing.T) {
|
||||
sql := migration001
|
||||
stmts := splitSQL(sql)
|
||||
for i, s := range stmts {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
continue
|
||||
}
|
||||
t.Logf("Statement %d: %s", i, s[:min(len(s), 80)])
|
||||
}
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
Reference in New Issue
Block a user