This repository has been archived by the owner on Nov 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_zfs_test.go
132 lines (112 loc) · 3.43 KB
/
check_zfs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"testing"
)
func TestCheckHealth(t *testing.T) {
z := zpool{name: "tank"}
// Test ONLINE
err := z.checkHealth("ONLINE")
if err != nil {
t.Errorf("Error in checkHealth (%s)", err)
}
if z.healthy == false {
t.Errorf("healthy should equal true when given 'ONLINE'")
}
// Test FAULED
err = z.checkHealth("FAULTED")
if err != nil {
t.Errorf("Error in checkHealth (%s)", err)
}
if z.healthy == true {
t.Errorf("healthy should equal true when given 'FAULTED'")
}
// Test DEGRADED
err = z.checkHealth("DEGRADED")
if err != nil {
t.Errorf("Error in checkHealth (%s)", err)
}
if z.healthy == true {
t.Errorf("healthy should equal true when given 'DEGRADED'")
}
// Test other
err = z.checkHealth("other status")
if err == nil {
t.Errorf("other status should throw error in checkHealth (%s)", err)
}
if z.healthy == true {
t.Errorf("healthy should equal false when given unknown input")
}
}
func TestGetCapacity(t *testing.T) {
z := zpool{name: "tank"}
// Test average capacity
err := z.getCapacity("51%")
if err != nil {
t.Errorf("Error in getCapacity")
}
if z.capacity != 51 {
t.Errorf("Non-matching integer, should be 51")
}
// Test non-integer
err = z.getCapacity("foo")
if err == nil {
t.Errorf("Non-integer should produce error in getCapacity")
}
}
func TestGetFaulted(t *testing.T) {
z := zpool{
name: "tank",
faulted: -1, // set to -1 to make sure we actually test the all-ONLINE case
}
// Test all ONLINE
err := z.getFaulted(` pool: tank
state: ONLINE
scan: scrub repaired 0 in 1h1m with 0 errors on Thu Jan 1 13:37:00 1970
config:
NAME STATE READ WRITE CKSUM
zones ONLINE 0 0 0
raidz2-0 ONLINE 0 0 0
c0t5000C5006A6E87D9d0 ONLINE 0 0 0
c0t5000C50024CAAFFCd0 ONLINE 0 0 0
c0t5000CCA249D27B4Ed0 ONLINE 0 0 0
c0t5000C5004425F6F6d0 ONLINE 0 0 0
c0t5000C500652DD0EFd0 ONLINE 0 0 0
c0t50014EE25A580141d0 ONLINE 0 0 0
errors: No known data errors`)
if err != nil {
t.Errorf("Error in getFaulted")
}
if z.faulted != 0 {
t.Errorf("Incorrect amount of faulted, should be 0.")
}
// Test degraded state
err = z.getFaulted(` pool: tank
state: DEGRADED
scan: scrub repaired 0 in 1h1m with 0 errors on Thu Jan 1 13:37:00 1970
config:
NAME STATE READ WRITE CKSUM
zones DEGRADED 0 0 0
raidz2-0 ONLINE 0 0 0
c0t5000C5006A6E87D9d0 FAULTED 0 0 0
c0t5000C50024CAAFFCd0 ONLINE 0 0 0
c0t5000CCA249D27B4Ed0 ONLINE 0 0 0
c0t5000C5004425F6F6d0 UNAVAIL 0 0 0
c0t5000C500652DD0EFd0 ONLINE 0 0 0
c0t50014EE25A580141d0 ONLINE 0 0 0
errors: No known data errors`)
if err != nil {
t.Errorf("Error in getFaulted")
}
if z.faulted != 2 {
t.Errorf("Incorrect amount of faulted, should be 2.")
}
// Test other output
err = z.getFaulted(` pool: tank
state: Oother`)
if err == nil {
t.Errorf("Should produce parsing error in getFaulted")
}
if z.faulted != 1 {
t.Errorf("Incorrect amount of faulted, should be 1 when parsing error.")
}
}