mirror of
https://github.com/restic/restic.git
synced 2025-01-03 05:35:43 +00:00
Add optional messages for Equals helper
This commit is contained in:
parent
94de87d4b7
commit
62a8a599f1
1 changed files with 15 additions and 2 deletions
|
@ -3,6 +3,7 @@ package test
|
||||||
import (
|
import (
|
||||||
"compress/bzip2"
|
"compress/bzip2"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -47,10 +48,22 @@ func OKs(tb testing.TB, errs []error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equals fails the test if exp is not equal to act.
|
// 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()
|
tb.Helper()
|
||||||
if !reflect.DeepEqual(exp, act) {
|
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 a new issue