28f0a0d8e2
Item 4 of the test-suite review: - Delete TestEmitWithNoObserversIsNoop (no assertion; ranging a nil slice cannot panic) and TestStoreReturnsWiredStore (a getter returning its own field). - Collapse the four TestFilteredJobIndexes* tests into one table-driven TestFilteredJobIndexes, matching TestFilterValue above it. - Replace the TestMainViewBuilds smoke test with TestMainViewRecordStartupAddsHistoryRow, which calls the recordStartup closure for both wordings run.go selects between and asserts the rows reach the History table through its own cell callbacks. Keeps the unique coverage the review identified and adds the !windowShown branch. Item 5 is declined with measurements: the three RunJob tests cost 0.14 s combined, so merging them saves ~90 ms while forcing their three fixtures (including the only Manual trigger) into one. The runner package's runtime is the two timeout tests, not subprocess spawns. go vet and go test -race pass for src/app and src/ui. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package app
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.mixdep.ru/mix/gosentry/src/domain"
|
|
)
|
|
|
|
func TestEmitDeliversToAllObserversInOrder(t *testing.T) {
|
|
svc := newTestService(nil)
|
|
|
|
var first, second []Event
|
|
svc.Subscribe(ObserverFunc(func(e Event) { first = append(first, e) }))
|
|
svc.Subscribe(ObserverFunc(func(e Event) { second = append(second, e) }))
|
|
|
|
svc.emit(JobChanged{JobID: 7})
|
|
svc.emit(RunRecorded{Record: domain.RunRecord{JobID: 7, State: "Success"}})
|
|
svc.emit(SchedulerStateChanged{Paused: true})
|
|
|
|
for name, got := range map[string][]Event{"first": first, "second": second} {
|
|
if len(got) != 3 {
|
|
t.Fatalf("%s observer got %d events, want 3", name, len(got))
|
|
}
|
|
if jc, ok := got[0].(JobChanged); !ok || jc.JobID != 7 {
|
|
t.Errorf("%s event[0] = %#v, want JobChanged{JobID:7}", name, got[0])
|
|
}
|
|
if rr, ok := got[1].(RunRecorded); !ok || rr.Record.State != "Success" {
|
|
t.Errorf("%s event[1] = %#v, want RunRecorded Success", name, got[1])
|
|
}
|
|
if ss, ok := got[2].(SchedulerStateChanged); !ok || !ss.Paused {
|
|
t.Errorf("%s event[2] = %#v, want SchedulerStateChanged{Paused:true}", name, got[2])
|
|
}
|
|
}
|
|
}
|
|
|
|
// Observers may read Service state from within OnEvent without deadlocking,
|
|
// because emit is called outside the state lock.
|
|
func TestObserverCanReadServiceState(t *testing.T) {
|
|
jobs := []domain.Job{{ID: 1, Name: "Job", Enabled: true}}
|
|
svc := newTestService(jobs)
|
|
|
|
var sawName string
|
|
svc.Subscribe(ObserverFunc(func(Event) {
|
|
if snapshot := svc.Jobs(); len(snapshot) == 1 {
|
|
sawName = snapshot[0].Name
|
|
}
|
|
}))
|
|
|
|
svc.emit(JobChanged{JobID: 1})
|
|
if sawName != "Job" {
|
|
t.Errorf("observer read name = %q, want %q", sawName, "Job")
|
|
}
|
|
}
|