Files
go-otel/internal/issues/statusstore_test.go
T
mats e790c02d59
Build and Publish / Metadata (push) Successful in 9s
Build and Publish / BuildAndDeployAmd64 (push) Failing after 2m11s
fixes
2026-09-21 19:51:43 +02:00

51 lines
1.4 KiB
Go

package issues
import (
"context"
"path/filepath"
"testing"
"time"
)
func TestTriagePersistsAcrossRestart(t *testing.T) {
path := filepath.Join(t.TempDir(), "status.json")
store, _ := NewFileStatusStore(path)
tr := NewTracker()
if err := tr.SetStatusStore(context.Background(), store); err != nil {
t.Fatal(err)
}
tr.Record("span", "svc", "boom", Sample{Timestamp: 1})
id := Fingerprint("span", "svc", NormalizeTitle("boom"))
if _, ok := tr.SetStatus(id, StatusIgnored); !ok {
t.Fatal("set status")
}
time.Sleep(100 * time.Millisecond) // async save
// "Restart": fresh tracker, same file.
store2, err := NewFileStatusStore(path)
if err != nil {
t.Fatal(err)
}
tr2 := NewTracker()
if err := tr2.SetStatusStore(context.Background(), store2); err != nil {
t.Fatal(err)
}
tr2.Record("span", "svc", "boom", Sample{Timestamp: 2})
got, _ := tr2.Get(id)
if got.Status != StatusIgnored {
t.Fatalf("status after restart = %q, want ignored", got.Status)
}
}
func TestResolvedIssueRegresses(t *testing.T) {
tr := NewTracker()
tr.Record("span", "svc", "boom", Sample{Timestamp: 1})
id := Fingerprint("span", "svc", NormalizeTitle("boom"))
tr.SetStatus(id, StatusResolved)
tr.Record("span", "svc", "boom", Sample{Timestamp: 5})
got, _ := tr.Get(id)
if got.Status != StatusOpen || got.RegressedAt != 5 {
t.Fatalf("got status=%q regressedAt=%d", got.Status, got.RegressedAt)
}
}