From ede74d0b3cc916bab1504dac1ec2e8f68c206a6c Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 15 Mar 2023 11:14:19 -0300 Subject: [PATCH] Bug 33227: Unit tests This patch adds a unit test that launches the swagger-cli validator against our spec. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 502e34e9b0f709d0ab9260da107c1c1e5c7e11d8) Signed-off-by: Matt Blenkinsop --- xt/api.t | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/xt/api.t b/xt/api.t index 1dd206f498..0dc8dccb86 100755 --- a/xt/api.t +++ b/xt/api.t @@ -14,11 +14,14 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use Test::Mojo; use Data::Dumper; +use FindBin(); +use IPC::Cmd qw(can_run); + my $t = Test::Mojo->new('Koha::REST::V1'); my $spec = $t->get_ok( '/api/v1/', 'Correctly fetched the spec' )->tx->res->json; @@ -75,3 +78,18 @@ foreach my $route ( keys %{$paths} ) { is( scalar @missing_additionalProperties, 0 ) or diag Dumper \@missing_additionalProperties; + +subtest 'The spec passes the swagger-cli validation' => sub { + + plan tests => 1; + + SKIP: { + skip "Skipping tests, swagger-cli missing", 1 + unless can_run('swagger-cli'); + + my $spec_dir = "$FindBin::Bin/../api/v1/swagger"; + my $var = qx{swagger-cli validate $spec_dir/swagger.yaml 2>&1}; + is( $?, 0, 'Validation exit code is 0' ) + or diag $var; + } +}; -- 2.39.5