fork/gdu
git clone https://git.julia.blue/fork/gdu
5312bf1
master
1package device 2 3import ( 4"sort" 5"testing" 6 7"github.com/stretchr/testify/assert" 8) 9 10func TestNested (t * testing.T ) { 11item := & Device { 12MountPoint :"/xxx" , 13 } 14nested := & Device { 15MountPoint :"/xxx/yyy" , 16 } 17notNested := & Device { 18MountPoint :"/zzz/yyy" , 19 } 20 21mounts := Devices {item ,nested ,notNested } 22 23mountsNested := GetNestedMountpointsPaths ("/xxx" ,mounts ) 24 25assert .Len (t ,mountsNested ,1 ) 26assert .Equal (t ,"/xxx/yyy" ,mountsNested [0 ]) 27} 28 29func TestSortByName (t * testing.T ) { 30item := & Device { 31Name :"/xxx" , 32 } 33nested := & Device { 34Name :"/xxx/yyy" , 35 } 36notNested := & Device { 37Name :"/zzz/yyy" , 38 } 39 40devices := Devices {item ,nested ,notNested } 41 42sort .Sort (sort .Reverse (ByName (devices ))) 43 44assert .Equal (t ,"/zzz/yyy" ,devices [0 ].Name ) 45assert .Equal (t ,"/xxx/yyy" ,devices [1 ].Name ) 46assert .Equal (t ,"/xxx" ,devices [2 ].Name ) 47} 48 49func TestSortByUsedSize (t * testing.T ) { 50item := & Device { 51Name :"xxx" , 52Size :1e12 , 53Free :1e3 , 54 } 55nested := & Device { 56Name :"yyy" , 57Size :1e12 , 58Free :1e6 , 59 } 60notNested := & Device { 61Name :"zzz" , 62Size :1e12 , 63Free :1e12 , 64 } 65 66devices := Devices {item ,nested ,notNested } 67 68sort .Sort (ByUsedSize (devices )) 69 70assert .Equal (t ,"zzz" ,devices [0 ].Name ) 71assert .Equal (t ,"yyy" ,devices [1 ].Name ) 72assert .Equal (t ,"xxx" ,devices [2 ].Name ) 73}