Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwren authored and dundee committed Oct 26, 2021
1 parent 2042af5 commit 0c109cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/analyze/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,20 @@ func TestEncode(t *testing.T) {
Flag: '@',
Mtime: time.Date(2021, 8, 19, 0, 40, 0, 0, time.UTC),
}
file3 := &File{
Name: "file3",
Mli: 1234,
Flag: 'H',
}
dir.Files = Files{subdir}
subdir.Files = Files{file, file2}
subdir.Files = Files{file, file2, file3}

var buff bytes.Buffer
err := dir.EncodeJSON(&buff, true)

assert.Nil(t, err)
assert.Contains(t, buff.String(), `"name":"nested"`)
assert.Contains(t, buff.String(), `"mtime":1629333600`)
assert.Contains(t, buff.String(), `"ino":1234`)
assert.Contains(t, buff.String(), `"hlnkc":true`)
}
6 changes: 6 additions & 0 deletions report/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"testing"

"github.com/dundee/gdu/v5/pkg/analyze"
log "github.com/sirupsen/logrus"

"github.com/stretchr/testify/assert"
Expand All @@ -23,6 +24,7 @@ func TestReadAnalysis(t *testing.T) {
[{"name":"app"},
{"name":"app.go","asize":4638,"dsize":8192},
{"name":"app_linux_test.go","asize":1410,"dsize":4096},
{"name":"app_linux_test2.go","ino":1234,"hlnkc":true,"asize":1410,"dsize":4096},
{"name":"app_test.go","asize":4974,"dsize":8192}],
{"name":"main.go","asize":3205,"dsize":4096,"mtime":1629333600}]]
`))
Expand All @@ -34,6 +36,10 @@ func TestReadAnalysis(t *testing.T) {
assert.Equal(t, "/home/xxx", dir.GetPath())
assert.Equal(t, 2021, dir.GetMtime().Year())
assert.Equal(t, 2021, dir.Files[3].GetMtime().Year())
alt2 := dir.Files[2].(*analyze.Dir).Files[2].(*analyze.File)
assert.Equal(t, "app_linux_test2.go", alt2.Name)
assert.Equal(t, uint64(1234), alt2.Mli)
assert.Equal(t, 'H', alt2.Flag)
}

func TestReadAnalysisWithEmptyInput(t *testing.T) {
Expand Down

0 comments on commit 0c109cf

Please sign in to comment.