Newer Older
f16725e 3 months ago History
55 lines | 1.467kb
Bogdan Timofte authored 3 months ago
1
#!/usr/bin/perl
2

            
3
use strict;
4
use warnings;
5
use DBI;
6

            
7
print "=== autoSMART Database Test ===\n\n";
8

            
9
my $dsn = "DBI:Pg:dbname=autosmart;host=192.168.2.102;port=5432";
10
my $dbh = DBI->connect($dsn, "autosmart", "autoSMART2025!", {
11
    RaiseError => 1,
12
    AutoCommit => 1,
13
    PrintError => 0
14
}) or die "Failed to connect to database: $DBI::errstr\n";
15

            
16
print "✓ Database connection successful\n";
17

            
18
# Test tables exist
19
my @tables = qw(hdd_inventory hdd_migrations smart_readings predictions smart_thresholds alert_history system_config);
20

            
21
for my $table (@tables) {
22
    my $sth = $dbh->prepare("SELECT COUNT(*) FROM $table");
23
    $sth->execute();
24
    my ($count) = $sth->fetchrow_array();
25
    print "✓ Table $table: $count rows\n";
26
}
27

            
28
# Test views
29
my @views = qw(smart_readings_reconstructed latest_smart_readings drive_health_summary);
30

            
31
for my $view (@views) {
32
    eval {
33
        my $sth = $dbh->prepare("SELECT COUNT(*) FROM $view");
34
        $sth->execute();
35
        my ($count) = $sth->fetchrow_array();
36
        print "✓ View $view: $count rows\n";
37
    };
38
    if ($@) {
39
        print "✗ View $view: ERROR - $@\n";
40
    }
41
}
42

            
43
# Test function
44
eval {
45
    my $sth = $dbh->prepare("SELECT should_store_smart_reading(1, '{}', 'test', NOW())");
46
    $sth->execute();
47
    print "✓ Function should_store_smart_reading: Available\n";
48
};
49
if ($@) {
50
    print "✗ Function should_store_smart_reading: ERROR - $@\n";
51
}
52

            
53
$dbh->disconnect();
54

            
55
print "\n=== Test Complete ===\n";