5 Commits

8 changed files with 105 additions and 375 deletions
+11 -8
View File
@@ -1,7 +1,7 @@
# RemoteRig — Camera Node Hardware Design # RemoteRig — Camera Node Hardware Design
> **Version:** 0.2.0 | **Status:** Draft > **Version:** 0.2.0 | **Status:** Draft
> **Target:** GoPro Hero 3 Black/Silver + ESP8266 + ESP32 + USB power bank > **Target:** GoPro Hero 3 Black/Silver + ESP-01S/ESP8266 + ESP32-C3 Super Mini + USB power bank
## Overview ## Overview
@@ -29,8 +29,8 @@ Each camera node is two ESP boards in a small case that clips to the tripod/stan
| Item | Qty | Cost | Notes | | Item | Qty | Cost | Notes |
|------|-----|------|-------| |------|-----|------|-------|
| ESP32 Dev Board | 1 | ~$5 | MQTT bridge — talks to hub | | ESP32-C3 Super Mini | 1 | ~$5 | MQTT bridge — talks to hub; board footprint 22.5 × 18.0mm |
| ESP8266 D1 Mini | 1 | ~$3 | Camera bridge — talks to GoPro | | ESP-01S / ESP8266 | 1 | ~$3 | Camera bridge — talks to GoPro; module envelope 24.7 × 14.3 × 12.0mm |
| USB power bank (5000mAh+) | 1 | ~$10 | Powers both boards + GoPro | | USB power bank (5000mAh+) | 1 | ~$10 | Powers both boards + GoPro |
| Micro-USB cable (short) | 2 | ~$2 | Power bank → boards + GoPro | | Micro-USB cable (short) | 2 | ~$2 | Power bank → boards + GoPro |
| Jumper wires F-F | 3 | ~$0.25 | UART TX/RX/GND between boards | | Jumper wires F-F | 3 | ~$0.25 | UART TX/RX/GND between boards |
@@ -45,8 +45,8 @@ Each camera node is two ESP boards in a small case that clips to the tripod/stan
**Pipeline:** `hardware/DESIGN_PIPELINE.md` **Pipeline:** `hardware/DESIGN_PIPELINE.md`
Four exported prototype files: Four exported prototype files:
1. **Case body** — holds both boards stacked, cable ports, rear dovetail-style receiver 1. **Case body** — holds both boards side-by-side with extra wiring/service clearance, cable ports, rear mounting boss
2. **Case lid** — screw-on cover with ventilation 2. **Case lid** — screw-on cover with ventilation and underside locating lip for flush seating
3. **Tripod clamp** — separate screw-tightened C-clamp sized around a 35mm stand/pole 3. **Tripod clamp** — separate screw-tightened C-clamp sized around a 35mm stand/pole
4. **Full preview** — combined visualization STL only, not intended as the print job 4. **Full preview** — combined visualization STL only, not intended as the print job
@@ -105,8 +105,11 @@ The ESP8266 and GoPro talk over Wi-Fi — **no data cable between them**. The on
| | W × D × H (mm) | | | W × D × H (mm) |
|---|---| |---|---|
| Case body external | ~56.8 × 38.2 × 19.0 | | Board envelope basis | ESP32-C3 Super Mini: 22.5 × 18.0; ESP-01S: 24.7 × 14.3 × 12.0 |
| Lid external | ~56.8 × 32.8 × 4.0 | | Internal CAD allowance | ~71.2 × 34.0 × 22.0; intentionally includes wiring gutters and vertical connector clearance |
| Tripod clamp | ~43.0 × 56.9 × 16.0 | | Case body external | ~76.0 × 42.6 × 26.0 including rear mount boss depth; main shell ~76.0 × 38.8 × 26.0 |
| Lid external | ~76.0 × 38.8 × 3.6; includes 1.6mm underside locating lip |
| Tripod clamp | ~43.0 × 53.5 × 16.0 |
| Clamp-to-case mount | Two side-by-side M3 screws through flat mounting plate |
| Clamp pole fit | Nominal 35mm; smaller poles TBD / may need inserts | | Clamp pole fit | Nominal 35mm; smaller poles TBD / may need inserts |
| Total weight | TBD after prototype print | | Total weight | TBD after prototype print |
Binary file not shown.
Binary file not shown.
Binary file not shown.
+94 -53
View File
@@ -1,26 +1,39 @@
// RemoteRig — Dual-ESP Tripod Case v3 // RemoteRig — Dual-ESP Tripod Case v3
// v3 changes: screw-tightened tripod clamp + dovetail slide interface. // v3e changes: board-specific envelope for ESP32-C3 Super Mini + ESP-01S with wiring clearance.
// Coordinate system: all case/lid geometry uses bottom-origin Z. // Coordinate system: all case/lid geometry uses bottom-origin Z.
$fn = 36; $fn = 36;
// Board dimensions // Board dimensions from selected modules.
esp8266_w = 34.2; esp8266_d = 25.6; esp8266_h = 5; // ESP32-C3 Super Mini: 22.5 x 18.0 mm footprint.
esp32_w = 52; esp32_d = 28; esp32_h = 5; // ESP-01S / ESP8266: 24.7 x 14.3 x 12.0 mm envelope.
board_gap = 3; // The case is intentionally larger than board footprints because the field
stack_h = esp8266_h + esp32_h + board_gap; // build needs room for Dupont/UART wiring, power leads, bend radius, and fingers.
inner_w = max(esp8266_w, esp32_w); esp32c3_w = 22.5; esp32c3_d = 18.0; esp32c3_h = 6.0; // height allowance includes headers/pins TBD
inner_d = max(esp8266_d, esp32_d); esp01s_w = 24.7; esp01s_d = 14.3; esp01s_h = 12.0;
inner_h = stack_h + 2; board_gap = 8.0; // side-by-side service gap between boards
wire_x = 8.0; // wiring gutter at left/right ends
wire_y = 8.0; // wiring gutter along front/back edges
wire_z = 10.0; // vertical wiring/connector clearance above tallest module
inner_w = esp32c3_w + esp01s_w + board_gap + wire_x*2;
inner_d = max(esp32c3_d, esp01s_d) + wire_y*2;
inner_h = max(esp32c3_h, esp01s_h) + wire_z;
// Case parameters // Case parameters
wall = 2.0; wall = 2.0;
tol = 0.4; tol = 0.4;
outer_w = inner_w + wall*2 + tol*2; // 56.8mm outer_w = inner_w + wall*2 + tol*2; // 76.0mm with current board/wiring envelope
outer_d = inner_d + wall*2 + tol*2; // 32.8mm outer_d = inner_d + wall*2 + tol*2; // 38.8mm with current board/wiring envelope
outer_h = inner_h + wall*2; // 19mm outer_h = inner_h + wall*2; // 26.0mm with current board/wiring envelope
corner_r = 2.5; corner_r = 2.5;
// Lid fit parameters
lid_top_thick = 2.0;
lid_lip_h = 1.6;
lid_clearance = 0.6; // clearance around underside locating lip
lid_lip_wall = 1.2; // thickness of perimeter lip/frame
// Tripod clamp parameters // Tripod clamp parameters
pole_dia = 35; // nominal stand/pole diameter pole_dia = 35; // nominal stand/pole diameter
clamp_thick = 4.0; // ring wall thickness clamp_thick = 4.0; // ring wall thickness
@@ -29,15 +42,16 @@ mouth_width = 13.0; // clamp opening
m3_clearance = 3.4; // M3 screw clearance m3_clearance = 3.4; // M3 screw clearance
nut_flat = 6.4; // M3 nut trap flat-to-flat nut_flat = 6.4; // M3 nut trap flat-to-flat
// Dovetail slide interface // Case ↔ clamp interface
// Male rail is on the case; matching female socket is on the tripod clamp. // v3b removes the dovetail: use a flat two-screw mounting plate instead.
// This is easier to inspect and avoids the previous mismatched "two lips + tab" geometry. // This is simpler to print, easier to inspect, and field-serviceable.
rail_z = outer_h * 0.78; mount_plate_w = 24.0;
rail_depth = 5.0; mount_plate_h = 16.0;
rail_neck_w = 12.0; // narrow width at case wall / slot opening mount_plate_thick = 4.0;
rail_outer_w = 18.0; // wider retained edge mount_hole_spacing = 14.0; // side-by-side M3 case-mount screws
rail_clearance = 0.45; // FDM sliding clearance per side-ish mount_screw_clear = 3.4; // M3 clearance through clamp plate
socket_wall = 2.2; mount_case_pilot = 2.7; // pilot/insert hole through case boss
mount_boss_r = 1.2;
// Cable ports // Cable ports
usb_port_w = 12; usb_port_h = 6; usb_port_w = 12; usb_port_h = 6;
@@ -107,15 +121,20 @@ module screw_post(x, y) {
} }
} }
module case_male_dovetail_rail() { module case_mount_boss() {
// Positive tapered rail on the case back. Cross-section is narrow at the // Flat rear boss on the case. The clamp plate bolts directly to this face.
// wall and wider at the outside, so the clamp socket captures it. // Holes run front/back (Y axis) for M3 screws, heat-set inserts, or nuts.
translate([0, outer_d/2 - 0.15, outer_h/2]) boss_y = outer_d/2 + mount_plate_thick/2 - 0.2;
dovetail_prism(rail_z, rail_neck_w, rail_outer_w, rail_depth); difference() {
translate([0, boss_y, outer_h/2])
rounded_cube_centered(mount_plate_w, mount_plate_thick, mount_plate_h, mount_boss_r);
// Bottom stop so the clamp socket cannot slide past the case. for (xoff = [-mount_hole_spacing/2, mount_hole_spacing/2]) {
translate([0, outer_d/2 + rail_depth/2, outer_h*0.12]) translate([xoff, outer_d/2 + mount_plate_thick/2, outer_h/2])
rounded_cube_centered(rail_outer_w + 3.0, rail_depth + 0.8, 2.4, 0.8); rotate([90, 0, 0])
cylinder(d=mount_case_pilot, h=mount_plate_thick + wall*3, center=true, $fn=24);
}
}
} }
module case_body() { module case_body() {
@@ -123,22 +142,48 @@ module case_body() {
case_shell(); case_shell();
for (x = [-1, 1], y = [-1, 1]) for (x = [-1, 1], y = [-1, 1])
screw_post(x*(outer_w/2 - 5), y*(outer_d/2 - 5)); screw_post(x*(outer_w/2 - 5), y*(outer_d/2 - 5));
case_male_dovetail_rail(); case_mount_boss();
} }
} }
module lid_locating_lip() {
// Thin underside frame that drops into the case opening. This registers the
// lid so it cannot skate/rock on the rim, while staying clear of screw posts.
lip_outer_w = inner_w + tol - lid_clearance;
lip_outer_d = inner_d + tol - lid_clearance;
lip_inner_w = lip_outer_w - lid_lip_wall*2;
lip_inner_d = lip_outer_d - lid_lip_wall*2;
translate([0, 0, -lid_lip_h])
difference() {
rounded_cube0(lip_outer_w, lip_outer_d, lid_lip_h, 1.0);
translate([0, 0, -0.1])
rounded_cube0(lip_inner_w, lip_inner_d, lid_lip_h + 0.2, 0.7);
// Corner reliefs so the lip doesn't interfere with screw posts.
for (x = [-1, 1], y = [-1, 1]) {
translate([x*(outer_w/2 - 5), y*(outer_d/2 - 5), lid_lip_h/2])
cylinder(d=7.0, h=lid_lip_h + 0.4, center=true, $fn=24);
}
}
}
module case_lid() { module case_lid() {
difference() { difference() {
rounded_cube0(outer_w, outer_d, wall*2, 1.8); union() {
// Thinner top cover; underside lip handles registration.
rounded_cube0(outer_w, outer_d, lid_top_thick, 0.8);
lid_locating_lip();
}
for (x = [-1, 1], y = [-1, 1]) { for (x = [-1, 1], y = [-1, 1]) {
translate([x*(outer_w/2 - 5), y*(outer_d/2 - 5), -0.5]) translate([x*(outer_w/2 - 5), y*(outer_d/2 - 5), -lid_lip_h - 0.5])
cylinder(d=2.4, h=wall*2 + 1, center=false, $fn=20); cylinder(d=2.4, h=lid_top_thick + lid_lip_h + 1, center=false, $fn=20);
} }
for (x = [-outer_w/4, 0, outer_w/4]) { for (x = [-outer_w/4, 0, outer_w/4]) {
translate([x, 0, wall*2/2]) translate([x, 0, lid_top_thick/2])
cube([8, outer_d*0.6, wall*3], center=true); cube([8, outer_d*0.6, lid_top_thick*3], center=true);
} }
} }
} }
@@ -147,7 +192,7 @@ module clamp_ring_with_mouth() {
outer_r = pole_dia/2 + clamp_thick; outer_r = pole_dia/2 + clamp_thick;
difference() { difference() {
cylinder(r=outer_r, h=clamp_width, center=true, $fn=72); cylinder(r=outer_r, h=clamp_width, center=true, $fn=72);
cylinder(r=pole_dia/2 + rail_clearance, h=clamp_width + 1, center=true, $fn=72); cylinder(r=pole_dia/2 + tol, h=clamp_width + 1, center=true, $fn=72);
// Mouth opens toward +Y. Width is intentionally generous for snap-on placement before tightening. // Mouth opens toward +Y. Width is intentionally generous for snap-on placement before tightening.
translate([0, outer_r, 0]) translate([0, outer_r, 0])
cube([mouth_width, outer_r*2, clamp_width + 2], center=true); cube([mouth_width, outer_r*2, clamp_width + 2], center=true);
@@ -174,25 +219,21 @@ module clamp_ears() {
} }
} }
module clamp_dovetail_socket() { module clamp_mount_plate() {
outer_r = pole_dia/2 + clamp_thick; outer_r = pole_dia/2 + clamp_thick;
socket_outer_w = rail_outer_w + socket_wall*2; plate_y = -outer_r - mount_plate_thick/2 + 0.2;
socket_depth = rail_depth + socket_wall*2;
// Solid boss on the rear of the clamp, opposite the tightening mouth. // Flat plate matching the case boss. Two M3 clearance holes pass through
// A matching dovetail void is cut through it along Z so the case rail // along Y so the clamp bolts to the case with ordinary hardware.
// slides in from the top/bottom with practical FDM clearance.
difference() { difference() {
translate([0, -outer_r - socket_depth/2 + socket_wall, 0]) translate([0, plate_y, 0])
rounded_cube_centered(socket_outer_w, socket_depth, clamp_width, 1.2); rounded_cube_centered(mount_plate_w, mount_plate_thick, mount_plate_h, mount_boss_r);
translate([0, -outer_r - 0.15, 0]) for (xoff = [-mount_hole_spacing/2, mount_hole_spacing/2]) {
dovetail_prism( translate([xoff, plate_y, 0])
clamp_width + 1.0, rotate([90, 0, 0])
rail_neck_w + rail_clearance, cylinder(d=mount_screw_clear, h=mount_plate_thick + 2, center=true, $fn=24);
rail_outer_w + rail_clearance, }
rail_depth + 0.6
);
} }
} }
@@ -200,7 +241,7 @@ module tripod_clamp() {
union() { union() {
clamp_ring_with_mouth(); clamp_ring_with_mouth();
clamp_ears(); clamp_ears();
clamp_dovetail_socket(); clamp_mount_plate();
} }
} }
@@ -211,7 +252,7 @@ module tripod_clip() {
module full_case() { module full_case() {
case_body(); case_body();
translate([0, 0, outer_h + 2]) case_lid(); translate([0, 0, outer_h]) case_lid();
translate([0, outer_d/2 + pole_dia/2 + clamp_thick + 8, outer_h/2]) translate([0, outer_d/2 + pole_dia/2 + clamp_thick + 8, outer_h/2])
rotate([90, 0, 0]) tripod_clamp(); rotate([90, 0, 0]) tripod_clamp();
} }
Binary file not shown.
-265
View File
@@ -1,265 +0,0 @@
package api
import (
"database/sql"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/cubecraft/remoterig/internal/db"
"github.com/go-chi/chi/v5"
_ "modernc.org/sqlite"
)
// openTestDB creates a file-based SQLite database with the schema applied
// manually, bypassing the migration splitter in db.Open.
func openTestDB(t *testing.T) *db.DB {
t.Helper()
f, err := os.CreateTemp("", "remoterig-api-test-*.db")
if err != nil {
t.Fatalf("create temp: %v", err)
}
path := f.Name()
f.Close()
t.Cleanup(func() { os.Remove(path) })
sqldb, err := sql.Open("sqlite", path)
if err != nil {
t.Fatalf("open db: %v", err)
}
// Apply pragmas
if _, err := sqldb.Exec("PRAGMA journal_mode=WAL"); err != nil {
t.Fatalf("WAL: %v", err)
}
if _, err := sqldb.Exec("PRAGMA foreign_keys=ON"); err != nil {
t.Fatalf("FK: %v", err)
}
// Apply schema directly
statements := []string{
`CREATE TABLE IF NOT EXISTS cameras (camera_id TEXT PRIMARY KEY, friendly_name TEXT NOT NULL, mac_address TEXT UNIQUE, created_at DATETIME NOT NULL DEFAULT (datetime('now')), updated_at DATETIME NOT NULL DEFAULT (datetime('now')))`,
`CREATE TABLE IF NOT EXISTS status_logs (id INTEGER PRIMARY KEY AUTOINCREMENT, camera_id TEXT NOT NULL REFERENCES cameras(camera_id), recorded_at DATETIME NOT NULL DEFAULT (datetime('now')), battery_pct INTEGER, video_remaining_sec INTEGER, recording_state INTEGER NOT NULL DEFAULT 0, mode TEXT, resolution TEXT, fps INTEGER, online INTEGER NOT NULL DEFAULT 1, raw_battery_pct REAL)`,
`CREATE TABLE IF NOT EXISTS recording_events (id INTEGER PRIMARY KEY AUTOINCREMENT, camera_id TEXT NOT NULL REFERENCES cameras(camera_id), started_at DATETIME NOT NULL, stopped_at DATETIME, reason TEXT, duration INTEGER)`,
`CREATE TABLE IF NOT EXISTS settings (key TEXT PRIMARY KEY, value TEXT NOT NULL, updated_at DATETIME NOT NULL DEFAULT (datetime('now')))`,
`CREATE INDEX IF NOT EXISTS idx_cameras_mac ON cameras(mac_address)`,
`CREATE INDEX IF NOT EXISTS idx_status_logs_camera_time ON status_logs(camera_id, recorded_at DESC)`,
`CREATE INDEX IF NOT EXISTS idx_recording_events_camera_time ON recording_events(camera_id, started_at DESC)`,
}
for _, stmt := range statements {
if _, err := sqldb.Exec(stmt); err != nil {
t.Fatalf("exec schema: %v\nstmt: %s", err, stmt[:min(len(stmt), 80)])
}
}
return &db.DB{DB: sqldb}
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
// seedTestCamera inserts a camera and optional status logs into the database.
func seedTestCamera(t *testing.T, database *db.DB, cameraID, friendlyName string, statusLogs int) {
t.Helper()
_, err := database.Exec(`
INSERT INTO cameras (camera_id, friendly_name, mac_address) VALUES (?, ?, ?)
`, cameraID, friendlyName, cameraID+"-mac")
if err != nil {
t.Fatalf("failed to seed camera: %v", err)
}
for i := 0; i < statusLogs; i++ {
online := 1
if i == 0 {
online = 0
}
_, err := database.Exec(`
INSERT INTO status_logs (camera_id, battery_pct, video_remaining_sec, recording_state, mode, resolution, fps, online, recorded_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, datetime('now', ? || ' minutes'))
`, cameraID, 80-i, 3600-i*100, i%2, "video", "4K", 30, online, fmt.Sprintf("-%d", i))
if err != nil {
t.Fatalf("failed to seed status_log %d: %v", i, err)
}
}
}
func TestGetCameraDetail_NotFound(t *testing.T) {
database := openTestDB(t)
defer database.Close()
handler := GetCameraDetail(database)
r := chi.NewRouter()
r.Get("/cameras/{id}", handler)
req := httptest.NewRequest(http.MethodGet, "/cameras/nonexistent", nil)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
if w.Code != http.StatusNotFound {
t.Errorf("expected status 404, got %d", w.Code)
}
var resp map[string]string
json.NewDecoder(w.Body).Decode(&resp)
if resp["error"] != "camera not found" {
t.Errorf("expected 'camera not found' error, got %q", resp["error"])
}
}
func TestGetCameraDetail_Success(t *testing.T) {
database := openTestDB(t)
defer database.Close()
seedTestCamera(t, database, "cam-1", "GoPro Hero", 3)
handler := GetCameraDetail(database)
r := chi.NewRouter()
r.Get("/cameras/{id}", handler)
req := httptest.NewRequest(http.MethodGet, "/cameras/cam-1", nil)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Fatalf("expected status 200, got %d, body: %s", w.Code, w.Body.String())
}
var resp map[string]interface{}
if err := json.NewDecoder(w.Body).Decode(&resp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
camera, ok := resp["camera"].(map[string]interface{})
if !ok {
t.Fatal("response missing 'camera' field")
}
if camera["camera_id"] != "cam-1" {
t.Errorf("expected camera_id 'cam-1', got %v", camera["camera_id"])
}
if camera["friendly_name"] != "GoPro Hero" {
t.Errorf("expected friendly_name 'GoPro Hero', got %v", camera["friendly_name"])
}
history, ok := resp["history"].([]interface{})
if !ok {
t.Fatal("response missing 'history' field or wrong type")
}
if len(history) != 3 {
t.Errorf("expected 3 history entries, got %d", len(history))
}
}
func TestGetCameraDetail_EmptyHistory(t *testing.T) {
database := openTestDB(t)
defer database.Close()
seedTestCamera(t, database, "cam-2", "Cam No Status", 0)
handler := GetCameraDetail(database)
r := chi.NewRouter()
r.Get("/cameras/{id}", handler)
req := httptest.NewRequest(http.MethodGet, "/cameras/cam-2", nil)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Fatalf("expected status 200, got %d", w.Code)
}
var resp map[string]interface{}
json.NewDecoder(w.Body).Decode(&resp)
history, ok := resp["history"].([]interface{})
if !ok {
t.Fatal("response missing 'history' field")
}
if len(history) != 0 {
t.Errorf("expected empty history, got %d entries", len(history))
}
}
func TestGetCameraDetail_HistoryLimitedTo100(t *testing.T) {
database := openTestDB(t)
defer database.Close()
seedTestCamera(t, database, "cam-3", "Verbose Cam", 105)
handler := GetCameraDetail(database)
r := chi.NewRouter()
r.Get("/cameras/{id}", handler)
req := httptest.NewRequest(http.MethodGet, "/cameras/cam-3", nil)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Fatalf("expected status 200, got %d", w.Code)
}
var resp map[string]interface{}
json.NewDecoder(w.Body).Decode(&resp)
history, ok := resp["history"].([]interface{})
if !ok {
t.Fatal("response missing 'history' field")
}
if len(history) > 100 {
t.Errorf("expected history capped at 100, got %d", len(history))
}
}
func TestGetCameraDetail_MissingID(t *testing.T) {
database := openTestDB(t)
defer database.Close()
handler := GetCameraDetail(database)
// Without a chi router, chi.URLParam returns "", triggering the 400 branch
req := httptest.NewRequest(http.MethodGet, "/cameras/", nil)
w := httptest.NewRecorder()
handler.ServeHTTP(w, req)
if w.Code != http.StatusBadRequest {
t.Errorf("expected status 400, got %d", w.Code)
}
}
func TestGetCameraDetail_LastStatusPresent(t *testing.T) {
database := openTestDB(t)
defer database.Close()
seedTestCamera(t, database, "cam-4", "Status Cam", 2)
handler := GetCameraDetail(database)
r := chi.NewRouter()
r.Get("/cameras/{id}", handler)
req := httptest.NewRequest(http.MethodGet, "/cameras/cam-4", nil)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Fatalf("expected status 200, got %d", w.Code)
}
var resp map[string]interface{}
json.NewDecoder(w.Body).Decode(&resp)
lastStatus, ok := resp["last_status"].(map[string]interface{})
if !ok {
t.Fatal("response missing 'last_status' field or wrong type")
}
if lastStatus["camera_id"] != "cam-4" {
t.Errorf("expected last_status camera_id 'cam-4', got %v", lastStatus["camera_id"])
}
}
-49
View File
@@ -1,49 +0,0 @@
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
}