Skip to content

Commit

Permalink
test: added more file and actions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dundee committed Feb 9, 2022
1 parent 6be2cde commit 5f9f3fa
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
59 changes: 59 additions & 0 deletions pkg/analyze/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,62 @@ func TestGetPathWithoutLeadingSlash(t *testing.T) {

assert.Equal(t, "C:\\", dir.GetPath())
}

func TestSetParent(t *testing.T) {
dir := &Dir{
File: &File{
Name: "root",
Size: 5,
Usage: 12,
},
ItemCount: 3,
BasePath: "/",
}
file := &File{
Name: "xxx",
Mli: 5,
}
file.SetParent(dir)

assert.Equal(t, "root", file.GetParent().GetName())
}

func TestGetFiles(t *testing.T) {
file := &File{
Name: "xxx",
Mli: 5,
}
dir := &Dir{
File: &File{
Name: "root",
Size: 5,
Usage: 12,
},
ItemCount: 3,
BasePath: "/",
Files: fs.Files{file},
}

assert.Equal(t, file.Name, dir.GetFiles()[0].GetName())
assert.Equal(t, fs.Files{}, file.GetFiles())
}

func TestSetFilesPanicsOnFile(t *testing.T) {
file := &File{
Name: "xxx",
Mli: 5,
}
assert.Panics(t, func() {
file.SetFiles(fs.Files{file})
})
}

func TestAddFilePanicsOnFile(t *testing.T) {
file := &File{
Name: "xxx",
Mli: 5,
}
assert.Panics(t, func() {
file.AddFile(file)
})
}
3 changes: 3 additions & 0 deletions tui/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ func TestShowInfoWithHardlinks(t *testing.T) {
assert.Equal(t, "test_dir", ui.currentDir.GetName())

ui.keyPressed(tcell.NewEventKey(tcell.KeyRight, 'l', 0))
ui.table.Select(1, 0)
ui.keyPressed(tcell.NewEventKey(tcell.KeyRight, 'l', 0))
ui.table.Select(1, 0)
ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'i', 0))

assert.True(t, ui.pages.HasPage("info"))
Expand Down

0 comments on commit 5f9f3fa

Please sign in to comment.