]> pd.if.org Git - newsd/commitdiff
Added stat response tests.
authorNathan Wagner <nw@hydaspes.if.org>
Fri, 2 Dec 2011 09:39:33 +0000 (04:39 -0500)
committerNathan Wagner <nw@hydaspes.if.org>
Fri, 2 Dec 2011 09:39:33 +0000 (04:39 -0500)
t/02_responses.t [new file with mode: 0644]

diff --git a/t/02_responses.t b/t/02_responses.t
new file mode 100644 (file)
index 0000000..0ff39d2
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+
+use Test::More tests => 8; 
+
+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('STAT','stat with no newsgroup',412);
+$c->try('GROUP de.test','group selection',211);
+$c->try('STAT','stat with newsgroup',223,420);
+
+goto quit;
+
+quit:
+
+$c->try('QUIT','quit',205);