Skip to content

Commit

Permalink
Fix test failures when optional keys in /sync are left out (#1040)
Browse files Browse the repository at this point in the history
* Fix test failures if presence, account_data or to_device keys are empty

Signed-off-by: Nicolas Werner <nicolas.werner@hotmail.de>

* Fix failures with empty room keys.

Signed-off-by: Nicolas Werner <nicolas.werner@hotmail.de>
  • Loading branch information
deepbluev7 authored May 5, 2021
1 parent af623da commit df27d43
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
21 changes: 15 additions & 6 deletions tests/30rooms/06invite.pl
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,11 @@ sub invited_user_can_reject_invite

# Check that invitee no longer sees the invite

assert_json_object( $body->{rooms}{invite} );
keys %{ $body->{rooms}{invite} } and die "Expected empty dictionary";
if( exists $body->{rooms} and exists $body->{rooms}{invite} ) {
assert_json_object( $body->{rooms}{invite} );
keys %{ $body->{rooms}{invite} } and die "Expected empty dictionary";
}

Future->done(1);
});
}
Expand Down Expand Up @@ -203,8 +206,10 @@ sub invited_user_can_reject_invite_for_empty_room

# Check that invitee no longer sees the invite

assert_json_object( $body->{rooms}{invite} );
keys %{ $body->{rooms}{invite} } and die "Expected empty dictionary";
if( exists $body->{rooms} and exists $body->{rooms}{invite} ) {
assert_json_object( $body->{rooms}{invite} );
keys %{ $body->{rooms}{invite} } and die "Expected empty dictionary";
}
Future->done(1);
});
}
Expand Down Expand Up @@ -235,8 +240,12 @@ sub invited_user_can_reject_invite_for_empty_room
my ( $body ) = @_;

log_if_fail "Sync body", $body;
assert_json_object( $body->{rooms}{invite} );
keys %{ $body->{rooms}{invite} } and die "Expected empty dictionary";

if( exists $body->{rooms} and exists $body->{rooms}{invite} ) {
assert_json_object( $body->{rooms}{invite} );
keys %{ $body->{rooms}{invite} } and die "Expected empty dictionary";
}

Future->done(1);
});
};
Expand Down
20 changes: 10 additions & 10 deletions tests/31sync/03joined.pl
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@
})->then( sub {
my ( $body ) = @_;

assert_json_keys( $body, qw( presence ));
assert_json_keys( $body->{presence}, qw( events ));
assert_json_list( $body->{presence}{events} );
if ( exists $body->{presence} and exists $body->{presence}{events} ) {
assert_json_list( $body->{presence}{events} );

my $presence = $body->{presence}{events};
my $presence = $body->{presence}{events};

assert_eq( scalar @$presence, 0, "number of presence events" );
assert_eq( scalar @$presence, 0, "number of presence events" );
}

Future->done(1);
});
Expand Down Expand Up @@ -289,13 +289,13 @@
})->then( sub {
my ( $body ) = @_;

assert_json_keys( $body, qw( presence ));
assert_json_keys( $body->{presence}, qw( events ));
assert_json_list( $body->{presence}{events} );
if ( exists $body->{presence} and exists $body->{presence}{events} ) {
assert_json_list( $body->{presence}{events} );

my $presence = $body->{presence}{events};
my $presence = $body->{presence}{events};

assert_eq( scalar @$presence, 0, "number of presence events" );
assert_eq( scalar @$presence, 0, "number of presence events" );
}

Future->done(1);
});
Expand Down
8 changes: 5 additions & 3 deletions tests/31sync/09archived.pl
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,12 @@
})->then( sub {
my ( $body ) = @_;

my $leave = $body->{rooms}{leave};
if( exists $body->{rooms} and exists $body->{rooms}{leave} ) {
my $leave = $body->{rooms}{leave};

assert_json_object( $leave );
keys %$leave == 0 or die "Expected no rooms in 'leave' state";
assert_json_object( $leave );
keys %$leave == 0 or die "Expected no rooms in 'leave' state";
}

Future->done(1);
});
Expand Down
6 changes: 4 additions & 2 deletions tests/31sync/15lazy-members.pl
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@
matrix_sync_again( $alice, filter => $filter_id );
})->then( sub {
my ( $body ) = @_;
my $joined_rooms = $body->{rooms}{join};
assert_deeply_eq($joined_rooms, {});
if( exists $body->{rooms} and exists $body->{rooms}{join} ) {
my $joined_rooms = $body->{rooms}{join};
assert_deeply_eq($joined_rooms, {});
}
Future->done(1);
});
};
Expand Down
2 changes: 1 addition & 1 deletion tests/46direct/01directmessage.pl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ sub matrix_recv_device_message
return 1 if $f->failure;
my $resp = $f->get;
log_if_fail "Sync response", $resp;
if( exists $resp->{to_device}{events} ) {
if( exists $resp->{to_device} and exists $resp->{to_device}{events} ) {
return scalar @{ $resp->{to_device}{events} };
}
};
Expand Down

0 comments on commit df27d43

Please sign in to comment.