mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
9f0b3f5609
full diff: https://github.com/gotestyourself/gotest.tools/compare/v2.3.0...v3.0.1 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
27 lines
695 B
Go
27 lines
695 B
Go
package format // import "gotest.tools/v3/internal/format"
|
|
|
|
import "fmt"
|
|
|
|
// Message accepts a msgAndArgs varargs and formats it using fmt.Sprintf
|
|
func Message(msgAndArgs ...interface{}) string {
|
|
switch len(msgAndArgs) {
|
|
case 0:
|
|
return ""
|
|
case 1:
|
|
return fmt.Sprintf("%v", msgAndArgs[0])
|
|
default:
|
|
return fmt.Sprintf(msgAndArgs[0].(string), msgAndArgs[1:]...)
|
|
}
|
|
}
|
|
|
|
// WithCustomMessage accepts one or two messages and formats them appropriately
|
|
func WithCustomMessage(source string, msgAndArgs ...interface{}) string {
|
|
custom := Message(msgAndArgs...)
|
|
switch {
|
|
case custom == "":
|
|
return source
|
|
case source == "":
|
|
return custom
|
|
}
|
|
return fmt.Sprintf("%s: %s", source, custom)
|
|
}
|