From 4fc9721fa646098d5f33523c6186b88fb834d0e6 Mon Sep 17 00:00:00 2001 From: ahrtr Date: Fri, 13 May 2022 10:50:19 +0800 Subject: [PATCH] provide a generic assert function --- client/pkg/verify/verify.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client/pkg/verify/verify.go b/client/pkg/verify/verify.go index 964ef9977..0cc1b4827 100644 --- a/client/pkg/verify/verify.go +++ b/client/pkg/verify/verify.go @@ -15,6 +15,7 @@ package verify import ( + "fmt" "os" "strings" ) @@ -70,3 +71,10 @@ func Verify(f func()) { f() } } + +// Assert will panic with a given formatted message if the given condition is false. +func Assert(condition bool, msg string, v ...interface{}) { + if !condition { + panic(fmt.Sprintf("assertion failed: "+msg, v...)) + } +}