simulated hostname file and ability to declare a different file for Host probe
Robert 'phaylon' Sedlacek [Wed, 11 Jul 2012 21:39:16 +0000 (21:39 +0000)]
lib/System/Introspector/Probe/Host.pm
t/data/hostname [new file with mode: 0644]
t/host.t

index 4330c2d..530875f 100644 (file)
@@ -8,6 +8,8 @@ use System::Introspector::Util qw(
     transform_exceptions
 );
 
+has hostname_file => (is => 'ro', default => sub {'/etc/hostname' });
+
 sub gather {
     my ($self) = @_;
     return transform_exceptions {
@@ -43,7 +45,7 @@ sub _gather_uname_info {
 
 sub _gather_hostname {
     my ($self) = @_;
-    my $hostname = output_from_file '/etc/hostname';
+    my $hostname = output_from_file $self->hostname_file;
     chomp $hostname;
     $hostname =~ s{(?:^\s+|\s+$)}{}g;
     return $hostname;
diff --git a/t/data/hostname b/t/data/hostname
new file mode 100644 (file)
index 0000000..3929a1c
--- /dev/null
@@ -0,0 +1 @@
+foo-bar
index 4e64d9e..04ef558 100644 (file)
--- a/t/host.t
+++ b/t/host.t
@@ -1,10 +1,13 @@
 use strictures 1;
 use Test::More;
+use FindBin;
 
 use System::Introspector::Probe::Host;
 
-my $probe = System::Introspector::Probe::Host->new;
-my $data  = $probe->gather;
+my $probe = System::Introspector::Probe::Host->new(
+    hostname_file => "$FindBin::Bin/data/hostname",
+);
+my $data = $probe->gather;
 
 ok length($data->{hostname}), 'found a hostname';
 ok defined($data->{uname}{ $_ }), "has uname $_" for qw(