Files
uptimesebi/internal/store/results_test.go
Sebastian UnterschützandClaude Opus 5.5 00658d49a2 feat(store): add monitors, regions, agents and check result hypertable
check_results has no row-level security because TimescaleDB refuses
compression and continuous aggregates on such tables. Every results
query takes org_id as a parameter, which a test enforces.

Refs #10, #13

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-22 01:12:53 +01:00

31 lines
751 B
Go

package store
import (
"os"
"regexp"
"strings"
"testing"
)
// TestResultQueriesFilterByOrg guards the tables that cannot use row-level
// security: every read of check results must be restricted to one org.
func TestResultQueriesFilterByOrg(t *testing.T) {
src, err := os.ReadFile("queries/check_results.sql")
if err != nil {
t.Fatal(err)
}
blocks := regexp.MustCompile(`(?m)^-- name: `).Split(string(src), -1)[1:]
if len(blocks) == 0 {
t.Fatal("no queries found")
}
for _, b := range blocks {
name, _, _ := strings.Cut(b, " ")
if strings.Contains(b, ":copyfrom") {
continue
}
if !regexp.MustCompile(`(?i)WHERE[^;]*\borg_id\s*=\s*\$1`).MatchString(b) {
t.Errorf("query %s does not filter by org_id = $1", name)
}
}
}