-
Notifications
You must be signed in to change notification settings - Fork 53
/
test_backend.py
73 lines (60 loc) · 3.53 KB
/
test_backend.py
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
#!/usr/bin/env python
__author__ = "Rodrigue Chakode"
__copyright__ = "Copyright 2019 Rodrigue Chakode and contributors"
__credits__ = ["Rodrigue Chakode and contributors"]
__license__ = "Apache"
__version__ = "2.0"
__maintainer__ = "Rodrigue Chakode"
__email__ = "Rodrigue Chakode <rodrigue.chakode @ gmail dot com"
__status__ = "Production"
import backend
class TestDecodeK8sMetrics(object):
def test_decode_cpu_capacity_nounit(self):
assert round(backend.K8sUsage().decode_capacity('1'), 0) == 1
assert round(backend.K8sUsage().decode_capacity('64'), 0) == 64
def test_decode_cpu_capacity_milli(self):
assert round(backend.K8sUsage().decode_capacity('1m'), 3) == 1e-3
assert round(backend.K8sUsage().decode_capacity('875m'), 3) == 875e-3
def test_decode_cpu_capacity_kilo(self):
assert round(backend.K8sUsage().decode_capacity('4.5k'), 3) == 4500
assert round(backend.K8sUsage().decode_capacity('192k'), 3) == 192000
def test_decode_cpu_capacity_nano(self):
assert round(backend.K8sUsage().decode_capacity('1n'), 9) == 1e-9
assert round(backend.K8sUsage().decode_capacity('875n'), 9) == 875e-9
def test_decode_cpu_capacity_micro(self):
assert round(backend.K8sUsage().decode_capacity('1u'), 6) == 1e-6
assert round(backend.K8sUsage().decode_capacity('875u'), 6) == 875e-6
def test_decode_memory_capacity_nounit(self):
assert round(backend.K8sUsage().decode_capacity('256'), 0) == 256
assert round(backend.K8sUsage().decode_capacity('875'), 0) == 875
def test_decode_memory_capacity_Ki(self):
assert round(backend.K8sUsage().decode_capacity('1Ki'), 3) == 1024
assert round(backend.K8sUsage().decode_capacity('875Ki'), 3) == 875 * 1024
assert round(backend.K8sUsage().decode_capacity('1K'), 3) == 1e3
assert round(backend.K8sUsage().decode_capacity('875K'), 3) == 875 * 1e3
def test_decode_memory_capacity_Mi(self):
# Mi = 1073741824 = 1024 * 1024 * 1024
assert round(backend.K8sUsage().decode_capacity('1Mi'), 6) == 1048576
assert round(backend.K8sUsage().decode_capacity('875Mi'), 6) == 875 * 1024 * 1024
# M = 1e6
assert round(backend.K8sUsage().decode_capacity('1M'), 6) == 1e6
assert round(backend.K8sUsage().decode_capacity('875M'), 6) == 875 * 1e6
def test_decode_memory_capacity_Gi(self):
# Gi = 1073741824 = 1024 * 1024 * 1024
assert round(backend.K8sUsage().decode_capacity('1Gi'), 9) == 1073741824
assert round(backend.K8sUsage().decode_capacity('875Gi'), 9) == 875 * 1024 * 1024 * 1024
# G = 1e9
assert round(backend.K8sUsage().decode_capacity('1G'), 9) == 1e9
assert round(backend.K8sUsage().decode_capacity('875G'), 9) == 875 * 1e9
def test_decode_memory_capacity_n_u_m(self):
# m = 1e-3
assert round(backend.K8sUsage().decode_capacity('14162554060800m'), 1) == 14162554060.8
assert backend.K8sUsage().decode_capacity('1u') == 1e-6
assert round(backend.K8sUsage().decode_capacity('875m'), 3) == 875 * 1e-3
def test_decode_memory_capacity_Pi(self):
# Pi = 1125899906842624 = 1024 * 1024 * 1024 * 1024 * 1024
assert round(backend.K8sUsage().decode_capacity('1Pi'), 15) == 1125899906842624
assert round(backend.K8sUsage().decode_capacity('875Pi'), 15) == 875 * 1024 * 1024 * 1024 * 1024 * 1024
# P = 1e15
assert round(backend.K8sUsage().decode_capacity('1P'), 9) == 1e15
assert round(backend.K8sUsage().decode_capacity('875P'), 9) == 875 * 1e15