blob: 52a1348fb0a34742b07899e04c5829d9f908c0a8 [file] [log] [blame]
Author Namea594e632018-08-10 11:33:58 -04001/*
2 Copyright 2017 the original author or authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17package integration
18
19import (
20 "fmt"
21 "path/filepath"
22 "reflect"
23 "runtime"
24 "testing"
25)
26
27// assert fails the test if the condition is false.
28func assert(tb testing.TB, condition bool, msg string, v ...interface{}) {
29 if !condition {
30 _, file, line, _ := runtime.Caller(1)
31 fmt.Printf("\033[31m%s:%d: "+msg+"\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...)
32 tb.FailNow()
33 }
34}
35
36// ok fails the test if an err is not nil.
37func ok(tb testing.TB, err error) {
38 if err != nil {
39 _, file, line, _ := runtime.Caller(1)
40 fmt.Printf("\033[31m%s:%d: unexpected error: %s\033[39m\n\n", filepath.Base(file), line, err.Error())
41 tb.FailNow()
42 }
43}
44
45// equals fails the test if exp is not equal to act.
46func equals(tb testing.TB, exp, act interface{}) {
47 if !reflect.DeepEqual(exp, act) {
48 _, file, line, _ := runtime.Caller(1)
49 fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, exp, act)
50 tb.FailNow()
51 }
52}