-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: more coverage for report package
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//go:build linux | ||
// +build linux | ||
|
||
package report | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
"testing" | ||
|
||
"github.com/dundee/gdu/v5/internal/testdir" | ||
"github.com/dundee/gdu/v5/pkg/analyze" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestReadFromStorage(t *testing.T) { | ||
fin := testdir.CreateTestDir() | ||
defer fin() | ||
|
||
const storagePath = "/tmp/badger-test" | ||
defer func() { | ||
err := os.RemoveAll(storagePath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
}() | ||
|
||
output := bytes.NewBuffer(make([]byte, 10)) | ||
reportOutput := bytes.NewBuffer(make([]byte, 10)) | ||
|
||
ui := CreateExportUI(output, reportOutput, false, true, false, false) | ||
ui.SetIgnoreDirPaths([]string{"/xxx"}) | ||
ui.SetAnalyzer(analyze.CreateStoredAnalyzer(storagePath)) | ||
err := ui.AnalyzePath("test_dir", nil) | ||
assert.Nil(t, err) | ||
err = ui.ReadFromStorage(storagePath, "test_dir") | ||
|
||
assert.Nil(t, err) | ||
assert.Contains(t, reportOutput.String(), `"name":"nested"`) | ||
} | ||
|
||
func TestReadFromStorageWithErr(t *testing.T) { | ||
fin := testdir.CreateTestDir() | ||
defer fin() | ||
|
||
const storagePath = "/tmp/badger-test" | ||
|
||
output := bytes.NewBuffer(make([]byte, 10)) | ||
reportOutput := bytes.NewBuffer(make([]byte, 10)) | ||
|
||
ui := CreateExportUI(output, reportOutput, false, false, false, false) | ||
ui.SetIgnoreDirPaths([]string{"/xxx"}) | ||
err := ui.ReadFromStorage(storagePath, "test_dir") | ||
|
||
assert.ErrorContains(t, err, "Key not found") | ||
} |