-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsourceipmap_plugin_test.py
34 lines (26 loc) · 1.04 KB
/
sourceipmap_plugin_test.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
import os
import pytest
from pidtree_bcc.plugins import sourceipmap
def test_hosts_loader():
hostfile = os.path.dirname(
os.path.realpath(__file__),
) + '/fixtures/hostfile'
assert sourceipmap.hosts_loader(hostfile) == {'169.254.0.1': 'derp'}
def test_multiple_hosts_loader():
hostfile1 = os.path.dirname(
os.path.realpath(__file__),
) + '/fixtures/hostfile'
hostfile2 = os.path.dirname(
os.path.realpath(__file__),
) + '/fixtures/hostfile2'
plugin = sourceipmap.Sourceipmap({'hostfiles': [hostfile1, hostfile2]})
assert plugin.process({'saddr': '169.254.0.2'})['source_host'] == 'herp'
assert plugin.process({'saddr': '169.254.0.1'})['source_host'] == 'derp'
def test_host_file_doesnt_exist():
hostfile = '/bananas_in_spaaaaaaaaaaace'
with pytest.raises(RuntimeError) as e:
sourceipmap.Sourceipmap({'hostfiles': [hostfile]})
assert (
"File `/bananas_in_spaaaaaaaaaaace` passed as a 'hostfiles'"
' entry to the sourceipmap plugin does not exist'
) in str(e)