bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/database/test/silence_test.go (about) 1 package dbtest 2 3 import ( 4 "testing" 5 "time" 6 7 "bosun.org/models" 8 ) 9 10 func TestSilence(t *testing.T) { 11 sd := testData.Silence() 12 13 silence := &models.Silence{ 14 Start: time.Now().Add(-48 * time.Hour), 15 End: time.Now().Add(5 * time.Hour), 16 Alert: "Foo", 17 } 18 future := &models.Silence{ 19 Start: time.Now().Add(1 * time.Hour), 20 End: time.Now().Add(2 * time.Hour), 21 Alert: "Foo", 22 } 23 past := &models.Silence{ 24 Start: time.Now().Add(-48 * time.Hour), 25 End: time.Now().Add(-5 * time.Hour), 26 Alert: "Foo", 27 } 28 29 check(t, sd.AddSilence(silence)) 30 check(t, sd.AddSilence(past)) 31 check(t, sd.AddSilence(future)) 32 33 active, err := sd.GetActiveSilences() 34 check(t, err) 35 if len(active) != 1 { 36 t.Fatalf("Expected only one active silence. Got %d.", len(active)) 37 } 38 39 }