fork/gdu

git clone https://git.julia.blue/fork/gdu

Daniel Milderefactor: correct ordering5312bf1

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