Debian Codegraph @

lemonldap-ng-manager/t/11-save-appCat-changed-conf.t

raw
1 # Verify that an unmodified configuration is rejected
2
3 use warnings;
4 use Data::Dumper;
5 use Test::More;
6 use strict;
7 use JSON;
8 require 't/test-lib.pm';
9
10 my @struct = qw[t/jsonfiles/03-base-tree-appCat-modifed.json];
11 my @desc = ('Changed conf with deleted Category');
12 my $confFiles =
13 [ "$main::tmpdir/conf/lmConf-1.json", "$main::tmpdir/conf/lmConf-2.json" ];
14
15 # Try to save a modified conf
16 for my $filename (@struct) {
17
18 my ( $len, $body ) = substitute_io_handle($filename);
19 my $desc = shift @desc;
20 my ( $res, $resBody );
21 ok(
22 $res = &client->_post(
23 '/confs/', 'cfgNum=1', $body, 'application/json', $len
24 ),
25 "$desc: positive result"
26 );
27 ok( $res->[0] == 200, "$desc: result code is 200" )
28 or print STDERR Dumper($res);
29 ok(
30 $resBody = from_json( $res->[2]->[0] ),
31 "$desc: result body contains JSON text"
32 );
33
34 #print STDERR Dumper($resBody);
35 ok( $resBody->{result} == 1, "$desc: JSON response contains \"result:1\"" );
36 ok( @{ $resBody->{details}->{__changes__} } eq 2,
37 "$desc: conf has changed" )
38 or print STDERR Dumper($resBody);
39 ok(
40 $resBody->{details}->{__changes__}->[0]->{new} eq
41 'categoryList, Administration, Documentation',
42 "$desc: new key received"
43 ) or print STDERR Dumper($resBody);
44 ok(
45 $resBody->{details}->{__changes__}->[0]->{old} eq
46 'categoryList, Administration, Documentation, Sample applications',
47 "$desc: old key received"
48 ) or print STDERR Dumper($resBody);
49 ok(
50 $resBody->{details}->{__changes__}->[0]->{key} eq
51 'Deletes in cat(s), Sample applications',
52 "$desc: key received"
53 ) or print STDERR Dumper($resBody);
54 ok( -e $confFiles->[1], "$desc: file is created" );
55
56 #print STDERR Dumper($resBody);
57 count(9);
58 }
59 eval { unlink $confFiles->[1]; rmdir $main::tmpdir; };
60
61 done_testing( count() );