mirror of
https://github.com/octoleo/restic.git
synced 2024-11-23 13:17:42 +00:00
Add optional messages for Equals helper
This commit is contained in:
parent
94de87d4b7
commit
62a8a599f1
@ -3,6 +3,7 @@ package test
|
||||
import (
|
||||
"compress/bzip2"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -47,10 +48,22 @@ func OKs(tb testing.TB, errs []error) {
|
||||
}
|
||||
|
||||
// Equals fails the test if exp is not equal to act.
|
||||
func Equals(tb testing.TB, exp, act interface{}) {
|
||||
// msg is optional message to be printed, first param being format string and rest being arguments.
|
||||
func Equals(tb testing.TB, exp, act interface{}, msgs ...string) {
|
||||
tb.Helper()
|
||||
if !reflect.DeepEqual(exp, act) {
|
||||
tb.Fatalf("\033[31m\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", exp, act)
|
||||
var msgString string
|
||||
length := len(msgs)
|
||||
if length == 1 {
|
||||
msgString = msgs[0]
|
||||
} else if length > 1 {
|
||||
args := make([]interface{}, length-1)
|
||||
for i, msg := range msgs[1:] {
|
||||
args[i] = msg
|
||||
}
|
||||
msgString = fmt.Sprintf(msgs[0], args...)
|
||||
}
|
||||
tb.Fatalf("\033[31m\n\n\t"+msgString+"\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", exp, act)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user