package host import ( "strings" "testing" "time" "github.com/carlosframework/platform/internal/metrics" ) func TestGeoIPAlertSentences(t *testing.T) { for code, want := range map[float64]string{ 1: "more than 45 days old", 2: "expires within 9 days", 3: "has expired and was removed", 4: "has not loaded the published geoip database", 5: "has failed 7 times in a row", } { if got := alertSentence(metrics.Event{Rule: "geoip", Firing: true, Value: code, Box: "b"}); !strings.Contains(got, want) { t.Errorf("code %v = %q, want %q", code, got, want) } } if got := alertClearSentence(metrics.Event{Rule: "geoip", Box: "b"}); got != "geoip on b is back to normal" { t.Errorf("clear = %q", got) } if geoIPAlertReading(time.Now()) != nil { t.Error("no edge published must mean no reading") } }