From b3b6e4bf6c9a14514bcfb8406d9cc86d9d18bd06 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Thu, 23 Sep 2021 01:20:25 +0200 Subject: better tests (util/io subtests + check log output) --- repo_test.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'repo_test.go') diff --git a/repo_test.go b/repo_test.go index 52da9ae..6ab7cb0 100644 --- a/repo_test.go +++ b/repo_test.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" "testing" "github.com/n-peugnet/dna-backup/logger" @@ -128,6 +129,9 @@ func TestReadFiles3(t *testing.T) { } func TestNoSuchFile(t *testing.T) { + var output bytes.Buffer + logger.SetOutput(&output) + defer logger.SetOutput(os.Stderr) tmpDir := t.TempDir() os.Symlink("./notexisting", filepath.Join(tmpDir, "linknotexisting")) var buff bytes.Buffer @@ -136,6 +140,9 @@ func TestNoSuchFile(t *testing.T) { concatFiles(&files, utils.NopCloser(&buff)) testutils.AssertLen(t, 0, files, "Files") testutils.AssertLen(t, 0, buff.Bytes(), "Buffer") + if !strings.Contains(output.String(), "linknotexisting") { + t.Errorf("log should contain a warning, actual %q", &output) + } } func TestLoadChunks(t *testing.T) { -- cgit v1.2.3