github.com/vishnupahwa/lakctl@v0.0.2-alpha/test/short/short.go (about)

     1  package short
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  	"reflect"
     7  	"runtime"
     8  	"testing"
     9  )
    10  
    11  // assert fails the test if the condition is false.
    12  func Assert(tb testing.TB, condition bool, msg string, v ...interface{}) {
    13  	if !condition {
    14  		_, file, line, _ := runtime.Caller(1)
    15  		fmt.Printf("\033[31m%s:%d: "+msg+"\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...)
    16  		tb.FailNow()
    17  	}
    18  }
    19  
    20  // ok fails the test if an err is not nil.
    21  func Ok(tb testing.TB, err error) {
    22  	if err != nil {
    23  		_, file, line, _ := runtime.Caller(1)
    24  		fmt.Printf("\033[31m%s:%d: unexpected error: %s\033[39m\n\n", filepath.Base(file), line, err.Error())
    25  		tb.FailNow()
    26  	}
    27  }
    28  
    29  // equals fails the test if exp is not equal to act.
    30  func Equals(tb testing.TB, exp, act interface{}) {
    31  	if !reflect.DeepEqual(exp, act) {
    32  		_, file, line, _ := runtime.Caller(1)
    33  		fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, exp, act)
    34  		tb.FailNow()
    35  	}
    36  }
    37  
    38  func Must(t *testing.T, err error) {
    39  	if err != nil {
    40  		t.Fatal(err)
    41  	}
    42  }