<commit_before>#! /usr/bin/env perl

use strict;
use warnings;

use Test::More;
use Artemis::CLI::Testrun;
use Artemis::Schema::TestTools;
use Artemis::Model 'model';
use Test::Fixture::DBIC::Schema;

# -----------------------------------------------------------------------------------------------------------------
construct_fixture( schema  => testrundb_schema, fixture => 't/fixtures/testrundb/testruns_with_scheduling.yml' );
# -----------------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------------
construct_fixture( schema  => hardwaredb_schema, fixture => 't/fixtures/hardwaredb/systems.yml' );
# -----------------------------------------------------------------------------------------------------------------

my $host_id = `/usr/bin/env perl -Ilib bin/artemis-testrun newhost  --name="host1"`;
chomp $host_id;

my $host_result = model('TestrunDB')->resultset('Host')->find($host_id);
ok($host_result->id, 'inserted host without option / id');
ok($host_result->free, 'inserted host  without option / free');
is($host_result->name, 'host1', 'inserted host without option / name');

# --------------------------------------------------

$host_id = `/usr/bin/env perl -Ilib bin/artemis-testrun newhost  --name="host2" --active --queue=KVM`;
chomp $host_id;

$host_result = model('TestrunDB')->resultset('Host')->find($host_id);
ok($host_result->id, 'inserted host with active and existing queue / id');
is($host_result->name, 'host2', 'inserted host with active and existing queue / name');
ok($host_result->active, 'inserted host with active and existing queue / active');
ok($host_result->free, 'inserted host with active and existing queue / free');

# --------------------------------------------------

$host_id = `/usr/bin/env perl -Ilib bin/artemis-testrun newhost  --name="host3" --queue=Xen --queue=KVM`;
chomp $host_id;

$host_result = model('TestrunDB')->resultset('Host')->find($host_id);
ok($host_result->id, 'inserted host with multiple existing queues / id');
is($host_result->name, 'host3', 'inserted host with multiple existing queues / name');
is($host_result->active, undef, 'inserted host with multiple existing queues / active');
ok($host_result->free, 'inserted host with multiple existing queues / free');
if ($host_result->queuehosts->count) {
        my @queue_names = map {$_->queue->name} $host_result->queuehosts->all;
        is_deeply(['Xen', 'KVM'] , \@queue_names, 'inserted host with multiple existing queues / queues');
}
else {
        fail("Queues assigned to host");
}

# --------------------------------------------------
$host_id = qx(/usr/bin/env perl -Ilib bin/artemis-testrun newhost  --name="host4" --queue=noexist 2>&1);
like($host_id, qr(No such queue: noexist), 'Error handling for nonexistent queue');


# --------------------------------------------------
my $hosts = qx(/usr/bin/env perl -Ilib bin/artemis-testrun listhost --queue=KVM 2>&1);
like($hosts, qr(11 *| *host2\n *12 *| *host3\n), 'Show hosts / queue');


# --------------------------------------------------
qx(/usr/bin/env perl -Ilib bin/artemis-testrun updatehost --delqueue --active --id=7 2>&1);
is($?, 0, 'Update host / return value');
$host_result = model('TestrunDB')->resultset('Host')->find(7);
ok($host_result->active, 'Update host / active');
is($host_result->queuehosts->count, 0, 'Update host / delete all queues');


# --------------------------------------------------
$host_result = model('TestrunDB')->resultset('Host')->find(7);
ok($host_result, 'Delete host / host exists before delete');
qx(/usr/bin/env perl -Ilib bin/artemis-testrun deletehost --id=7 2>&1);
$host_result = model('TestrunDB')->resultset('Host')->find(7);
is($host_result, undef, 'Delete host / host does not exist after delete');






done_testing();<commit_msg>CLI: added really to delete host unit test<commit_after>#! /usr/bin/env perl

use strict;
use warnings;

use Test::More;
use Artemis::CLI::Testrun;
use Artemis::Schema::TestTools;
use Artemis::Model 'model';
use Test::Fixture::DBIC::Schema;

# -----------------------------------------------------------------------------------------------------------------
construct_fixture( schema  => testrundb_schema, fixture => 't/fixtures/testrundb/testruns_with_scheduling.yml' );
# -----------------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------------
construct_fixture( schema  => hardwaredb_schema, fixture => 't/fixtures/hardwaredb/systems.yml' );
# -----------------------------------------------------------------------------------------------------------------

my $host_id = `/usr/bin/env perl -Ilib bin/artemis-testrun newhost  --name="host1"`;
chomp $host_id;

my $host_result = model('TestrunDB')->resultset('Host')->find($host_id);
ok($host_result->id, 'inserted host without option / id');
ok($host_result->free, 'inserted host  without option / free');
is($host_result->name, 'host1', 'inserted host without option / name');

# --------------------------------------------------

$host_id = `/usr/bin/env perl -Ilib bin/artemis-testrun newhost  --name="host2" --active --queue=KVM`;
chomp $host_id;

$host_result = model('TestrunDB')->resultset('Host')->find($host_id);
ok($host_result->id, 'inserted host with active and existing queue / id');
is($host_result->name, 'host2', 'inserted host with active and existing queue / name');
ok($host_result->active, 'inserted host with active and existing queue / active');
ok($host_result->free, 'inserted host with active and existing queue / free');

# --------------------------------------------------

$host_id = `/usr/bin/env perl -Ilib bin/artemis-testrun newhost  --name="host3" --queue=Xen --queue=KVM`;
chomp $host_id;

$host_result = model('TestrunDB')->resultset('Host')->find($host_id);
ok($host_result->id, 'inserted host with multiple existing queues / id');
is($host_result->name, 'host3', 'inserted host with multiple existing queues / name');
is($host_result->active, undef, 'inserted host with multiple existing queues / active');
ok($host_result->free, 'inserted host with multiple existing queues / free');
if ($host_result->queuehosts->count) {
        my @queue_names = map {$_->queue->name} $host_result->queuehosts->all;
        is_deeply(['Xen', 'KVM'] , \@queue_names, 'inserted host with multiple existing queues / queues');
}
else {
        fail("Queues assigned to host");
}

# --------------------------------------------------
$host_id = qx(/usr/bin/env perl -Ilib bin/artemis-testrun newhost  --name="host4" --queue=noexist 2>&1);
like($host_id, qr(No such queue: noexist), 'Error handling for nonexistent queue');


# --------------------------------------------------
my $hosts = qx(/usr/bin/env perl -Ilib bin/artemis-testrun listhost --queue=KVM 2>&1);
like($hosts, qr(11 *| *host2\n *12 *| *host3\n), 'Show hosts / queue');


# --------------------------------------------------
qx(/usr/bin/env perl -Ilib bin/artemis-testrun updatehost --delqueue --active --id=7 2>&1);
is($?, 0, 'Update host / return value');
$host_result = model('TestrunDB')->resultset('Host')->find(7);
ok($host_result->active, 'Update host / active');
is($host_result->queuehosts->count, 0, 'Update host / delete all queues');


# --------------------------------------------------
$host_result = model('TestrunDB')->resultset('Host')->find(7);
ok($host_result, 'Delete host / host exists before delete');
qx(/usr/bin/env perl -Ilib bin/artemis-testrun deletehost --id=7 --really 2>&1);
$host_result = model('TestrunDB')->resultset('Host')->find(7);
is($host_result, undef, 'Delete host / host does not exist after delete');






done_testing();
{'fraction_non_alphanumeric': 0.3338824125696908, 'fraction_numerical': 0.007095793208312215, 'mean_word_length': 2.0819992190550565, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '879270', 'n_tokens_mistral': 2287, 'n_tokens_neox': 2213, 'n_words': 551}