summaryrefslogtreecommitdiff
blob: 3cd799a629b7bb949e7b03fd6ae986f180b67074 (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
From 38c823ef25d78205e24314233ae7a503967b53e9 Mon Sep 17 00:00:00 2001
From: Kent Fredric <kentnl@gentoo.org>
Date: Wed, 13 Dec 2017 22:22:20 +1300
Subject: Guard tests that require network device names and root via ENV

---
 Makefile.PL     |  9 ---------
 t/arp_lookup.t  | 10 ++++++++--
 t/send_packet.t | 13 +++++++++++--
 test.pl         | 23 ++++++++---------------
 4 files changed, 27 insertions(+), 28 deletions(-)

diff --git a/Makefile.PL b/Makefile.PL
index e1a4ee7..fbfe0b0 100755
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -18,15 +18,6 @@
 use ExtUtils::MakeMaker;
 use Config;
 
-BEGIN {
-      eval { require Net::Pcap };
-
-      if($@)
-      {
-          print "Module Net::Pcap is required for make test!\n";
-      }
-}
-
 if($Config{'osname'} =~ /linux/i)
 {
     $flags = "-DLINUX";
diff --git a/t/arp_lookup.t b/t/arp_lookup.t
index 4cf9626..df68c90 100644
--- a/t/arp_lookup.t
+++ b/t/arp_lookup.t
@@ -13,8 +13,14 @@ ok( $mac eq "unknown", "unkown mac on strange dev value -> $mac" );
 $mac = Net::ARP::arp_lookup("$fu","127.0.0.1");
 ok( $mac eq "unknown", "unkown mac on strange dev value 2 -> $mac" );
 
-$mac = Net::ARP::arp_lookup("eth0","this_is_not_an_ip_address");
-ok( $mac eq "unknown", "unkown mac on strange ip value -> $mac" );
+SKIP: {
+
+  skip "TEST_ARP_IF unset", 1 unless exists $ENV{TEST_ARP_IF};
+
+  $mac = Net::ARP::arp_lookup($ENV{TEST_ARP_IF},"this_is_not_an_ip_address");
+  ok( $mac eq "unknown", "unkown mac on strange ip value -> $mac" );
+
+}
 
 #Net::ARP::arp_lookup("eth0","192.168.1.1","fu");
 #ok( $mac eq "unknown", "unkown mac on strange mac value" );
diff --git a/t/send_packet.t b/t/send_packet.t
index 1f95f4f..3b4b998 100644
--- a/t/send_packet.t
+++ b/t/send_packet.t
@@ -5,9 +5,18 @@
 # Last update: 22.06.2013
 
 use Net::ARP;
-use Test::More qw( no_plan );
+use Test::More;
+BEGIN {
+  if ( $> != 0 )  {
+      plan skip_all => "This test must be run as root";
+  }
+  if ( not exists $ENV{TEST_ARP_IF} ) {
+    plan skip_all => "TEST_ARP_IF not specified";
+  }
+  $dev = $ENV{TEST_ARP_IF};
+  plan qw/no_plan/;
+}
 
-$dev="lo";
 print "Using device $dev to test send_packet()\n";
 
 $ret = Net::ARP::send_packet("strange_dev",   # network interface
diff --git a/test.pl b/test.pl
index 27af515..c2e4cc2 100755
--- a/test.pl
+++ b/test.pl
@@ -19,23 +19,16 @@
 use ExtUtils::testlib;
 use Net::ARP;
 
-BEGIN
-{
-    eval{ require Net::Pcap; };
-              
-    if($@ =~ /^Can\'t\slocate/)
-    {
-        $dev = "eth0";
-    }
-    else
-    {
-   	import Net::Pcap;
-        $dev = Net::Pcap::lookupdev(\$errbuf);
-    }
+if ( $> != 0 ) {
+  print "SKIPPED: test must be run as root\n";
+  exit 0;
 }
-
+if ( not exists $ENV{TEST_ARP_IF} ) {
+  print "SKIPPED: TEST_ARP_IF unset\n";
+  exit 0;
+}
+$dev = $ENV{TEST_ARP_IF};
 print "Sending ARP reply packet via dev $dev... ";
-
 $ret = Net::ARP::send_packet($dev,                           # network interface
 		      '127.0.0.1',                    # source ip
 	              '127.0.0.1',                    # destination ip
-- 
2.14.3