--- trunk/t/5_Node.t 2006/05/09 12:42:39 135 +++ trunk/t/5_Node.t 2006/05/09 14:05:57 137 @@ -3,17 +3,17 @@ use strict; use blib; -use Test::More tests => 120; +use Test::More tests => 132; use Test::Exception; use Data::Dumper; BEGIN { use_ok('Search::Estraier') }; -my $debug = 1; +my $debug = 0; # name of node for test -my $test1_node = 'test1'; -my $test2_node = 'test2'; +my $test1_node = '_test1_' . $$; +my $test2_node = '_test2_' . $$; ok(my $node = new Search::Estraier::Node( debug => $debug ), 'new'); isa_ok($node, 'Search::Estraier::Node'); @@ -32,29 +32,89 @@ # test master functionality -diag "not testing shutdown\n"; +#diag "not testing shutdown\n"; -ok(my $foo = $node->master( action => 'sync' ), 'sync'); +my $msg; -diag "not testing backup\n"; +ok($msg = $node->master( action => 'sync' ), "sync: $msg"); + +#diag "not testing backup\n"; ok(my @users = $node->master( action => 'userlist' ), 'userlist'); -diag "users: ", Dumper( \@users ); +#diag "users: ", Dumper( \@users ); +diag "found ", $#users + 1, " users"; + +my $user = { + name => '_test_' . $$, + flags => 'b', + fname => 'Search::Estraier', + misc => 'test user', +}; + +ok($msg = $node->master( + action => 'useradd', + %{ $user }, + passwd => 'test1234', +), "useradd: $msg"); + +ok(my @users2 = $node->master( action => 'userlist' ), 'userlist'); +cmp_ok($#users2, '==', $#users + 1, 'added user'); + +while (my $row = shift @users2) { + next unless ($row->{name} eq $user); + map { + cmp_ok($user->{$_}, 'eq', $row->{$_}, "$_"); + } keys %{ $user }; +} + +ok($msg = $node->master( + action => 'userdel', + name => $user->{name}, +), "userdel: $msg"); + +ok(@users2 = $node->master( action => 'userlist' ), 'userlist'); +cmp_ok($#users2, '==', $#users, 'removed user'); + +ok(my @nodes = $node->master( action => 'nodelist' ), 'nodelist' ); +#diag "nodelist: ", Dumper( \@nodes ); +diag "found ", $#nodes + 1, " nodes"; -SKIP: { +if ($#nodes > 42) { + diag <<'_END_OF_WARNING_'; -skip "no $test1_node node in Hyper Estraier", 110, unless($node->name); +This tests create three nodes in your Hyper Estraier. -my @res = ( -1, 200 ); +Since you have more than 43 modes, and Hyper Estraier seems to be limited to +maximum of 46 nodes on each estmaster process, expect tests to fail. -my $nodelist; -foreach my $url (qw{?action=nodelist http://localhost:1978/master?action=nodelist}) { - cmp_ok( - $node->shuttle_url( $url, 'text/plain', undef, \$nodelist) - ,'==', shift @res, 'nodelist'); +_END_OF_WARNING_ } +my $temp_node = "_test_temp_$$"; + +foreach my $node_name ( $test1_node , $test2_node, $temp_node ) { + ok($msg = $node->master( + action => 'nodeadd', + name => $node_name, + label => "$node_name label", + ), "nodeadd $node_name: $msg"); +} + +ok($msg = $node->master( + action => 'nodeclr', + name => $temp_node, +), "nodeclr $temp_node: $msg"); + +ok($msg = $node->master( + action => 'nodedel', + name => $temp_node, +), "nodedel $temp_node: $msg"); + +#diag "not testing logrtt\n"; + +# test document creation + my $draft = <<'_END_OF_DRAFT_'; @uri=data001 @title=Material Girl @@ -163,34 +223,33 @@ ok(! $node->uri_to_id('foobar'), 'uri_to_id without croak'); -# test users +# test users ok(! $node->admins, 'no admins'); ok(! $node->guests, 'no guests'); -# test search without results +# test search without results ok($cond = new Search::Estraier::Condition, 'new cond'); ok($cond->set_phrase('this_is_phrase_which_does_not_exits'), 'cond set_phrase'); ok($nres = $node->search( $cond, 0 ), 'search'); -SKIP: { - skip "no $test2_node in Hyper Estraier, skipping set_link", 5 unless (my $test2_label = $node2->label); - - my $link_url = "http://localhost:1978/node/$test2_node"; - - ok($node->set_link( $link_url, $test2_label, 42), "set_link $test2_node ($test2_label) 42"); - - ok(my $links = $node->links, 'links'); - - cmp_ok($#{$links}, '==', 0, 'one link'); - - like($links->[0], qr/^$link_url/, 'link correct'); - - ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 0), "set_link $test2_node ($test2_label) delete"); -} # SKIP 2 - -} # SKIP 1 +# now, test links +my $test2_label = "$test2_node label"; +my $link_url = "http://localhost:1978/node/$test2_node"; +ok($node->set_link( $link_url, $test2_label, 42), "set_link $test2_node ($test2_label) 42"); +ok(my $links = $node->links, 'links'); +cmp_ok($#{$links}, '==', 0, 'one link'); +like($links->[0], qr/^$link_url/, 'link correct'); +ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 0), "set_link $test2_node ($test2_label) delete"); + +# cleanup test nodes +foreach my $node_name ( $test1_node , $test2_node ) { + ok($msg = $node->master( + action => 'nodedel', + name => $node_name, + ), "nodedel $node_name: $msg"); +} diag "over";