Go service (nasmon/) plus nfpm packaging (packaging/), carried over from the home_nas monorepo. Adds rpm packaging alongside the existing deb build (Fedora/RHEL/Rocky dependency names via nfpm overrides, per-format systemd unit path, dpkg+rpm-compatible maintainer scripts) and a Gitea Actions workflow that builds both formats on every push. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package store
|
|
|
|
import (
|
|
"database/sql"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// TestMigrateOldAlertsTable opens a database created by the first release
|
|
// (no acked_at column) and checks that the column is added.
|
|
func TestMigrateOldAlertsTable(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "old.db")
|
|
db, err := sql.Open("sqlite", path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, err = db.Exec(`CREATE TABLE alerts (id INTEGER PRIMARY KEY, key TEXT NOT NULL, level TEXT NOT NULL, title TEXT NOT NULL,
|
|
detail TEXT NOT NULL, opened_at INTEGER NOT NULL, resolved_at INTEGER, last_notified_at INTEGER);
|
|
INSERT INTO alerts(key, level, title, detail, opened_at) VALUES('k', 'warn', 't', 'd', 1)`)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
db.Close()
|
|
|
|
st, err := Open(path)
|
|
if err != nil {
|
|
t.Fatalf("open with migration: %v", err)
|
|
}
|
|
defer st.Close()
|
|
open, err := st.OpenAlerts()
|
|
if err != nil || len(open) != 1 || open[0].Acked() {
|
|
t.Fatalf("after migration: %+v %v", open, err)
|
|
}
|
|
if err := st.AckAlert(open[0].ID, time.Now()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
act, _ := st.ActiveAlerts()
|
|
if len(act) != 0 {
|
|
t.Fatalf("acked alert listed as active")
|
|
}
|
|
// opening again must not fail (column already there)
|
|
st2, err := Open(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
st2.Close()
|
|
}
|