1
0
mirror of https://github.com/juanfont/headscale.git synced 2025-08-10 13:46:46 +02:00

integration/hsic: add SQLite schema validation before extraction

- Check if database file exists at expected path
- Verify database has actual schema/tables using sqlite3 command
- Show file size and schema preview in logs
- Error early if database is empty/uninitialized instead of extracting empty file

This will help identify whether the issue is:
- Missing database file
- Empty/uninitialized database
- Database created but not populated
This commit is contained in:
Kristoffer Dalby 2025-06-19 17:44:41 +02:00
parent 0fc88c4f68
commit e23feb6ada
No known key found for this signature in database

View File

@ -659,6 +659,31 @@ func (t *HeadscaleInContainer) SaveDatabase(savePath string) error {
log.Printf("SQLite files found in %s:\n%s", t.hostname, sqliteFiles)
}
// Check if the database file exists and has a schema
dbPath := "/tmp/integration_test_db.sqlite3"
fileInfo, err := t.Execute([]string{"ls", "-la", dbPath})
if err != nil {
return fmt.Errorf("database file does not exist at %s: %w", dbPath, err)
}
log.Printf("Database file info: %s", fileInfo)
// Check if the database has any tables (schema)
schemaCheck, err := t.Execute([]string{"sqlite3", dbPath, ".schema"})
if err != nil {
return fmt.Errorf("failed to check database schema (sqlite3 command failed): %w", err)
}
if strings.TrimSpace(schemaCheck) == "" {
return fmt.Errorf("database file exists but has no schema (empty database)")
}
// Show a preview of the schema (first 500 chars)
schemaPreview := schemaCheck
if len(schemaPreview) > 500 {
schemaPreview = schemaPreview[:500] + "..."
}
log.Printf("Database schema preview:\n%s", schemaPreview)
tarFile, err := t.FetchPath("/tmp/integration_test_db.sqlite3")
if err != nil {
return fmt.Errorf("failed to fetch database file: %w", err)