Skip to content

Commit

Permalink
test(dependencies): add test for threshold checking
Browse files Browse the repository at this point in the history
  • Loading branch information
scriptprivate authored Aug 28, 2024
1 parent ce7edce commit 081f273
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions tests/dependencies-threshold-checking.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env perl

use strict;
use warnings;
use Test::More;
use Test::Exception;
use Test::MockObject;
use Test::Output;

{
package Mojo::UserAgent;
use Test::MockObject;

my $mock_response;

sub new {
my $class = shift;
return Test::MockObject -> new -> mock('get', sub {
my ($self, $url, $headers) = @_;
return Test::MockObject -> new -> mock('result', sub {
return $mock_response;
});
});
}

sub set_mock_response {
my ($class, $response) = @_;
$mock_response = $response;
return;
}
}

use lib '../lib';
use SecurityGate::Engine::Dependencies;

subtest 'Threshold checking' => sub {
plan tests => 2;

my $mock_response = Test::MockObject -> new;
Mojo::UserAgent -> set_mock_response($mock_response);
$mock_response -> set_always('code', 200);
$mock_response -> set_always('json', [
{ state => 'open', security_vulnerability => { severity => 'critical' } },
{ state => 'open', security_vulnerability => { severity => 'critical' } },
]);

my %severity_limits_exceeded = (
critical => 1,
high => 0,
medium => 0,
low => 0
);

my %severity_limits_not_exceeded = (
critical => 2,
high => 0,
medium => 0,
low => 0
);

is(
SecurityGate::Engine::Dependencies -> new('test_token', 'test_repo', \%severity_limits_exceeded),
1,
'Returns 1 when threshold is exceeded'
);

is(
SecurityGate::Engine::Dependencies -> new('test_token', 'test_repo', \%severity_limits_not_exceeded),
0,
'Returns 0 when threshold is not exceeded'
);
};

done_testing();

0 comments on commit 081f273

Please sign in to comment.