Skip to content

Commit

Permalink
wip: improved mojo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Feb 7, 2024
1 parent 268bf4c commit 8923947
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/Ravada.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6367,6 +6367,7 @@ sub _req_method {
,pause => \&_cmd_pause
,create => \&_cmd_create
,remove => \&_cmd_remove
,remove_domain => \&_cmd_remove
,remove_clones => \&_cmd_remove_clones
,restore_domain => \&_cmd_restore_domain
,resume => \&_cmd_resume
Expand Down
5 changes: 5 additions & 0 deletions t/mojo/10_login.t
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,15 @@ sub test_login_non_admin_req($t, $base, $clone){

mojo_check_login($t, $name, $pass);
$base->is_public(0);
$base->show_clones(1);

$t->get_ok("/machine/clone/".$base->id.".html")
->status_is(200);
die "Error cloning ".$base->id if $t->tx->res->code() != 200;

$base->show_clones(0);
$t->get_ok("/machine/clone/".$base->id.".html")
->status_is(403);
}


Expand Down
39 changes: 32 additions & 7 deletions t/mojo/30_settings.t
Original file line number Diff line number Diff line change
Expand Up @@ -512,16 +512,46 @@ sub clean_clones() {
}
}

sub _create_storage_pool($id_vm , $vm_name) {
$t->get_ok("/list_storage_pools/$vm_name");
my $sp = decode_json($t->tx->res->body);
my $name = new_pool_name();
my ($found) = grep { $_->{name} eq $name } @$sp;
return $name if $found;

my $dir0 = "/var/tmp/$$/";

mkdir $dir0 if !-e $dir0;

my $dir = $dir0."/".new_pool_name();

mkdir $dir or die "$! $dir" if !-e $dir;


my $req = Ravada::Request->create_storage_pool(
uid => user_admin->id
,id_vm => $id_vm
,name => $name
,directory => $dir
);
wait_request( );
is($req->error,'');

return $name;
}

sub test_storage_pools($vm_name) {

my $id_vm = _id_vm($vm_name);
my $sp_name = _create_storage_pool($id_vm, $vm_name);

$t->get_ok("/list_storage_pools/$vm_name");

is($t->tx->res->code(),200) or die $t->tx->res->body;

my $sp = decode_json($t->tx->res->body);
ok(scalar(@$sp));

my $id_vm = _id_vm($vm_name);

$t->get_ok("/list_storage_pools/$id_vm");

is($t->tx->res->code(),200) or die $t->tx->res->body;
Expand All @@ -532,11 +562,6 @@ sub test_storage_pools($vm_name) {

my ($sp_inactive) = grep { $_->{name} ne 'default' } @$sp_id;

if ( !$sp_inactive ) {
# warn "Warning: no sp in addition to 'default' in ".Dumper($sp_id);
$sp_inactive = $sp_id->[0];
}

my $name_inactive= $sp_inactive->{name};
die "Error, no name in ".Dumper($sp_inactive) if !$name_inactive;

Expand Down

0 comments on commit 8923947

Please sign in to comment.