From bdbf5fd8fc82aaaeb224bf7e9430f86a87a2e0ca Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Tue, 23 Apr 2024 16:43:23 +0200 Subject: [PATCH] test: more coverage for app package --- cmd/gdu/app/app_linux_test.go | 67 +++++++++++++++++++++++++++++++ cmd/gdu/app/app_test.go | 75 +++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) diff --git a/cmd/gdu/app/app_linux_test.go b/cmd/gdu/app/app_linux_test.go index 65d8928d0..42dd473ef 100644 --- a/cmd/gdu/app/app_linux_test.go +++ b/cmd/gdu/app/app_linux_test.go @@ -4,6 +4,7 @@ package app import ( + "os" "testing" "github.com/dundee/gdu/v5/internal/testdev" @@ -52,3 +53,69 @@ func TestOutputFileError(t *testing.T) { assert.Empty(t, out) assert.Contains(t, err.Error(), "permission denied") } + +func TestUseStorage(t *testing.T) { + fin := testdir.CreateTestDir() + defer fin() + + defer func() { + err := os.RemoveAll("/tmp/badger-test") + if err != nil { + panic(err) + } + }() + + out, err := runApp( + &Flags{LogFile: "/dev/null", UseStorage: true, StoragePath: "/tmp/badger-test"}, + []string{"test_dir"}, + false, + testdev.DevicesInfoGetterMock{}, + ) + + assert.Contains(t, out, "nested") + assert.Nil(t, err) +} + +func TestReadFromStorage(t *testing.T) { + fin := testdir.CreateTestDir() + defer fin() + + defer func() { + err := os.RemoveAll("/tmp/badger-test") + if err != nil { + panic(err) + } + }() + + out, err := runApp( + &Flags{LogFile: "/dev/null", UseStorage: true, StoragePath: "/tmp/badger-test"}, + []string{"test_dir"}, + false, + testdev.DevicesInfoGetterMock{}, + ) + assert.Contains(t, out, "nested") + assert.Nil(t, err) + + out, err = runApp( + &Flags{LogFile: "/dev/null", ReadFromStorage: true, StoragePath: "/tmp/badger-test"}, + []string{"test_dir"}, + false, + testdev.DevicesInfoGetterMock{}, + ) + assert.Contains(t, out, "nested") + assert.Nil(t, err) +} + +func TestReadFromStorageWithErr(t *testing.T) { + fin := testdir.CreateTestDir() + defer fin() + + _, err := runApp( + &Flags{LogFile: "/dev/null", ReadFromStorage: true, StoragePath: "/tmp/badger-test"}, + []string{"test_dir"}, + false, + testdev.DevicesInfoGetterMock{}, + ) + + assert.ErrorContains(t, err, "Key not found") +} diff --git a/cmd/gdu/app/app_test.go b/cmd/gdu/app/app_test.go index 7fa34e080..e5a276552 100644 --- a/cmd/gdu/app/app_test.go +++ b/cmd/gdu/app/app_test.go @@ -47,6 +47,21 @@ func TestAnalyzePath(t *testing.T) { assert.Nil(t, err) } +func TestSequentialScanning(t *testing.T) { + fin := testdir.CreateTestDir() + defer fin() + + out, err := runApp( + &Flags{LogFile: "/dev/null", SequentialScanning: true}, + []string{"test_dir"}, + false, + testdev.DevicesInfoGetterMock{}, + ) + + assert.Contains(t, out, "nested") + assert.Nil(t, err) +} + func TestFollowSymlinks(t *testing.T) { fin := testdir.CreateTestDir() defer fin() @@ -149,6 +164,66 @@ func TestAnalyzePathWithGui(t *testing.T) { assert.Nil(t, err) } +func TestAnalyzePathWithGuiNoColor(t *testing.T) { + fin := testdir.CreateTestDir() + defer fin() + + out, err := runApp( + &Flags{LogFile: "/dev/null", NoColor: true}, + []string{"test_dir"}, + true, + testdev.DevicesInfoGetterMock{}, + ) + + assert.Empty(t, out) + assert.Nil(t, err) +} + +func TestGuiShowMTimeAndItemCount(t *testing.T) { + fin := testdir.CreateTestDir() + defer fin() + + out, err := runApp( + &Flags{LogFile: "/dev/null", ShowItemCount: true, ShowMTime: true}, + []string{"test_dir"}, + true, + testdev.DevicesInfoGetterMock{}, + ) + + assert.Empty(t, out) + assert.Nil(t, err) +} + +func TestGuiNoDelete(t *testing.T) { + fin := testdir.CreateTestDir() + defer fin() + + out, err := runApp( + &Flags{LogFile: "/dev/null", NoDelete: true}, + []string{"test_dir"}, + true, + testdev.DevicesInfoGetterMock{}, + ) + + assert.Empty(t, out) + assert.Nil(t, err) +} + +func TestGuiDeleteInParallel(t *testing.T) { + fin := testdir.CreateTestDir() + defer fin() + + out, err := runApp( + &Flags{LogFile: "/dev/null", DeleteInParallel: true}, + []string{"test_dir"}, + true, + testdev.DevicesInfoGetterMock{}, + ) + + assert.Empty(t, out) + assert.Nil(t, err) +} + func TestAnalyzePathWithGuiBackgroundDeletion(t *testing.T) { fin := testdir.CreateTestDir() defer fin()