Debian Codegraph @

lemonldap-ng-manager/t/04-misc-api.t

raw
1 # Test Providers API
2
3 use warnings;
4 use Test::More;
5 use strict;
6 use JSON;
7 use IO::String;
8 require 't/test-lib.pm';
9
10 sub LLNG::Manager::Test::getStatus {
11 my ( $client, $test, $expectCode ) = @_;
12 my $res;
13 ok( $res = $client->_get( "/api/v1/status", '' ),
14 "$test: Request succeed" );
15 is( $res->[0], $expectCode || 200, "$test: correct status code" );
16 count(1);
17 return from_json( $res->[2]->[0] );
18 }
19
20 my $client = LLNG::Manager::Test->new;
21
22 # "break" config file
23 rename "$main::tmpdir/conf/lmConf-1.json",
24 "$main::tmpdir/conf/lmConf-1.json.broken";
25 my $brokenconfig = $client->getStatus( "Broken config backend", 503 );
26 is( $brokenconfig->{status}, 'ko', 'Got expected global status' );
27 is( $brokenconfig->{status_config}, 'ko', 'Got expected config status' );
28 rename "$main::tmpdir/conf/lmConf-1.json.broken",
29 "$main::tmpdir/conf/lmConf-1.json";
30
31 my $allfine = $client->getStatus("Back to normal");
32 is( $allfine->{status}, 'ok', 'Got expected global status' );
33 is( $allfine->{status_config}, 'ok', 'Got expected config status' );
34 is( $allfine->{status_sessions}, 'unknown', 'Not implemented yet' );
35 is( $allfine->{status_psessions}, 'unknown', 'Not implemented yet' );
36
37 # Clean up generated files, except for "lmConf-1.json"
38 unlink grep { $_ ne "$main::tmpdir/conf/lmConf-1.json" }
39 glob "$main::tmpdir/conf/lmConf-*.json";
40
41 done_testing();