-
Notifications
You must be signed in to change notification settings - Fork 22
/
assert_test.go
68 lines (61 loc) · 1.85 KB
/
assert_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright Josh Komoroske. All rights reserved.
// Use of this source code is governed by the MIT license,
// a copy of which can be found in the LICENSE.txt file.
// SPDX-License-Identifier: MIT
package junit
import (
"bytes"
"reflect"
"testing"
)
// assertEqual is a testing helper function which asserts that the given
// objects are equal.
func assertEqual(t *testing.T, expected, actual interface{}) {
t.Helper()
if !reflect.DeepEqual(expected, actual) {
t.Fatalf("objects were not equal: \n"+
"expected: %v\n"+
"actual : %v", expected, actual)
}
}
// assertEqualBytes is a testing helper function which asserts that the given
// byte slices are equal.
func assertEqualBytes(t *testing.T, expected, actual []byte) {
t.Helper()
if !bytes.Equal(expected, actual) {
t.Fatalf("byte slices were not equal: \n"+
"expected: %s\n"+
"actual : %s", string(expected), string(actual))
}
}
// assertLen is a testing helper function which asserts that the given object
// has the expected length.
func assertLen(t *testing.T, object interface{}, expected int) {
t.Helper()
actual := reflect.ValueOf(object).Len()
if actual != expected {
t.Fatalf("lengths were not equal: \n"+
"expected: %d\n"+
"actual : %d", expected, actual)
}
}
// assertError is a testing helper function which asserts that the given error
// is not nil and has the expected error text.
func assertError(t *testing.T, actual error, expected string) {
t.Helper()
if actual == nil || actual.Error() != expected {
t.Fatalf("error was not equal: \n"+
"expected: %v\n"+
"actual : %v", expected, actual)
}
}
// assertNoError is a testing helper function which asserts that the given
// error is nil.
func assertNoError(t *testing.T, actual error) {
t.Helper()
if actual != nil {
t.Fatalf("error was not nil: \n"+
"expected: no error\n"+
"actual : %v", actual)
}
}