-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_utils.py
68 lines (57 loc) · 1.98 KB
/
test_utils.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
import utils
import pytest
def test_parse_free_output():
sample_output = b"""
total used free shared buff/cache available
Mem: 7963500 2717740 973420 582872 4272340 4218632
Swap: 8388604 4 8388600
"""
actual_result = utils.parse_free_output(sample_output)
expected_result = utils.SwapMem(free=8388600, used=4)
assert expected_result == actual_result
def test_mkswapfile():
expected_cmd = [
["fallocate", "-l", "100M", "/home/.swap/swapfile1"],
["mkswap", "/home/.swap/swapfile1"],
]
assert (
utils.mkswapfile(path="/home/.swap/swapfile1", size=100, dryrun=True)
== expected_cmd
)
def test_activate_swapfile():
expected_cmd = ["swapon", "/home/.swap/swapfile1", "-p", "500"]
assert (
utils.activate_swapfile(
utils.SwapFile(path="/home/.swap/swapfile1", prio=500), dryrun=True
)
== expected_cmd
)
def test_new_swapfile():
current_swapfiles = [
utils.SwapFile("/prefix/file1", 1000),
utils.SwapFile("/prefix/file3", 960),
utils.SwapFile("/prefix/file4", 955),
utils.SwapFile("/prefix/file6", 950),
]
prefix = "/prefix/file"
assert utils.new_swapfile_path(prefix, current_swapfiles) == utils.SwapFile(
path="/prefix/file7", prio=949
)
def test_new_swapfile_empty():
current_swapfiles = [
]
prefix = "/prefix/file"
assert utils.new_swapfile_path(prefix, current_swapfiles) == utils.SwapFile(
path="/prefix/file1", prio=32767
)
def test_new_swapfile_exhausted_prio():
current_swapfiles = [
utils.SwapFile("/prefix/file1", 1000),
utils.SwapFile("/prefix/file3", 960),
utils.SwapFile("/prefix/file4", 0),
utils.SwapFile("/prefix/file6", -1),
]
prefix = "/prefix/file"
assert utils.new_swapfile_path(prefix, current_swapfiles) == utils.SwapFile(
path="/prefix/file7", prio=-1
)