forked from a3linux/go-aws-mon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbytes_test.go
More file actions
41 lines (38 loc) · 773 Bytes
/
bytes_test.go
File metadata and controls
41 lines (38 loc) · 773 Bytes
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
package main
import "testing"
type convFn func(uint64) uint64
func TestBytes(t *testing.T) {
for b, xb := range map[uint64]uint64{
1024: 1, // KB
1050: 1,
2048: 2,
2050: 2,
1048576: 1, // MB
1050000: 1,
2097152: 2,
2100000: 2,
1073741824: 1, // GB
1100000000: 1,
2147483648: 2,
2150000000: 2,
1099511627776: 1, // TB
1100000000000: 1,
2199023255552: 2,
2200000000000: 2,
} {
var fn convFn
switch {
case b >= TB:
fn = ToTerraBytes
case b >= GB:
fn = ToGigaBytes
case b >= MB:
fn = ToMegaBytes
case b >= KB:
fn = ToKiloBytes
}
if xb != fn(b) {
t.Errorf("failed asserting that %dB equals %dxB, got %dxB instead", b, xb, fn(b))
}
}
}