diff --git a/tests/fixtures/centos-7.7/netstat-r.json b/tests/fixtures/centos-7.7/netstat-r.json new file mode 100644 index 00000000..bd3bea76 --- /dev/null +++ b/tests/fixtures/centos-7.7/netstat-r.json @@ -0,0 +1 @@ +[{"destination": "default", "gateway": "gateway", "genmask": "0.0.0.0", "route_flags": "UG", "mss": 0, "window": 0, "irtt": 0, "iface": "ens33", "kind": "route"}, {"destination": "172.17.0.0", "gateway": "0.0.0.0", "genmask": "255.255.0.0", "route_flags": "U", "mss": 0, "window": 0, "irtt": 0, "iface": "docker0", "kind": "route"}, {"destination": "192.168.71.0", "gateway": "0.0.0.0", "genmask": "255.255.255.0", "route_flags": "U", "mss": 0, "window": 0, "irtt": 0, "iface": "ens33", "kind": "route"}] diff --git a/tests/fixtures/centos-7.7/netstat-rne.json b/tests/fixtures/centos-7.7/netstat-rne.json new file mode 100644 index 00000000..1e7e0bcc --- /dev/null +++ b/tests/fixtures/centos-7.7/netstat-rne.json @@ -0,0 +1 @@ +[{"destination": "0.0.0.0", "gateway": "192.168.71.2", "genmask": "0.0.0.0", "route_flags": "UG", "metric": 100, "route_refs": 0, "use": 0, "iface": "ens33", "kind": "route"}, {"destination": "172.17.0.0", "gateway": "0.0.0.0", "genmask": "255.255.0.0", "route_flags": "U", "metric": 0, "route_refs": 0, "use": 0, "iface": "docker0", "kind": "route"}, {"destination": "192.168.71.0", "gateway": "0.0.0.0", "genmask": "255.255.255.0", "route_flags": "U", "metric": 100, "route_refs": 0, "use": 0, "iface": "ens33", "kind": "route"}] diff --git a/tests/fixtures/centos-7.7/netstat-rnee.json b/tests/fixtures/centos-7.7/netstat-rnee.json new file mode 100644 index 00000000..3093e895 --- /dev/null +++ b/tests/fixtures/centos-7.7/netstat-rnee.json @@ -0,0 +1 @@ +[{"destination": "0.0.0.0", "gateway": "192.168.71.2", "genmask": "0.0.0.0", "route_flags": "UG", "metric": 100, "route_refs": 0, "use": 0, "iface": "ens33", "mss": 0, "window": 0, "irtt": 0, "kind": "route"}, {"destination": "172.17.0.0", "gateway": "0.0.0.0", "genmask": "255.255.0.0", "route_flags": "U", "metric": 0, "route_refs": 0, "use": 0, "iface": "docker", "mss": 0, "window": 0, "irtt": 0, "kind": "route"}, {"destination": "192.168.71.0", "gateway": "0.0.0.0", "genmask": "255.255.255.0", "route_flags": "U", "metric": 100, "route_refs": 0, "use": 0, "iface": "ens33", "mss": 0, "window": 0, "irtt": 0, "kind": "route"}] diff --git a/tests/fixtures/ubuntu-18.04/netstat-r.json b/tests/fixtures/ubuntu-18.04/netstat-r.json new file mode 100644 index 00000000..618fca58 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/netstat-r.json @@ -0,0 +1 @@ +[{"destination": "default", "gateway": "_gateway", "genmask": "0.0.0.0", "route_flags": "UG", "mss": 0, "window": 0, "irtt": 0, "iface": "ens33", "kind": "route"}, {"destination": "192.168.71.0", "gateway": "0.0.0.0", "genmask": "255.255.255.0", "route_flags": "U", "mss": 0, "window": 0, "irtt": 0, "iface": "ens33", "kind": "route"}, {"destination": "_gateway", "gateway": "0.0.0.0", "genmask": "255.255.255.255", "route_flags": "UH", "mss": 0, "window": 0, "irtt": 0, "iface": "ens33", "kind": "route"}] diff --git a/tests/fixtures/ubuntu-18.04/netstat-r.out b/tests/fixtures/ubuntu-18.04/netstat-r.out new file mode 100644 index 00000000..877fceb8 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/netstat-r.out @@ -0,0 +1,5 @@ +Kernel IP routing table +Destination Gateway Genmask Flags MSS Window irtt Iface +default _gateway 0.0.0.0 UG 0 0 0 ens33 +192.168.71.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33 +_gateway 0.0.0.0 255.255.255.255 UH 0 0 0 ens33 diff --git a/tests/fixtures/ubuntu-18.04/netstat-rne.json b/tests/fixtures/ubuntu-18.04/netstat-rne.json new file mode 100644 index 00000000..5acccd57 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/netstat-rne.json @@ -0,0 +1 @@ +[{"destination": "0.0.0.0", "gateway": "192.168.71.2", "genmask": "0.0.0.0", "route_flags": "UG", "metric": 100, "route_refs": 0, "use": 0, "iface": "ens33", "kind": "route"}, {"destination": "192.168.71.0", "gateway": "0.0.0.0", "genmask": "255.255.255.0", "route_flags": "U", "metric": 0, "route_refs": 0, "use": 0, "iface": "ens33", "kind": "route"}, {"destination": "192.168.71.2", "gateway": "0.0.0.0", "genmask": "255.255.255.255", "route_flags": "UH", "metric": 100, "route_refs": 0, "use": 0, "iface": "ens33", "kind": "route"}] diff --git a/tests/fixtures/ubuntu-18.04/netstat-rne.out b/tests/fixtures/ubuntu-18.04/netstat-rne.out new file mode 100644 index 00000000..8cd80602 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/netstat-rne.out @@ -0,0 +1,5 @@ +Kernel IP routing table +Destination Gateway Genmask Flags Metric Ref Use Iface +0.0.0.0 192.168.71.2 0.0.0.0 UG 100 0 0 ens33 +192.168.71.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33 +192.168.71.2 0.0.0.0 255.255.255.255 UH 100 0 0 ens33 diff --git a/tests/fixtures/ubuntu-18.04/netstat-rnee.json b/tests/fixtures/ubuntu-18.04/netstat-rnee.json new file mode 100644 index 00000000..47a4d04b --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/netstat-rnee.json @@ -0,0 +1 @@ +[{"destination": "0.0.0.0", "gateway": "192.168.71.2", "genmask": "0.0.0.0", "route_flags": "UG", "metric": 100, "route_refs": 0, "use": 0, "iface": "ens33", "mss": 0, "window": 0, "irtt": 0, "kind": "route"}, {"destination": "192.168.71.0", "gateway": "0.0.0.0", "genmask": "255.255.255.0", "route_flags": "U", "metric": 0, "route_refs": 0, "use": 0, "iface": "ens33", "mss": 0, "window": 0, "irtt": 0, "kind": "route"}, {"destination": "192.168.71.2", "gateway": "0.0.0.0", "genmask": "255.255.255.255", "route_flags": "UH", "metric": 100, "route_refs": 0, "use": 0, "iface": "ens33", "mss": 0, "window": 0, "irtt": 0, "kind": "route"}] diff --git a/tests/fixtures/ubuntu-18.04/netstat-rnee.out b/tests/fixtures/ubuntu-18.04/netstat-rnee.out new file mode 100644 index 00000000..be841a85 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/netstat-rnee.out @@ -0,0 +1,5 @@ +Kernel IP routing table +Destination Gateway Genmask Flags Metric Ref Use Iface MSS Window irtt +0.0.0.0 192.168.71.2 0.0.0.0 UG 100 0 0 ens33 0 0 0 +192.168.71.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33 0 0 0 +192.168.71.2 0.0.0.0 255.255.255.255 UH 100 0 0 ens33 0 0 0 diff --git a/tests/test_netstat.py b/tests/test_netstat.py index 38634343..82b201df 100644 --- a/tests/test_netstat.py +++ b/tests/test_netstat.py @@ -9,7 +9,11 @@ THIS_DIR = os.path.dirname(os.path.abspath(__file__)) class MyTests(unittest.TestCase): def setUp(self): + # # input + # + + # netstat with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat.out'), 'r', encoding='utf-8') as f: self.centos_7_7_netstat = f.read() @@ -52,6 +56,24 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-Abn.out'), 'r', encoding='utf-8') as f: self.osx_14_6_netstat_Abn = f.read() + # netstat -r + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-r.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_netstat_r = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-rne.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_netstat_rne = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-rnee.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_netstat_rnee = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-r.out'), 'r', encoding='utf-8') as f: + self.ubuntu_18_4_netstat_r = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-rne.out'), 'r', encoding='utf-8') as f: + self.ubuntu_18_4_netstat_rne = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-rnee.out'), 'r', encoding='utf-8') as f: + self.ubuntu_18_4_netstat_rnee = f.read() with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-r.out'), 'r', encoding='utf-8') as f: self.osx_14_6_netstat_r = f.read() @@ -59,7 +81,11 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-rnl.out'), 'r', encoding='utf-8') as f: self.osx_14_6_netstat_rnl = f.read() + # # output + # + + # netstat with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat.json'), 'r', encoding='utf-8') as f: self.centos_7_7_netstat_json = json.loads(f.read()) @@ -102,6 +128,25 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-Abn.json'), 'r', encoding='utf-8') as f: self.osx_14_6_netstat_Abn_json = json.loads(f.read()) + # netsat -r + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-r.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_netstat_r_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-rne.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_netstat_rne_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-rnee.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_netstat_rnee_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-r.json'), 'r', encoding='utf-8') as f: + self.ubuntu_18_4_netstat_r_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-rne.json'), 'r', encoding='utf-8') as f: + self.ubuntu_18_4_netstat_rne_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-rnee.json'), 'r', encoding='utf-8') as f: + self.ubuntu_18_4_netstat_rnee_json = json.loads(f.read()) + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-r.json'), 'r', encoding='utf-8') as f: self.osx_14_6_netstat_r_json = json.loads(f.read()) @@ -192,6 +237,42 @@ class MyTests(unittest.TestCase): """ self.assertEqual(jc.parsers.netstat.parse(self.osx_14_6_netstat_Abn, quiet=True), self.osx_14_6_netstat_Abn_json) + def test_netstat_r_centos_7_7(self): + """ + Test 'netstat -r' on Centos 7.7 + """ + self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_r, quiet=True), self.centos_7_7_netstat_r_json) + + def test_netstat_rne_centos_7_7(self): + """ + Test 'netstat -rne' on Centos 7.7 + """ + self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_rne, quiet=True), self.centos_7_7_netstat_rne_json) + + def test_netstat_rnee_centos_7_7(self): + """ + Test 'netstat -rnee' on Centos 7.7 + """ + self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_rnee, quiet=True), self.centos_7_7_netstat_rnee_json) + + def test_netstat_r_ubuntu_18_4(self): + """ + Test 'netstat -r' on Ubuntu 18.4 + """ + self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_r, quiet=True), self.ubuntu_18_4_netstat_r_json) + + def test_netstat_rne_ubuntu_18_4(self): + """ + Test 'netstat -rne' on Ubuntu 18.4 + """ + self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_rne, quiet=True), self.ubuntu_18_4_netstat_rne_json) + + def test_netstat_rnee_ubuntu_18_4(self): + """ + Test 'netstat -rnee' on Ubuntu 18.4 + """ + self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_rnee, quiet=True), self.ubuntu_18_4_netstat_rnee_json) + def test_netstat_r_osx_16_4(self): """ Test 'netstat -r' on OSX 16.4