diff --git a/pkg/common/utils/utils_test.go b/pkg/common/utils/utils_test.go index 92873b51d..225d8e42e 100644 --- a/pkg/common/utils/utils_test.go +++ b/pkg/common/utils/utils_test.go @@ -49,7 +49,34 @@ import ( // test assert func func TestUtilsAssert(t *testing.T) { - // nothing to test + assertPanic := func() (panicked bool) { + defer func() { + if r := recover(); r != nil { + panicked = true + } + }() + Assert(false, "should panic") + return false + } + + // Checking if the assertPanic function results in a panic as expected. + // We expect a true value because it should panic. + assert.DeepEqual(t, true, assertPanic()) + + // Checking if a true assertion does not result in a panic. + // We create a wrapper around Assert to capture if it panics when it should not. + noPanic := func() (panicked bool) { + defer func() { + if r := recover(); r != nil { + panicked = true + } + }() + Assert(true, "should not panic") + return false + } + + // We expect a false value because it should not panic. + assert.DeepEqual(t, false, noPanic()) } func TestUtilsIsTrueString(t *testing.T) { @@ -142,3 +169,18 @@ func TestFilterContentType(t *testing.T) { contentType = FilterContentType(contentType) assert.DeepEqual(t, "text/plain", contentType) } + +func TestNormalizeHeaderKeyEdgeCases(t *testing.T) { + empty := []byte("") + NormalizeHeaderKey(empty, false) + assert.DeepEqual(t, []byte(""), empty) + NormalizeHeaderKey(empty, true) + assert.DeepEqual(t, []byte(""), empty) +} + +func TestFilterContentTypeEdgeCases(t *testing.T) { + simpleContentType := "text/plain" + assert.DeepEqual(t, "text/plain", FilterContentType(simpleContentType)) + complexContentType := "text/html; charset=utf-8; format=flowed" + assert.DeepEqual(t, "text/html", FilterContentType(complexContentType)) +}