summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd/run_test.go7
-rw-r--r--stdout/stdout_test.go10
-rw-r--r--tui/tui_test.go94
3 files changed, 109 insertions, 2 deletions
diff --git a/cmd/run_test.go b/cmd/run_test.go
index 3abe4e3..6d48cb0 100644
--- a/cmd/run_test.go
+++ b/cmd/run_test.go
@@ -17,6 +17,13 @@ func TestVersion(t *testing.T) {
assert.Contains(t, buff.String(), "Version:\t development")
}
+func TestLogError(t *testing.T) {
+ buff := bytes.NewBuffer(make([]byte, 10))
+ err := Run(&RunFlags{LogFile: "/xyzxyz"}, []string{}, false, buff, true)
+
+ assert.Contains(t, err.Error(), "permission denied")
+}
+
func TestAnalyzePath(t *testing.T) {
fin := testdir.CreateTestDir()
defer fin()
diff --git a/stdout/stdout_test.go b/stdout/stdout_test.go
index 6234854..e948070 100644
--- a/stdout/stdout_test.go
+++ b/stdout/stdout_test.go
@@ -72,6 +72,16 @@ func TestShowDevicesWithColor(t *testing.T) {
assert.Contains(t, output.String(), "xxx")
}
+func TestShowDevicesWithErr(t *testing.T) {
+ output := bytes.NewBuffer(make([]byte, 10))
+
+ getter := device.LinuxDevicesInfoGetter{MountsPath: "/xyzxyz"}
+ ui := CreateStdoutUI(output, false, true, false)
+ err := ui.ListDevices(getter)
+
+ assert.Contains(t, err.Error(), "no such file")
+}
+
func printBuffer(buff *bytes.Buffer) {
for i, x := range buff.String() {
println(i, string(x))
diff --git a/tui/tui_test.go b/tui/tui_test.go
index 5cad532..3cac19f 100644
--- a/tui/tui_test.go
+++ b/tui/tui_test.go
@@ -200,6 +200,47 @@ func TestDeleteDirWithConfirm(t *testing.T) {
assert.NoFileExists(t, "test_dir/nested/file2")
}
+func TestDeleteDirWithConfirmNoAskAgain(t *testing.T) {
+ fin := testdir.CreateTestDir()
+ defer fin()
+
+ simScreen := tcell.NewSimulationScreen("UTF-8")
+ simScreen.Init()
+ simScreen.SetSize(50, 50)
+
+ ui := CreateUI(simScreen, false, false)
+
+ ui.AnalyzePath("test_dir", analyze.ProcessDir, nil)
+
+ go func() {
+ time.Sleep(100 * time.Millisecond)
+ simScreen.InjectKey(tcell.KeyRune, '?', 1)
+ time.Sleep(10 * time.Millisecond)
+ simScreen.InjectKey(tcell.KeyRune, 'q', 1)
+ time.Sleep(10 * time.Millisecond)
+ simScreen.InjectKey(tcell.KeyEnter, '1', 1)
+ time.Sleep(10 * time.Millisecond)
+ simScreen.InjectKey(tcell.KeyRune, 'j', 1)
+ time.Sleep(10 * time.Millisecond)
+ simScreen.InjectKey(tcell.KeyRune, 'j', 1)
+ time.Sleep(10 * time.Millisecond)
+ simScreen.InjectKey(tcell.KeyRune, 'd', 1)
+ time.Sleep(10 * time.Millisecond)
+ simScreen.InjectKey(tcell.KeyRight, ' ', 1)
+ time.Sleep(10 * time.Millisecond)
+ simScreen.InjectKey(tcell.KeyRight, ' ', 1) // select "do not ask again"
+ time.Sleep(10 * time.Millisecond)
+ simScreen.InjectKey(tcell.KeyEnter, ' ', 1)
+ time.Sleep(10 * time.Millisecond)
+ simScreen.InjectKey(tcell.KeyRune, 'q', 1)
+ time.Sleep(10 * time.Millisecond)
+ }()
+
+ ui.StartUILoop()
+
+ assert.NoFileExists(t, "test_dir/nested/file2")
+}
+
func TestShowConfirm(t *testing.T) {
fin := testdir.CreateTestDir()
defer fin()
@@ -274,6 +315,37 @@ func TestDeleteWithErr(t *testing.T) {
assert.DirExists(t, "test_dir/nested")
}
+func TestDeleteWithErrBW(t *testing.T) {
+ fin := testdir.CreateTestDir()
+ defer fin()
+
+ os.Chmod("test_dir/nested", 0)
+ defer os.Chmod("test_dir/nested", 0755)
+
+ simScreen := tcell.NewSimulationScreen("UTF-8")
+ simScreen.Init()
+ simScreen.SetSize(50, 50)
+
+ ui := CreateUI(simScreen, false, false)
+ ui.askBeforeDelete = false
+
+ ui.AnalyzePath("test_dir", analyze.ProcessDir, nil)
+
+ go func() {
+ time.Sleep(100 * time.Millisecond)
+ simScreen.InjectKey(tcell.KeyRune, 'd', 1)
+ time.Sleep(10 * time.Millisecond)
+ simScreen.InjectKey(tcell.KeyEnter, ' ', 1)
+ time.Sleep(10 * time.Millisecond)
+ simScreen.InjectKey(tcell.KeyRune, 'q', 1)
+ time.Sleep(10 * time.Millisecond)
+ }()
+
+ ui.StartUILoop()
+
+ assert.DirExists(t, "test_dir/nested")
+}
+
func TestRescan(t *testing.T) {
fin := testdir.CreateTestDir()
defer fin()
@@ -313,7 +385,7 @@ func TestShowDevices(t *testing.T) {
simScreen.Init()
simScreen.SetSize(50, 50)
- ui := CreateUI(simScreen, false, true)
+ ui := CreateUI(simScreen, true, true)
ui.ListDevices(getDevicesInfoMock())
ui.table.Draw(simScreen)
simScreen.Show()
@@ -336,7 +408,7 @@ func TestShowDevicesBW(t *testing.T) {
simScreen.Init()
simScreen.SetSize(50, 50)
- ui := CreateUI(simScreen, true, false)
+ ui := CreateUI(simScreen, false, false)
ui.ListDevices(getDevicesInfoMock())
ui.table.Draw(simScreen)
simScreen.Show()
@@ -349,6 +421,24 @@ func TestShowDevicesBW(t *testing.T) {
}
}
+func TestShowDevicesWithError(t *testing.T) {
+ if runtime.GOOS != "linux" {
+ return
+ }
+
+ simScreen := tcell.NewSimulationScreen("UTF-8")
+ defer simScreen.Fini()
+ simScreen.Init()
+ simScreen.SetSize(50, 50)
+
+ getter := device.LinuxDevicesInfoGetter{MountsPath: "/xyzxyz"}
+
+ ui := CreateUI(simScreen, false, false)
+ err := ui.ListDevices(getter)
+
+ assert.Contains(t, err.Error(), "no such file")
+}
+
func TestSelectDevice(t *testing.T) {
if runtime.GOOS != "linux" {
return