Skip to content

Commit

Permalink
test: more coverage for report package
Browse files Browse the repository at this point in the history
  • Loading branch information
dundee committed Apr 23, 2024
1 parent bdbf5fd commit c3ff48c
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions report/export_linux_test.go
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")
}

0 comments on commit c3ff48c

Please sign in to comment.