Skip to content

Commit a18a473

Browse files
Remove obsolete test
We have since replaced all the calls to log.Print and log.Fatal Signed-off-by: Richard Wall <[email protected]>
1 parent aa12acc commit a18a473

File tree

1 file changed

+0
-43
lines changed

1 file changed

+0
-43
lines changed

pkg/logs/logs_test.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -371,46 +371,3 @@ func Test_replaceWithStaticTimestamps(t *testing.T) {
371371
})
372372
}
373373
}
374-
375-
func TestLogToSlogWriter(t *testing.T) {
376-
// This test makes sure that all the agent's remaining Log calls are correctly
377-
// translated to slog.Error calls where appropriate.
378-
//
379-
// This list was generated using:
380-
// git grep -i "log\.\(print\|fatal\)" pkg/ cmd/ | fgrep -e error -e failed
381-
given := strings.TrimPrefix(`
382-
failed to complete initial sync of %q data gatherer %q: %v
383-
error messages will not show in the pod's events because the POD_NAME environment variable is empty
384-
retrying in %v after error: %s
385-
datagatherer informer for %q has failed and is backing off due to error: %s
386-
this is a happy log that should show as INFO`, "\n")
387-
expect := strings.TrimPrefix(`
388-
level=ERROR msg="failed to complete initial sync of %q data gatherer %q: %v" source=agent
389-
level=ERROR msg="error messages will not show in the pod's events because the POD_NAME environment variable is empty" source=agent
390-
level=ERROR msg="retrying in %v after error: %s" source=agent
391-
level=ERROR msg="datagatherer informer for %q has failed and is backing off due to error: %s" source=agent
392-
level=INFO msg="this is a happy log that should show as INFO" source=agent
393-
`, "\n")
394-
395-
gotBuf := &bytes.Buffer{}
396-
slogHandler := slog.NewTextHandler(gotBuf, &slog.HandlerOptions{
397-
// Remove the timestamp from the logs so that we can compare them.
398-
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
399-
if a.Key == "time" {
400-
return slog.Attr{}
401-
}
402-
return a
403-
},
404-
})
405-
slogLogger := slog.New(slogHandler)
406-
407-
logger := log.New(&bytes.Buffer{}, "", 0)
408-
logger.SetOutput(logs.LogToSlogWriter{Slog: slogLogger, Source: "agent"})
409-
410-
for _, line := range strings.Split(given, "\n") {
411-
// Simulate the current agent's logs.
412-
logger.Print(line)
413-
}
414-
415-
assert.Equal(t, expect, gotBuf.String())
416-
}

0 commit comments

Comments
 (0)