mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
common/helpers: opt-in for custom formatters for diff
Many stuff has a `String()` method that would hide details.
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -28,9 +29,14 @@ import (
|
||||
|
||||
var prettyC = pretty.Config{
|
||||
Diffable: true,
|
||||
PrintStringers: true,
|
||||
PrintStringers: false,
|
||||
SkipZeroFields: true,
|
||||
IncludeUnexported: false,
|
||||
Formatter: map[reflect.Type]interface{}{
|
||||
reflect.TypeOf(net.IP{}): fmt.Sprint,
|
||||
reflect.TypeOf(time.Time{}): fmt.Sprint,
|
||||
reflect.TypeOf(SubnetMap[string]{}): fmt.Sprint,
|
||||
},
|
||||
}
|
||||
|
||||
// Diff return a diff of two objects. If no diff, an empty string is
|
||||
@@ -39,6 +45,11 @@ func Diff(a, b interface{}) string {
|
||||
return prettyC.Compare(a, b)
|
||||
}
|
||||
|
||||
// RegisterDiffFormatter add an additional formatter for pretty diff.
|
||||
func RegisterDiffFormatter(t reflect.Type, fn interface{}) {
|
||||
prettyC.Formatter[t] = fn
|
||||
}
|
||||
|
||||
// HTTPEndpointCases describes case for TestHTTPEndpoints
|
||||
type HTTPEndpointCases []struct {
|
||||
Description string
|
||||
|
||||
Reference in New Issue
Block a user