]> pd.if.org Git - newsd/commitdiff
Added capabilities response test.
authorNathan Wagner <nw@hydaspes.if.org>
Fri, 2 Dec 2011 10:23:12 +0000 (05:23 -0500)
committerNathan Wagner <nw@hydaspes.if.org>
Fri, 2 Dec 2011 10:23:12 +0000 (05:23 -0500)
t/02_capabilities.t [new file with mode: 0644]
t/03_responses.t [moved from t/02_responses.t with 100% similarity]

diff --git a/t/02_capabilities.t b/t/02_capabilities.t
new file mode 100644 (file)
index 0000000..33b80b0
--- /dev/null
@@ -0,0 +1,79 @@
+#!/usr/bin/perl
+
+use Test::More tests => 17; 
+
+BEGIN { use_ok('Net::Cmd') }
+BEGIN { use_ok('Net::NNTP') }
+
+my $c = Net::NNTP->new(Host => '127.0.0.1', Port => 20203, Reader => 0);
+
+ok(defined $c, 'connected to localhost');
+
+BAIL_OUT(q{can't connect to test server'}) unless $c;
+
+sub Net::NNTP::issue {
+       my ($c, @cmd) = @_;
+       $c->command(@cmd);
+       $c->response();
+       return $c->code();
+}
+
+sub Net::NNTP::try {
+       my ($c, $cmd, $test, @valid) = @_;
+       $c->command($cmd);
+       $c->response();
+       ok(scalar (grep {$c->code == $_} @valid) , "$test ".$c->code." in (@valid)");
+       return $c->code;
+}
+
+# 3977:5.1.1 initial greeting must be 200 201 400 502
+my @valid = (200, 201, 400, 502);
+my $greeting = $c->code;
+
+ok(grep {$c->code == $_} @valid, 'correct initial response from server');
+
+unless ($greeting == 200 or $greeting = 201) {
+       BAIL_OUT(q{bad greeting from server'});
+}
+
+# 4 tests done to here
+
+$c->try('CAPABILITIES','capabilities',101);
+
+SKIP: {
+       skip q{can't get capabilities}, 3 unless $c->code == 101;
+
+       my $capabilities = $c->read_until_dot() if ($c->code == 101);
+
+       my %cap = ();
+       my $twice = 0;
+       foreach my $line (@$capabilities) {
+               my ($capability, @arg) = split(/\s+/, $line);
+               if (exists($cap{$capability})) {
+                       $twice = 1;
+               }
+               $cap{$capability} = \@arg;
+       }
+
+       ok($twice == 0, 'No capability listed twice (3977:5.2.2)');
+       ok(exists $cap{READER}, 'announce READER');
+       is($cap{'MODE-READER'}, undef, q{don't announce MODE-READER});
+       foreach $trycap qw(ACTIVE NEWSGROUPS OVERVIEW.FMT
+               ACTIVE.TIMES HEADERS) {
+               cmp_ok(scalar(grep { $trycap eq $_ } @{$cap{LIST}}), '==', 1,
+                       "list capability $trycap");
+       }
+       foreach $trycap qw(MSGID) {
+               cmp_ok(scalar(grep { $trycap eq $_ } @{$cap{OVER}}), '==', 1,
+                       "list capability $trycap");
+       }
+
+       $capabilities->[0] =~ /(VERSION) (\d+)(\r?)(\n)/;
+
+       is($1, 'VERSION', 'VERSION capability first');
+       is($2, 2, 'Version 2 server');
+       skip q{can only test version 2 servers}, 0 unless $2 == 2;
+
+}
+
+$c->try('QUIT','quit',205);
similarity index 100%
rename from t/02_responses.t
rename to t/03_responses.t