Add storage block geometry to audit and viewer
This commit is contained in:
@@ -1016,6 +1016,39 @@ func TestViewerRendersLatestSnapshot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestViewerRendersDerivedStorageBlockFormat(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "audit.json")
|
||||
body := `{
|
||||
"collected_at":"2026-04-29T00:05:00Z",
|
||||
"hardware":{
|
||||
"board":{"serial_number":"SERIAL-NEW"},
|
||||
"storage":[
|
||||
{
|
||||
"serial_number":"DISK-1",
|
||||
"model":"Test NVMe",
|
||||
"logical_block_size_bytes":512,
|
||||
"physical_block_size_bytes":4096,
|
||||
"metadata_bytes_per_block":8
|
||||
}
|
||||
]
|
||||
}
|
||||
}`
|
||||
if err := os.WriteFile(path, []byte(body), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
handler := NewHandler(HandlerOptions{AuditPath: path})
|
||||
rec := httptest.NewRecorder()
|
||||
handler.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/viewer", nil))
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status=%d", rec.Code)
|
||||
}
|
||||
if !strings.Contains(rec.Body.String(), "512+8") {
|
||||
t.Fatalf("viewer body missing derived block format: %s", rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuditJSONServesLatestSnapshot(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "audit.json")
|
||||
@@ -1038,6 +1071,36 @@ func TestAuditJSONServesLatestSnapshot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuditJSONDoesNotInjectDerivedStorageBlockFormat(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "audit.json")
|
||||
body := `{
|
||||
"hardware":{
|
||||
"board":{"serial_number":"SERIAL-API"},
|
||||
"storage":[
|
||||
{
|
||||
"serial_number":"DISK-1",
|
||||
"logical_block_size_bytes":512,
|
||||
"metadata_bytes_per_block":8
|
||||
}
|
||||
]
|
||||
}
|
||||
}`
|
||||
if err := os.WriteFile(path, []byte(body), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
handler := NewHandler(HandlerOptions{AuditPath: path})
|
||||
rec := httptest.NewRecorder()
|
||||
handler.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/audit.json", nil))
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status=%d", rec.Code)
|
||||
}
|
||||
if strings.Contains(rec.Body.String(), "block_format") {
|
||||
t.Fatalf("audit.json should remain contract-only: %s", rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestMissingAuditJSONReturnsNotFound(t *testing.T) {
|
||||
handler := NewHandler(HandlerOptions{AuditPath: "/missing/audit.json"})
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
Reference in New Issue
Block a user