1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
//go: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-test2"
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)
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-test3"
output := bytes.NewBuffer(make([]byte, 10))
reportOutput := bytes.NewBuffer(make([]byte, 10))
ui := CreateExportUI(output, reportOutput, false, false, false)
ui.SetIgnoreDirPaths([]string{"/xxx"})
err := ui.ReadFromStorage(storagePath, "test_dir")
assert.ErrorContains(t, err, "Key not found")
}
|