Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor tests, update cpanfile and add workflow for running test suite #12

Merged
merged 10 commits into from
Sep 30, 2024
Merged
28 changes: 28 additions & 0 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test Suite

on:
pull_request:
branches:
- main
- develop

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Perl
run: |
sudo apt-get update
sudo apt-get install -y perl
sudo apt-get install -y cpanminus

- name: Install dependencies
run: sudo cpanm --installdeps --with-test .

- name: Run tests
working-directory: ./tests
run: prove -r
5 changes: 4 additions & 1 deletion .perlcriticrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
severity = 3

[-TestingAndDebugging::RequireUseStrict]
[-TestingAndDebugging::RequireUseWarnings]
[-TestingAndDebugging::RequireUseWarnings]

[TestingAndDebugging::ProhibitNoWarnings]
allow = once
10 changes: 9 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
requires "Getopt::Long", "2.54";
requires "Mojo::JSON";
requires "Mojo::UserAgent";
requires "Mojo::UserAgent";

on 'test' => sub {
requires "Test::More";
requires "Test::Exception";
requires "Test::MockObject";
requires "Test::Output";
requires "Capture::Tiny";
};
1 change: 1 addition & 0 deletions tests/no-open-secret-scanning-alerts.t
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ BEGIN {
}
}

no warnings 'once';
*Mojo::UserAgent::new = \&MockMojoUserAgent::new;

subtest 'No open secret scanning alerts' => sub {
Expand Down
8 changes: 4 additions & 4 deletions tests/open-code-scanning-alerts-exceeding-limits.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ subtest 'Open code scanning alerts exceeding limits' => sub {

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

my %severity_limits = (
Expand Down
1 change: 1 addition & 0 deletions tests/open-secret-scanning-alerts-exceeding-limits.t
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ BEGIN {
}
}

no warnings 'once';
*Mojo::UserAgent::new = \&MockMojoUserAgent::new;

subtest 'Open secret scanning alerts exceeding limits' => sub {
Expand Down
5 changes: 3 additions & 2 deletions tests/open-secret-scanning-alerts-within-limits.t
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ BEGIN {
}
}

no warnings 'once';
*Mojo::UserAgent::new = \&MockMojoUserAgent::new;

subtest 'Open secret scanning alerts within limits' => sub {
Expand All @@ -60,7 +61,7 @@ subtest 'Open secret scanning alerts within limits' => sub {
]);

MockMojoUserAgent::setup_locations_response(200, [
{ path => 'file1.txt', start_line => 10 },
{ details => { path => 'file.txt', start_line => 10 } },
]);

my %severity_limits = (
Expand All @@ -73,7 +74,7 @@ subtest 'Open secret scanning alerts within limits' => sub {
my $result;
my $expected_output_part1 = qr/\[!\]\ Total\ of\ open\ secret\ scanning\ alerts:\ 1/xsm;
my $expected_output_part2 = qr/\[-\]\ Alert\ 1\ found\ in\ the\ following\ locations:/xsm;
my $expected_output_part3 = qr/File:\ file1\.txt,\ Start\ line:\ 10/xsm;
my $expected_output_part3 = qr/File:\ file\.txt,\ Start\ line:\ 10/xsm;
my $expected_output_part4_part1 = qr/\[-\]\ Number\ of\ secret\ scanning\ alerts\ \(/xsm;
my $expected_output_part4_part2 = qr/1\)\ is\ within\ the\ acceptable\ limit\ \(/xsm;
my $expected_output_part4_part3 = qr/1\)\./xsm;
Expand Down
1 change: 1 addition & 0 deletions tests/secrets-api-error-handling.t
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ BEGIN {
}
}

no warnings 'once';
*Mojo::UserAgent::new = \&MockMojoUserAgent::new;

subtest 'API error handling' => sub {
Expand Down
179 changes: 0 additions & 179 deletions tests/security-gate.t

This file was deleted.

Loading