From 4eda8330e86a7d2282197c58af6b172592ec18f6 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Fri, 20 Mar 2015 11:51:26 +1100 Subject: [PATCH] byteSliceEq --- samples/flushfs/flush_fs_test.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/samples/flushfs/flush_fs_test.go b/samples/flushfs/flush_fs_test.go index 0984d21..4b961e9 100644 --- a/samples/flushfs/flush_fs_test.go +++ b/samples/flushfs/flush_fs_test.go @@ -15,6 +15,8 @@ package flushfs_test import ( + "errors" + "fmt" "io" "os" "path" @@ -76,7 +78,24 @@ func (t *FlushFSTest) SetUp(ti *TestInfo) { //////////////////////////////////////////////////////////////////////// // Match byte slices equal to the supplied string. -func byteSliceEq(expected string) Matcher +func byteSliceEq(expected string) Matcher { + pred := func(c interface{}) error { + slice, ok := c.([]byte) + if !ok { + return errors.New("which is not []byte") + } + + if string(slice) != expected { + return fmt.Errorf("which is string \"%s\"", string(slice)) + } + + return nil + } + + return NewMatcher( + pred, + fmt.Sprintf("byte slice equal to string \"%s\"", expected)) +} // Return a copy of the current contents of t.flushes. //