CUB-235: add tests for GET /api/v1/cameras/:id endpoint
CI/CD / lint-and-typecheck (pull_request) Successful in 9m27s
CI/CD / test (pull_request) Successful in 7s
CI/CD / build (pull_request) Failing after 9s
CI/CD / deploy (pull_request) Has been skipped

- 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:
2026-05-23 04:36:18 +00:00
parent 1a8f67a392
commit 5100f6be65
2 changed files with 314 additions and 0 deletions
+49
View File
@@ -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
}