fork/gdu
git clone https://git.julia.blue/fork/gdu
da638da
master
1package analyze 2 3import ( 4"sort" 5"testing" 6 7"github.com/dundee/gdu/v5/internal/testdir" 8"github.com/dundee/gdu/v5/pkg/fs" 9"github.com/stretchr/testify/assert" 10) 11 12func TestCollectTopFiles2 (t * testing.T ) { 13fin := testdir .CreateTestDir () 14defer fin () 15 16dir := CreateAnalyzer ().AnalyzeDir ( 17"test_dir" ,func (_ ,_ string )bool {return false },func (_ string )bool {return false }, 18 ) 19 20topFiles := CollectTopFiles (dir ,2 ) 21assert .Equal (t ,2 ,len (topFiles )) 22assert .Equal (t ,"file" ,topFiles [0 ].GetName ()) 23assert .Equal (t ,int64 (5 ),topFiles [0 ].GetSize ()) 24assert .Equal (t ,"file2" ,topFiles [1 ].GetName ()) 25assert .Equal (t ,int64 (2 ),topFiles [1 ].GetSize ()) 26} 27 28func TestCollectTopFiles1 (t * testing.T ) { 29fin := testdir .CreateTestDir () 30defer fin () 31 32dir := CreateAnalyzer ().AnalyzeDir ( 33"test_dir" ,func (_ ,_ string )bool {return false },func (_ string )bool {return false }, 34 ) 35 36topFiles := CollectTopFiles (dir ,1 ) 37assert .Equal (t ,1 ,len (topFiles )) 38assert .Equal (t ,"file" ,topFiles [0 ].GetName ()) 39assert .Equal (t ,int64 (5 ),topFiles [0 ].GetSize ()) 40} 41 42func TestAdd2 (t * testing.T ) { 43topList := NewTopList (2 ) 44topList .Add (& File {Size :1 ,Name :"file1" }) 45topList .Add (& File {Size :5 ,Name :"file5" }) 46topList .Add (& File {Size :2 ,Name :"file2" }) 47 48sort .Sort (sort .Reverse (fs .ByApparentSize (topList .Items ))) 49 50assert .Equal (t ,2 ,len (topList .Items )) 51assert .Equal (t ,"file5" ,topList .Items [0 ].GetName ()) 52assert .Equal (t ,"file2" ,topList .Items [1 ].GetName ()) 53} 54 55func TestAdd3 (t * testing.T ) { 56topList := NewTopList (3 ) 57topList .Add (& File {Size :5 ,Name :"file5" }) 58topList .Add (& File {Size :1 ,Name :"file1" }) 59topList .Add (& File {Size :2 ,Name :"file2" }) 60topList .Add (& File {Size :4 ,Name :"file4" }) 61topList .Add (& File {Size :3 ,Name :"file3" }) 62 63sort .Sort (sort .Reverse (fs .ByApparentSize (topList .Items ))) 64 65assert .Equal (t ,3 ,len (topList .Items )) 66assert .Equal (t ,"file5" ,topList .Items [0 ].GetName ()) 67assert .Equal (t ,"file4" ,topList .Items [1 ].GetName ()) 68assert .Equal (t ,"file3" ,topList .Items [2 ].GetName ()) 69}