/[Search-Estraier]/trunk/t/5_Node.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/t/5_Node.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 136 by dpavlin, Tue May 9 12:42:39 2006 UTC revision 137 by dpavlin, Tue May 9 14:05:57 2006 UTC
# Line 3  Line 3 
3  use strict;  use strict;
4  use blib;  use blib;
5    
6  use Test::More tests => 120;  use Test::More tests => 132;
7  use Test::Exception;  use Test::Exception;
8  use Data::Dumper;  use Data::Dumper;
9    
10  BEGIN { use_ok('Search::Estraier') };  BEGIN { use_ok('Search::Estraier') };
11    
12  my $debug = 1;  my $debug = 0;
13    
14  # name of node for test  # name of node for test
15  my $test1_node = 'test1';  my $test1_node = '_test1_' . $$;
16  my $test2_node = 'test2';  my $test2_node = '_test2_' . $$;
17    
18  ok(my $node = new Search::Estraier::Node( debug => $debug ), 'new');  ok(my $node = new Search::Estraier::Node( debug => $debug ), 'new');
19  isa_ok($node, 'Search::Estraier::Node');  isa_ok($node, 'Search::Estraier::Node');
# Line 32  cmp_ok($node->status, '==', -1, 'status' Line 32  cmp_ok($node->status, '==', -1, 'status'
32    
33  # test master functionality  # test master functionality
34    
35  diag "not testing shutdown\n";  #diag "not testing shutdown\n";
36    
37  ok(my $foo = $node->master( action => 'sync' ), 'sync');  my $msg;
38    
39  diag "not testing backup\n";  ok($msg = $node->master( action => 'sync' ), "sync: $msg");
40    
41    #diag "not testing backup\n";
42    
43  ok(my @users = $node->master( action => 'userlist' ), 'userlist');  ok(my @users = $node->master( action => 'userlist' ), 'userlist');
44    
45  diag "users: ", Dumper( \@users );  #diag "users: ", Dumper( \@users );
46    diag "found ", $#users + 1, " users";
47    
48    my $user = {
49            name => '_test_' . $$,
50            flags => 'b',
51            fname => 'Search::Estraier',
52            misc => 'test user',
53    };
54    
55    ok($msg = $node->master(
56            action => 'useradd',
57            %{ $user },
58            passwd => 'test1234',
59    ), "useradd: $msg");
60    
61    ok(my @users2 = $node->master( action => 'userlist' ), 'userlist');
62    cmp_ok($#users2, '==', $#users + 1, 'added user');
63    
64    while (my $row = shift @users2) {
65            next unless ($row->{name} eq $user);
66            map {
67                    cmp_ok($user->{$_}, 'eq', $row->{$_}, "$_");
68            } keys %{ $user };
69    }
70    
71    ok($msg = $node->master(
72            action => 'userdel',
73            name => $user->{name},
74    ), "userdel: $msg");
75    
76    ok(@users2 = $node->master( action => 'userlist' ), 'userlist');
77    cmp_ok($#users2, '==', $#users, 'removed user');
78    
79    ok(my @nodes = $node->master( action => 'nodelist' ), 'nodelist' );
80    #diag "nodelist: ", Dumper( \@nodes );
81    diag "found ", $#nodes + 1, " nodes";
82    
83  SKIP: {  if ($#nodes > 42) {
84            diag <<'_END_OF_WARNING_';
85    
86  skip "no $test1_node node in Hyper Estraier", 110, unless($node->name);  This tests create three nodes in your Hyper Estraier.
87    
88  my @res = ( -1, 200 );  Since you have more than 43 modes, and Hyper Estraier seems to be limited to
89    maximum of 46 nodes on each estmaster process, expect tests to fail.
90    
91  my $nodelist;  _END_OF_WARNING_
 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');  
92  }  }
93    
94    my $temp_node = "_test_temp_$$";
95    
96    foreach my $node_name ( $test1_node , $test2_node, $temp_node ) {
97            ok($msg = $node->master(
98                    action => 'nodeadd',
99                    name => $node_name,
100                    label => "$node_name label",
101            ), "nodeadd $node_name: $msg");
102    }
103    
104    ok($msg = $node->master(
105            action => 'nodeclr',
106            name => $temp_node,
107    ), "nodeclr $temp_node: $msg");
108    
109    ok($msg = $node->master(
110            action => 'nodedel',
111            name => $temp_node,
112    ), "nodedel $temp_node: $msg");
113    
114    #diag "not testing logrtt\n";
115    
116    # test document creation
117    
118  my $draft = <<'_END_OF_DRAFT_';  my $draft = <<'_END_OF_DRAFT_';
119  @uri=data001  @uri=data001
120  @title=Material Girl  @title=Material Girl
# Line 163  ok($node = new Search::Estraier::Node( u Line 223  ok($node = new Search::Estraier::Node( u
223    
224  ok(! $node->uri_to_id('foobar'), 'uri_to_id without croak');  ok(! $node->uri_to_id('foobar'), 'uri_to_id without croak');
225    
 # test users  
226    
227    # test users
228  ok(! $node->admins, 'no admins');  ok(! $node->admins, 'no admins');
229  ok(! $node->guests, 'no guests');  ok(! $node->guests, 'no guests');
230    
 # test search without results  
231    
232    # test search without results
233  ok($cond = new Search::Estraier::Condition, 'new cond');  ok($cond = new Search::Estraier::Condition, 'new cond');
234  ok($cond->set_phrase('this_is_phrase_which_does_not_exits'), 'cond set_phrase');  ok($cond->set_phrase('this_is_phrase_which_does_not_exits'), 'cond set_phrase');
235    
236  ok($nres = $node->search( $cond, 0 ), 'search');  ok($nres = $node->search( $cond, 0 ), 'search');
237    
238  SKIP: {  # now, test links
239          skip "no $test2_node in Hyper Estraier, skipping set_link", 5 unless (my $test2_label = $node2->label);  my $test2_label = "$test2_node label";
240    my $link_url = "http://localhost:1978/node/$test2_node";
241          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");
242    ok(my $links = $node->links, 'links');
243          ok($node->set_link( $link_url, $test2_label, 42), "set_link $test2_node ($test2_label) 42");  cmp_ok($#{$links}, '==', 0, 'one link');
244    like($links->[0], qr/^$link_url/, 'link correct');
245          ok(my $links = $node->links, 'links');  ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 0), "set_link $test2_node ($test2_label) delete");
246    
247          cmp_ok($#{$links}, '==', 0, 'one link');  # cleanup test nodes
248    foreach my $node_name ( $test1_node , $test2_node ) {
249          like($links->[0], qr/^$link_url/, 'link correct');          ok($msg = $node->master(
250                    action => 'nodedel',
251          ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 0), "set_link $test2_node ($test2_label) delete");                  name => $node_name,
252  }       # SKIP 2          ), "nodedel $node_name: $msg");
253    }
 }       # SKIP 1  
254    
255  diag "over";  diag "over";

Legend:
Removed from v.136  
changed lines
  Added in v.137

  ViewVC Help
Powered by ViewVC 1.1.26