From 469e5f14dc7b93686b8b966d143eb38dab7a884e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 17 Feb 2016 11:05:13 +0100 Subject: [PATCH] Add tests for readerContains --- util_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/util_test.go b/util_test.go index 46432c6..d3dcdd1 100644 --- a/util_test.go +++ b/util_test.go @@ -139,6 +139,35 @@ func TestIsEmpty(t *testing.T) { } } +func TestReaderContains(t *testing.T) { + for i, this := range []struct { + v1 string + v2 []byte + expect bool + }{ + {"abc", []byte("a"), true}, + {"abc", []byte("b"), true}, + {"abcdefg", []byte("efg"), true}, + {"abc", []byte("d"), false}, + {"", nil, false}, + {"", []byte("a"), false}, + {"a", []byte(""), false}, + {"", []byte(""), false}} { + result := readerContains(strings.NewReader(this.v1), this.v2) + if result != this.expect { + t.Errorf("[%d] readerContains: got %t but expected %t", i, result, this.expect) + } + } + + if readerContains(nil, []byte("a")) { + t.Error("readerContains with nil reader") + } + + if readerContains(nil, nil) { + t.Error("readerContains with nil arguments") + } +} + func createZeroSizedFileInTempDir() (File, error) { filePrefix := "_path_test_" f, e := TempFile(testFS, "", filePrefix) // dir is os.TempDir()