Skip to content

Commit

Permalink
test: more coverage for app package
Browse files Browse the repository at this point in the history
  • Loading branch information
dundee committed Apr 23, 2024
1 parent e621676 commit bdbf5fd
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
67 changes: 67 additions & 0 deletions cmd/gdu/app/app_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package app

import (
"os"
"testing"

"github.com/dundee/gdu/v5/internal/testdev"
Expand Down Expand Up @@ -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")
}
75 changes: 75 additions & 0 deletions cmd/gdu/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit bdbf5fd

Please sign in to comment.