02-get_functions.t 1.4 KB

1234567891011121314151617181920212223242526
  1. use warnings;
  2. use strict;
  3. use Test::More 'tests' => 12;
  4. use Disk::SMART;
  5. my $disk = '/dev/sda';
  6. my $smart = Disk::SMART->new($disk);
  7. ok( $smart->get_disk_temp($disk), 'get_disk_temp() returns drive temperature or N/A' );
  8. is( eval{$smart->get_disk_temp('/dev/sdz')}, undef, 'get_disk_temp() returns failure when passed invalid device' );
  9. like( $smart->get_disk_health($disk), qr/PASSED|FAILED|N\/A/, 'get_disk_health() returns health status or N/A' );
  10. is( eval{$smart->get_disk_health('/dev/sdz')}, undef, 'get_disk_health() returns failure when passed invalid device' );
  11. cmp_ok( length $smart->get_disk_model($disk), '>=', 3, 'get_disk_model() returns disk model or N/A' );
  12. is( eval{$smart->get_disk_errors('/dev/sdz')}, undef, 'get_disk_model() returns failure when passed invalid device' );
  13. like( $smart->get_disk_errors($disk), qr/\w+/, 'get_disk_errors() returns proper string' );
  14. is( eval{$smart->get_disk_errors('/dev/sdz')}, undef, 'get_disk_errors() returns failure when passed invalid device' );
  15. cmp_ok( scalar( keys $smart->get_disk_attributes($disk) ), '>', 1, 'get_disk_attributes() returns hash of device attributes' );
  16. is( eval{$smart->get_disk_attributes('/dev/sdz')}, undef, 'get_disk_attributes() returns failure when passed invalid device' );
  17. is( $smart->update_data($disk), 1, 'update_data() updated object with current device data' );
  18. is( eval{$smart->update_data('/dev/sdz')}, undef, 'update_data() returns falure when passed invalid device' );