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>
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package app
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.mixdep.ru/mix/gosentry/src/domain"
|
|
"gitea.mixdep.ru/mix/gosentry/src/storage"
|
|
)
|
|
|
|
func newTestService(jobs []domain.Job) *Service {
|
|
return NewService(&storage.Store{}, jobs)
|
|
}
|
|
|
|
func TestNewServiceBuildsRuntimePerJob(t *testing.T) {
|
|
jobs := []domain.Job{
|
|
{ID: 1, Name: "Enabled", Enabled: true},
|
|
{ID: 2, Name: "Disabled", Enabled: false},
|
|
}
|
|
svc := newTestService(jobs)
|
|
|
|
if got := svc.Runtime(1); got == nil {
|
|
t.Fatal("expected runtime for enabled job 1")
|
|
} else if got.LastState != "Ready" {
|
|
t.Errorf("enabled job runtime state = %q, want %q", got.LastState, "Ready")
|
|
}
|
|
if got := svc.Runtime(2); got == nil {
|
|
t.Fatal("expected runtime for disabled job 2")
|
|
} else if got.LastState != "Paused" {
|
|
t.Errorf("disabled job runtime state = %q, want %q", got.LastState, "Paused")
|
|
}
|
|
if got := svc.Runtime(99); got != nil {
|
|
t.Errorf("expected nil runtime for unknown job, got %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestJobsReturnsCopy(t *testing.T) {
|
|
jobs := []domain.Job{{ID: 1, Name: "Original"}}
|
|
svc := newTestService(jobs)
|
|
|
|
snapshot := svc.Jobs()
|
|
if len(snapshot) != 1 {
|
|
t.Fatalf("Jobs() len = %d, want 1", len(snapshot))
|
|
}
|
|
// Mutating the returned slice must not affect Service-owned state.
|
|
snapshot[0].Name = "Mutated"
|
|
if again := svc.Jobs(); again[0].Name != "Original" {
|
|
t.Errorf("Service state leaked through Jobs(): name = %q, want %q", again[0].Name, "Original")
|
|
}
|
|
}
|