mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-18 07:13:50 +01:00
refactor: use stretchr/testify, replace ExpectBytesEqual and ExpectDeepEqual with ExpectEqual in tests
This commit is contained in:
@@ -36,11 +36,11 @@ func TestNewConfig(t *testing.T) {
|
||||
ExpectEqual(t, config.BufferSize, 10)
|
||||
ExpectEqual(t, config.Format, FormatCombined)
|
||||
ExpectEqual(t, config.Path, "/tmp/access.log")
|
||||
ExpectDeepEqual(t, config.Filters.StatusCodes.Values, []*StatusCodeRange{{Start: 200, End: 299}})
|
||||
ExpectEqual(t, config.Filters.StatusCodes.Values, []*StatusCodeRange{{Start: 200, End: 299}})
|
||||
ExpectEqual(t, len(config.Filters.Method.Values), 2)
|
||||
ExpectDeepEqual(t, config.Filters.Method.Values, []HTTPMethod{"GET", "POST"})
|
||||
ExpectEqual(t, config.Filters.Method.Values, []HTTPMethod{"GET", "POST"})
|
||||
ExpectEqual(t, len(config.Filters.Headers.Values), 2)
|
||||
ExpectDeepEqual(t, config.Filters.Headers.Values, []*HTTPHeader{{Key: "foo", Value: "bar"}, {Key: "baz", Value: ""}})
|
||||
ExpectEqual(t, config.Filters.Headers.Values, []*HTTPHeader{{Key: "foo", Value: "bar"}, {Key: "baz", Value: ""}})
|
||||
ExpectTrue(t, config.Filters.Headers.Negative)
|
||||
ExpectEqual(t, len(config.Filters.CIDR.Values), 1)
|
||||
ExpectEqual(t, config.Filters.CIDR.Values[0].String(), "192.168.10.0/24")
|
||||
|
||||
@@ -15,7 +15,7 @@ func TestAccessLoggerJSONKeepHeaders(t *testing.T) {
|
||||
entry := getJSONEntry(t, config)
|
||||
for k, v := range req.Header {
|
||||
if k != "Cookie" {
|
||||
ExpectDeepEqual(t, entry.Headers[k], v)
|
||||
ExpectEqual(t, entry.Headers[k], v)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ func TestAccessLoggerJSONKeepHeaders(t *testing.T) {
|
||||
"User-Agent": FieldModeDrop,
|
||||
}
|
||||
entry = getJSONEntry(t, config)
|
||||
ExpectDeepEqual(t, entry.Headers["Referer"], []string{RedactedValue})
|
||||
ExpectDeepEqual(t, entry.Headers["User-Agent"], nil)
|
||||
ExpectEqual(t, entry.Headers["Referer"], []string{RedactedValue})
|
||||
ExpectEqual(t, entry.Headers["User-Agent"], nil)
|
||||
}
|
||||
|
||||
func TestAccessLoggerJSONDropHeaders(t *testing.T) {
|
||||
@@ -33,7 +33,7 @@ func TestAccessLoggerJSONDropHeaders(t *testing.T) {
|
||||
config.Fields.Headers.Default = FieldModeDrop
|
||||
entry := getJSONEntry(t, config)
|
||||
for k := range req.Header {
|
||||
ExpectDeepEqual(t, entry.Headers[k], nil)
|
||||
ExpectEqual(t, entry.Headers[k], nil)
|
||||
}
|
||||
|
||||
config.Fields.Headers.Config = map[string]FieldMode{
|
||||
@@ -41,8 +41,8 @@ func TestAccessLoggerJSONDropHeaders(t *testing.T) {
|
||||
"User-Agent": FieldModeRedact,
|
||||
}
|
||||
entry = getJSONEntry(t, config)
|
||||
ExpectDeepEqual(t, entry.Headers["Referer"], []string{req.Header.Get("Referer")})
|
||||
ExpectDeepEqual(t, entry.Headers["User-Agent"], []string{RedactedValue})
|
||||
ExpectEqual(t, entry.Headers["Referer"], []string{req.Header.Get("Referer")})
|
||||
ExpectEqual(t, entry.Headers["User-Agent"], []string{RedactedValue})
|
||||
}
|
||||
|
||||
func TestAccessLoggerJSONRedactHeaders(t *testing.T) {
|
||||
@@ -52,7 +52,7 @@ func TestAccessLoggerJSONRedactHeaders(t *testing.T) {
|
||||
ExpectEqual(t, len(entry.Headers["Cookie"]), 0)
|
||||
for k := range req.Header {
|
||||
if k != "Cookie" {
|
||||
ExpectDeepEqual(t, entry.Headers[k], []string{RedactedValue})
|
||||
ExpectEqual(t, entry.Headers[k], []string{RedactedValue})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,14 +83,14 @@ func TestAccessLoggerJSONDropQuery(t *testing.T) {
|
||||
config := DefaultConfig()
|
||||
config.Fields.Query.Default = FieldModeDrop
|
||||
entry := getJSONEntry(t, config)
|
||||
ExpectDeepEqual(t, entry.Query["foo"], nil)
|
||||
ExpectDeepEqual(t, entry.Query["bar"], nil)
|
||||
ExpectEqual(t, entry.Query["foo"], nil)
|
||||
ExpectEqual(t, entry.Query["bar"], nil)
|
||||
}
|
||||
|
||||
func TestAccessLoggerJSONRedactQuery(t *testing.T) {
|
||||
config := DefaultConfig()
|
||||
config.Fields.Query.Default = FieldModeRedact
|
||||
entry := getJSONEntry(t, config)
|
||||
ExpectDeepEqual(t, entry.Query["foo"], []string{RedactedValue})
|
||||
ExpectDeepEqual(t, entry.Query["bar"], []string{RedactedValue})
|
||||
ExpectEqual(t, entry.Query["foo"], []string{RedactedValue})
|
||||
ExpectEqual(t, entry.Query["bar"], []string{RedactedValue})
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func TestParseRetention(t *testing.T) {
|
||||
if !test.shouldErr {
|
||||
ExpectNoError(t, err)
|
||||
} else {
|
||||
ExpectDeepEqual(t, r, test.expected)
|
||||
ExpectEqual(t, r, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -45,9 +45,9 @@ func TestModifyRequest(t *testing.T) {
|
||||
t.Run("set_options", func(t *testing.T) {
|
||||
mr, err := ModifyRequest.New(opts)
|
||||
ExpectNoError(t, err)
|
||||
ExpectDeepEqual(t, mr.impl.(*modifyRequest).SetHeaders, opts["set_headers"].(map[string]string))
|
||||
ExpectDeepEqual(t, mr.impl.(*modifyRequest).AddHeaders, opts["add_headers"].(map[string]string))
|
||||
ExpectDeepEqual(t, mr.impl.(*modifyRequest).HideHeaders, opts["hide_headers"].([]string))
|
||||
ExpectEqual(t, mr.impl.(*modifyRequest).SetHeaders, opts["set_headers"].(map[string]string))
|
||||
ExpectEqual(t, mr.impl.(*modifyRequest).AddHeaders, opts["add_headers"].(map[string]string))
|
||||
ExpectEqual(t, mr.impl.(*modifyRequest).HideHeaders, opts["hide_headers"].([]string))
|
||||
})
|
||||
|
||||
t.Run("request_headers", func(t *testing.T) {
|
||||
|
||||
@@ -48,9 +48,9 @@ func TestModifyResponse(t *testing.T) {
|
||||
t.Run("set_options", func(t *testing.T) {
|
||||
mr, err := ModifyResponse.New(opts)
|
||||
ExpectNoError(t, err)
|
||||
ExpectDeepEqual(t, mr.impl.(*modifyResponse).SetHeaders, opts["set_headers"].(map[string]string))
|
||||
ExpectDeepEqual(t, mr.impl.(*modifyResponse).AddHeaders, opts["add_headers"].(map[string]string))
|
||||
ExpectDeepEqual(t, mr.impl.(*modifyResponse).HideHeaders, opts["hide_headers"].([]string))
|
||||
ExpectEqual(t, mr.impl.(*modifyResponse).SetHeaders, opts["set_headers"].(map[string]string))
|
||||
ExpectEqual(t, mr.impl.(*modifyResponse).AddHeaders, opts["add_headers"].(map[string]string))
|
||||
ExpectEqual(t, mr.impl.(*modifyResponse).HideHeaders, opts["hide_headers"].([]string))
|
||||
})
|
||||
|
||||
t.Run("response_headers", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user