diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/server/backend-t.in | 45 | 
1 files changed, 44 insertions, 1 deletions
| diff --git a/tests/server/backend-t.in b/tests/server/backend-t.in index 408cb0f..bac2105 100644 --- a/tests/server/backend-t.in +++ b/tests/server/backend-t.in @@ -5,7 +5,7 @@  use strict;  use IO::String; -use Test::More tests => 720; +use Test::More tests => 750;  # Create a dummy class for Wallet::Server that prints what method was called  # with its arguments and returns data for testing. @@ -48,6 +48,11 @@ sub acl_show {      return 'acl_show';  } +sub flag_clear +    { shift; print "flag_clear @_\n"; ($_[0] eq 'error') ? undef : 1 } +sub flag_set +    { shift; print "flag_set @_\n"; ($_[0] eq 'error') ? undef : 1 } +  sub acl {      shift;      print "acl @_\n"; @@ -139,6 +144,9 @@ is ($out, "$new\n", ' and nothing ran');  ($out, $err) = run_backend ('acl', 'foo');  is ($err, "unknown command acl foo\n", 'Unknown ACL command');  is ($out, "$new\n", ' and nothing ran'); +($out, $err) = run_backend ('flag', 'foo'); +is ($err, "unknown command flag foo\n", 'Unknown flag command'); +is ($out, "$new\n", ' and nothing ran');  # Check too few, too many, and bad arguments for every command.  my %commands = (create  => [2, 2], @@ -156,6 +164,8 @@ my %acl_commands = (add     => [3, 3],                      remove  => [3, 3],                      rename  => [2, 2],                      show    => [1, 1]); +my %flag_commands = (clear => [3, 3], +                     set   => [3, 3]);  for my $command (sort keys %commands) {      my ($min, $max) = @{ $commands{$command} };      ($out, $err) = run_backend ($command, ('foo') x ($min - 1)); @@ -199,6 +209,25 @@ for my $command (sort keys %acl_commands) {          is ($out, "$new\n", ' and nothing ran');      }  } +for my $command (sort keys %flag_commands) { +    my ($min, $max) = @{ $flag_commands{$command} }; +    ($out, $err) = run_backend ('flag', $command, ('foo') x ($min - 1)); +    is ($err, "insufficient arguments\n", +        "Too few arguments for flag $command"); +    is ($out, "$new\n", ' and nothing ran'); +    ($out, $err) = run_backend ('flag', $command, ('foo') x ($max + 1)); +    is ($err, "too many arguments\n", "Too many arguments for flag $command"); +    is ($out, "$new\n", ' and nothing ran'); +    my @base = ('foobar') x $max; +    for my $arg (0 .. ($max - 1)) { +        my @args = @base; +        $args[$arg] = 'foo;bar'; +        ($out, $err) = run_backend ('flag', $command, @args); +        is ($err, "invalid characters in argument: foo;bar\n", +            "Invalid arguments for flag $command $arg"); +        is ($out, "$new\n", ' and nothing ran'); +    } +}  # Now, test that we ran the right functions and passed the correct arguments.  my $error = 1; @@ -266,6 +295,20 @@ for my $command (sort keys %acl_commands) {          ' and ran the right method');      $error++;  } +for my $command (sort keys %flag_commands) { +    my @extra = ('foo') x ($flag_commands{$command}[0] - 2); +    my $extra = @extra ? join (' ', '', @extra) : ''; +    ($out, $err) = run_backend ('flag', $command, 'type', 'name', @extra); +    is ($err, '', "Command flag $command ran with no errors"); +    is ($out, "$new\nflag_$command type name$extra\n", +        ' and ran the right method'); +    ($out, $err) = run_backend ('flag', $command, 'error', 'name', @extra); +    is ($err, "error count $error\n", +        "Command flag $command ran with errors"); +    is ($out, "$new\nflag_$command error name$extra\n", +        ' and ran the right method'); +    $error++; +}  # Almost done.  All that remains is to test the robustness of the bad  # character checks against every possible character. | 
