App-FuguVM

 view release on metacpan or  search on metacpan

t/fuguvm/state.t  view on Meta::CPAN

    my $state3 = App::FuguVM::State->new($tmpdir, 'test');
    is($state3->get_vm_pid, undef, 'VM PID cleared persists after reload');
}

# Test is_vm_running (with fake PID)
{
    my $tmpdir = tempdir(CLEANUP => 1);
    my $state = App::FuguVM::State->new($tmpdir, 'test');
    
    # Use the current process PID, which is running
    $state->vm_pidfile->write_pid($$);
    ok($state->is_vm_running, 'is_vm_running returns true for running process');
    
    # Use an invalid PID
    $state->vm_pidfile->write_pid(99999999);
    ok(!$state->is_vm_running, 'is_vm_running returns false for non-running process');
}

# The proxy child rides on its own pid file, apart from the VM's
{
    my $tmpdir = tempdir(CLEANUP => 1);
    my $state = App::FuguVM::State->new($tmpdir, 'test');

    $state->proxy_pidfile->write_pid(22222);
    is($state->proxy_pidfile->read_pid, 22222,
	'proxy pidfile stores its own PID');
    ok(-f "$tmpdir/test/proxy.pid", 'proxy.pid is a separate file');

    $state->clear_vm_pid;
    is($state->proxy_pidfile->read_pid, 22222,
	'proxy PID unchanged after clearing VM PID');

    $state->proxy_pidfile->remove;
    ok(!-f "$tmpdir/test/proxy.pid", 'proxy.pid removed');
}

# Test installation state
{
    my $tmpdir = tempdir(CLEANUP => 1);
    my $state = App::FuguVM::State->new($tmpdir, 'test');
    
    ok(!$state->is_installed, 'Not installed initially');
    
    $state->mark_installed;
    ok($state->is_installed, 'Installed after mark_installed');
    
    # Reload the state and make sure that the value persists
    my $state2 = App::FuguVM::State->new($tmpdir, 'test');
    ok($state2->is_installed, 'Installation state persisted');
}

# Test disk paths
{
    my $tmpdir = tempdir(CLEANUP => 1);
    my $state = App::FuguVM::State->new($tmpdir, 'test');
    
    like($state->disk_path, qr/disk\.qcow2$/, 'disk_path ends with disk.qcow2');
    ok(!$state->disk_exists, 'disk_exists returns false when no disk');
}

# Test root password management
{
    my $tmpdir = tempdir(CLEANUP => 1);
    my $state = App::FuguVM::State->new($tmpdir, 'test');
    
    is($state->get_root_password, undef, 'No password initially');
    
    $state->set_root_password('testpass123');
    is($state->get_root_password, 'testpass123', 'Password stored and retrieved');
    
    # Reload the state and make sure that the value persists
    my $state2 = App::FuguVM::State->new($tmpdir, 'test');
    is($state2->get_root_password, 'testpass123', 'Password persisted');
}

# Test SSH key installation state
{
    my $tmpdir = tempdir(CLEANUP => 1);
    my $state = App::FuguVM::State->new($tmpdir, 'test');
    
    is($state->get_installed_ssh_pubkey, undef, 'No pubkey stored initially');
    
    my $test_pubkey = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... test@example';
    $state->mark_ssh_key_installed($test_pubkey);
    is($state->get_installed_ssh_pubkey, $test_pubkey, 'Pubkey stored correctly');
    
    # Reload the state and make sure that the value persists
    my $state2 = App::FuguVM::State->new($tmpdir, 'test');
    is($state2->get_installed_ssh_pubkey, $test_pubkey, 'Pubkey persisted correctly');
}

# ============================================================
# Robustness tests (from ROBUSTNESS-REPORT.md)
# ============================================================

# Issue 1: Extremely long VM name
{
    my $tmpdir = tempdir(CLEANUP => 1);
    
    # Suppress warnings for this test
    local $SIG{__WARN__} = sub {};
    
    my $long_name = 'x' x 10000;
    my $state = App::FuguVM::State->new($tmpdir, $long_name);
    is($state, undef, 'Long VM name (10000 chars) returns undef');
}

# Issue 1: a VM name at the boundary of 255 chars works
{
    my $tmpdir = tempdir(CLEANUP => 1);
    
    my $max_name = 'x' x 255;
    my $state = App::FuguVM::State->new($tmpdir, $max_name);
    ok(defined $state, 'VM name at 255 chars is accepted');
}

# Issue 1: a VM name over the boundary at 256 chars fails
{
    my $tmpdir = tempdir(CLEANUP => 1);
    
    local $SIG{__WARN__} = sub {};
    
    my $over_name = 'x' x 256;
    my $state = App::FuguVM::State->new($tmpdir, $over_name);
    is($state, undef, 'VM name at 256 chars returns undef');
}

# Issue 1: VM name with invalid characters (path separator)
{
    my $tmpdir = tempdir(CLEANUP => 1);
    
    local $SIG{__WARN__} = sub {};
    



( run in 1.960 second using v1.01-cache-2.11-cpan-4ef0a570458 )