MCPcopy Create free account
hub / github.com/ddev/ddev / TestWarningOnce

Function TestWarningOnce

pkg/util/utils_test.go:305–337  ·  view source on GitHub ↗

TestWarningOnce tests that WarningOnce only shows each unique message once

(t *testing.T)

Source from the content-addressed store, hash-verified

303
304// TestWarningOnce tests that WarningOnce only shows each unique message once
305func TestWarningOnce(t *testing.T) {
306 assert := asrt.New(t)
307
308 // Capture output to test warning messages (warnings go to UserErr)
309 restoreOutput := util.CaptureUserErr()
310
311 // Test that same message is only shown once
312 util.WarningOnce("test warning message")
313 util.WarningOnce("test warning message")
314 util.WarningOnce("test warning message")
315
316 // Test that different messages are both shown
317 util.WarningOnce("different warning message")
318
319 out := restoreOutput()
320
321 // Should contain each unique message only once
322 assert.Equal(1, strings.Count(out, "test warning message"))
323 assert.Equal(1, strings.Count(out, "different warning message"))
324
325 // Test with format arguments
326 restoreOutput = util.CaptureUserErr()
327
328 util.WarningOnce("warning with %s", "arg1")
329 util.WarningOnce("warning with %s", "arg1")
330 util.WarningOnce("warning with %s", "arg2")
331
332 out = restoreOutput()
333
334 // Should show each formatted message once
335 assert.Equal(1, strings.Count(out, "warning with arg1"))
336 assert.Equal(1, strings.Count(out, "warning with arg2"))
337}
338
339// TestSubtractSlices does simple test of SubtractSlices
340func TestSubtractSlices(t *testing.T) {

Callers

nothing calls this directly

Calls 3

CaptureUserErrFunction · 0.92
WarningOnceFunction · 0.92
CountMethod · 0.80

Tested by

no test coverage detected