summaryrefslogtreecommitdiff
path: root/vendor/github.com/onsi/gomega/format
diff options
context:
space:
mode:
authordependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2021-05-06 08:07:07 +0000
committerGitHub <noreply@github.com>2021-05-06 08:07:07 +0000
commit3de369fd696e6b98d00259d3c759d9b81df4e84b (patch)
tree7c489ea3aa926cda031d6aaa4a852e9e6e469d14 /vendor/github.com/onsi/gomega/format
parent9b9bd9e0e7b72c91d8e60103e8da7999cefbc63d (diff)
downloadpodman-3de369fd696e6b98d00259d3c759d9b81df4e84b.tar.gz
podman-3de369fd696e6b98d00259d3c759d9b81df4e84b.tar.bz2
podman-3de369fd696e6b98d00259d3c759d9b81df4e84b.zip
Bump github.com/onsi/gomega from 1.11.0 to 1.12.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.11.0 to 1.12.0. - [Release notes](https://github.com/onsi/gomega/releases) - [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/gomega/compare/v1.11.0...v1.12.0) Signed-off-by: dependabot[bot] <support@github.com>
Diffstat (limited to 'vendor/github.com/onsi/gomega/format')
-rw-r--r--vendor/github.com/onsi/gomega/format/format.go70
1 files changed, 58 insertions, 12 deletions
diff --git a/vendor/github.com/onsi/gomega/format/format.go b/vendor/github.com/onsi/gomega/format/format.go
index 4f7462ab1..6e78c391d 100644
--- a/vendor/github.com/onsi/gomega/format/format.go
+++ b/vendor/github.com/onsi/gomega/format/format.go
@@ -18,6 +18,10 @@ import (
// Use MaxDepth to set the maximum recursion depth when printing deeply nested objects
var MaxDepth = uint(10)
+// MaxLength of the string representation of an object.
+// If MaxLength is set to 0, the Object will not be truncated.
+var MaxLength = 4000
+
/*
By default, all objects (even those that implement fmt.Stringer and fmt.GoStringer) are recursively inspected to generate output.
@@ -53,6 +57,14 @@ var Indent = " "
var longFormThreshold = 20
+// GomegaStringer allows for custom formating of objects for gomega.
+type GomegaStringer interface {
+ // GomegaString will be used to custom format an object.
+ // It does not follow UseStringerRepresentation value and will always be called regardless.
+ // It also ignores the MaxLength value.
+ GomegaString() string
+}
+
/*
Generates a formatted matcher success/failure message of the form:
@@ -159,6 +171,33 @@ func findFirstMismatch(a, b string) int {
return 0
}
+const truncateHelpText = `
+Gomega truncated this representation as it exceeds 'format.MaxLength'.
+Consider having the object provide a custom 'GomegaStringer' representation
+or adjust the parameters in Gomega's 'format' package.
+
+Learn more here: https://onsi.github.io/gomega/#adjusting-output
+`
+
+func truncateLongStrings(s string) string {
+ if MaxLength > 0 && len(s) > MaxLength {
+ var sb strings.Builder
+ for i, r := range s {
+ if i < MaxLength {
+ sb.WriteRune(r)
+ continue
+ }
+ break
+ }
+
+ sb.WriteString("...\n")
+ sb.WriteString(truncateHelpText)
+
+ return sb.String()
+ }
+ return s
+}
+
/*
Pretty prints the passed in object at the passed in indentation level.
@@ -219,14 +258,21 @@ func formatValue(value reflect.Value, indentation uint) string {
return "nil"
}
- if UseStringerRepresentation {
- if value.CanInterface() {
- obj := value.Interface()
+ if value.CanInterface() {
+ obj := value.Interface()
+
+ // GomegaStringer will take precedence to other representations and disregards UseStringerRepresentation
+ if x, ok := obj.(GomegaStringer); ok {
+ // do not truncate a user-defined GoMegaString() value
+ return x.GomegaString()
+ }
+
+ if UseStringerRepresentation {
switch x := obj.(type) {
case fmt.GoStringer:
- return x.GoString()
+ return truncateLongStrings(x.GoString())
case fmt.Stringer:
- return x.String()
+ return truncateLongStrings(x.String())
}
}
}
@@ -257,26 +303,26 @@ func formatValue(value reflect.Value, indentation uint) string {
case reflect.Ptr:
return formatValue(value.Elem(), indentation)
case reflect.Slice:
- return formatSlice(value, indentation)
+ return truncateLongStrings(formatSlice(value, indentation))
case reflect.String:
- return formatString(value.String(), indentation)
+ return truncateLongStrings(formatString(value.String(), indentation))
case reflect.Array:
- return formatSlice(value, indentation)
+ return truncateLongStrings(formatSlice(value, indentation))
case reflect.Map:
- return formatMap(value, indentation)
+ return truncateLongStrings(formatMap(value, indentation))
case reflect.Struct:
if value.Type() == timeType && value.CanInterface() {
t, _ := value.Interface().(time.Time)
return t.Format(time.RFC3339Nano)
}
- return formatStruct(value, indentation)
+ return truncateLongStrings(formatStruct(value, indentation))
case reflect.Interface:
return formatInterface(value, indentation)
default:
if value.CanInterface() {
- return fmt.Sprintf("%#v", value.Interface())
+ return truncateLongStrings(fmt.Sprintf("%#v", value.Interface()))
}
- return fmt.Sprintf("%#v", value)
+ return truncateLongStrings(fmt.Sprintf("%#v", value))
}
}