...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package xfs_test
16
17 import (
18 "testing"
19
20 "github.com/prometheus/procfs/xfs"
21 )
22
23 func TestReadProcStat(t *testing.T) {
24 xfs, err := xfs.NewFS("testdata/fixtures/proc", "testdata/fixtures/sys")
25 if err != nil {
26 t.Fatalf("failed to access xfs fs: %v", err)
27 }
28 stats, err := xfs.ProcStat()
29 if err != nil {
30 t.Fatalf("failed to parse XFS stats: %v", err)
31 }
32
33
34
35 if want, got := uint32(92447), stats.ExtentAllocation.ExtentsAllocated; want != got {
36 t.Errorf("unexpected extents allocated:\nwant: %d\nhave: %d", want, got)
37 }
38 }
39
40 func TestReadSysStats(t *testing.T) {
41 xfs, err := xfs.NewFS("testdata/fixtures/proc", "testdata/fixtures/sys")
42 if err != nil {
43 t.Fatalf("failed to access xfs fs: %v", err)
44 }
45 stats, err := xfs.SysStats()
46 if err != nil {
47 t.Fatalf("failed to parse XFS stats: %v", err)
48 }
49
50 tests := []struct {
51 name string
52 allocated uint32
53 }{
54 {
55 name: "sda1",
56 allocated: 1,
57 },
58 {
59 name: "sdb1",
60 allocated: 2,
61 },
62 }
63
64 const expect = 2
65
66 if l := len(stats); l != expect {
67 t.Fatalf("unexpected number of XFS stats: %d", l)
68 }
69 if l := len(tests); l != expect {
70 t.Fatalf("unexpected number of tests: %d", l)
71 }
72
73 for i, tt := range tests {
74 if want, got := tt.name, stats[i].Name; want != got {
75 t.Errorf("unexpected stats name:\nwant: %q\nhave: %q", want, got)
76 }
77
78 if want, got := tt.allocated, stats[i].ExtentAllocation.ExtentsAllocated; want != got {
79 t.Errorf("unexpected extents allocated:\nwant: %d\nhave: %d", want, got)
80 }
81 }
82 }
83
View as plain text