From 4c38e0672ebbfec454421503b9c7becd9ae5b578 Mon Sep 17 00:00:00 2001 From: Siarhiej Siemianczuk Date: Fri, 16 Aug 2024 20:29:13 +0300 Subject: [PATCH] cmds/core/du: add run test Signed-off-by: Siarhiej Siemianczuk --- cmds/core/du/du_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/cmds/core/du/du_test.go b/cmds/core/du/du_test.go index 9fade6fe95..2c835239c0 100644 --- a/cmds/core/du/du_test.go +++ b/cmds/core/du/du_test.go @@ -4,7 +4,9 @@ package main import ( + "bytes" "os" + "regexp" "testing" ) @@ -60,3 +62,24 @@ func TestDU(t *testing.T) { } }) } + +func TestRun(t *testing.T) { + t.Run("empty folder", func(t *testing.T) { + dir := t.TempDir() + err := os.Chdir(dir) + if err != nil { + t.Fatal(err) + } + + stdout := &bytes.Buffer{} + err = run(stdout) + if err != nil { + t.Fatalf("expected nil got %v", err) + } + + r := regexp.MustCompile(`^\d\t\.\n$`) + if !r.MatchString(stdout.String()) { + t.Error("expected number tab dot new-line") + } + }) +}