Say a secret given in plain words, and log words the keeper refuses
The secret-given condition's explanation carried a clock time, which the
plain rule refuses, so the operator read the scope's fallback ("needs a
look") instead of what changed. Its words now carry no time and say the
secret's name as words; a test holds them to the rule through a keeper.
With no test hook set, the keeper logs a refused or missing wording once
per kind and reason, so a fallback is never silent again (hq issue 359).
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package conditions
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -245,3 +248,26 @@ func TestAChangeOfWordsIsSaid(t *testing.T) {
|
||||
t.Fatalf("%+v", said)
|
||||
}
|
||||
}
|
||||
|
||||
// **Words that fall back are never silent** (hq issue 359): with no test listening, the keeper logs which
|
||||
// kind is said in borrowed words and why — once, however often the condition is observed.
|
||||
func TestBorrowedWordsAreLogged(t *testing.T) {
|
||||
k, _, _, _ := keeper(t)
|
||||
before := Unworded
|
||||
Unworded = nil
|
||||
t.Cleanup(func() { Unworded = before })
|
||||
var out bytes.Buffer
|
||||
log.SetOutput(&out)
|
||||
t.Cleanup(func() { log.SetOutput(os.Stderr) })
|
||||
for i := 0; i < 3; i++ {
|
||||
if _, err := k.Observe(t.Context(), Observation{Scope: ScopeMachine, ID: "ace", Kind: "test-clock", Machine: "ace",
|
||||
Severity: Warning, Source: "test", Summary: "s", Headline: "ace was given a secret",
|
||||
Explanation: "It was given at 23:32.", Resolved: "Seen"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if got := out.String(); strings.Count(got, "\n") != 1 || !strings.Contains(got, `"test-clock"`) ||
|
||||
!strings.Contains(got, "a clock time or date") {
|
||||
t.Errorf("the log said %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user