/[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

Annotation of /trunk/t/5_Node.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 137 - (hide annotations)
Tue May 9 14:05:57 2006 UTC (17 years, 11 months ago) by dpavlin
File MIME type: application/x-troff
File size: 7105 byte(s)
test whole new ->master API except for shutdown, backup and logrtt (those operations are
specific to Hyper Estraier installation and sysadmins might not appreciate tests which
mess system services)
1 dpavlin 28 #!/usr/bin/perl -w
2    
3     use strict;
4     use blib;
5    
6 dpavlin 137 use Test::More tests => 132;
7 dpavlin 28 use Test::Exception;
8     use Data::Dumper;
9    
10     BEGIN { use_ok('Search::Estraier') };
11    
12 dpavlin 137 my $debug = 0;
13 dpavlin 40
14 dpavlin 35 # name of node for test
15 dpavlin 137 my $test1_node = '_test1_' . $$;
16     my $test2_node = '_test2_' . $$;
17 dpavlin 35
18 dpavlin 57 ok(my $node = new Search::Estraier::Node( debug => $debug ), 'new');
19 dpavlin 28 isa_ok($node, 'Search::Estraier::Node');
20    
21 dpavlin 78 ok($node->set_url("http://localhost:1978/node/$test1_node"), "set_url $test1_node");
22 dpavlin 29
23 dpavlin 38 ok($node->set_proxy('', 8080), 'set_proxy');
24 dpavlin 30 throws_ok {$node->set_proxy('proxy.example.com', 'foo') } qr/port/, 'set_proxy port NaN';
25    
26     ok($node->set_timeout(42), 'set_timeout');
27     throws_ok {$node->set_timeout('foo') } qr/timeout/, 'set_timeout NaN';
28 dpavlin 31
29 dpavlin 39 ok($node->set_auth('admin','admin'), 'set_auth');
30 dpavlin 32
31     cmp_ok($node->status, '==', -1, 'status');
32 dpavlin 35
33 dpavlin 134 # test master functionality
34    
35 dpavlin 137 #diag "not testing shutdown\n";
36 dpavlin 134
37 dpavlin 137 my $msg;
38 dpavlin 134
39 dpavlin 137 ok($msg = $node->master( action => 'sync' ), "sync: $msg");
40 dpavlin 135
41 dpavlin 137 #diag "not testing backup\n";
42    
43 dpavlin 135 ok(my @users = $node->master( action => 'userlist' ), 'userlist');
44    
45 dpavlin 137 #diag "users: ", Dumper( \@users );
46     diag "found ", $#users + 1, " users";
47 dpavlin 135
48 dpavlin 137 my $user = {
49     name => '_test_' . $$,
50     flags => 'b',
51     fname => 'Search::Estraier',
52     misc => 'test user',
53     };
54 dpavlin 73
55 dpavlin 137 ok($msg = $node->master(
56     action => 'useradd',
57     %{ $user },
58     passwd => 'test1234',
59     ), "useradd: $msg");
60 dpavlin 73
61 dpavlin 137 ok(my @users2 = $node->master( action => 'userlist' ), 'userlist');
62     cmp_ok($#users2, '==', $#users + 1, 'added user');
63 dpavlin 38
64 dpavlin 137 while (my $row = shift @users2) {
65     next unless ($row->{name} eq $user);
66     map {
67     cmp_ok($user->{$_}, 'eq', $row->{$_}, "$_");
68     } keys %{ $user };
69 dpavlin 37 }
70 dpavlin 35
71 dpavlin 137 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     if ($#nodes > 42) {
84     diag <<'_END_OF_WARNING_';
85    
86     This tests create three nodes in your Hyper Estraier.
87    
88     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     _END_OF_WARNING_
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 dpavlin 35 my $draft = <<'_END_OF_DRAFT_';
119     @uri=data001
120     @title=Material Girl
121    
122     Living in a material world
123     And I am a material girl
124     You know that we are living in a material world
125     And I am a material girl
126     _END_OF_DRAFT_
127    
128 dpavlin 40 #diag "draft:\n$draft";
129     ok(my $doc = new Search::Estraier::Document($draft), 'new doc from draft');
130    
131 dpavlin 46 ok( $node->put_doc($doc), "put_doc data001");
132    
133 dpavlin 41 for ( 1 .. 10 ) {
134     $doc->add_attr('@uri', 'test' . $_);
135     ok( $node->put_doc($doc), "put_doc test$_");
136     #diag $doc->dump_draft;
137     }
138    
139 dpavlin 50 my $id;
140     ok($id = $node->uri_to_id( 'data001' ), "uri_to_id = $id");
141 dpavlin 41
142 dpavlin 100 my $data_max = 5;
143    
144     for ( 1 .. $data_max ) {
145 dpavlin 43 ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_");
146 dpavlin 41 }
147 dpavlin 42
148 dpavlin 50 ok($doc = $node->get_doc( $id ), 'get_doc for edit');
149 dpavlin 42 $doc->add_attr('foo', 'bar');
150 dpavlin 50 #diag Dumper($doc);
151 dpavlin 42 ok( $node->edit_doc( $doc ), 'edit_doc');
152 dpavlin 43
153 dpavlin 50 ok( $node->out_doc( $id ), "out_doc $id");
154    
155     ok( ! $node->edit_doc( $doc ), "edit removed");
156    
157 dpavlin 53 my $max = 3;
158    
159 dpavlin 51 ok(my $cond = new Search::Estraier::Condition, 'new cond');
160     ok($cond->set_phrase('girl'), 'cond set_phrase');
161 dpavlin 53 ok($cond->set_max($max), "cond set_max $max");
162 dpavlin 51 ok($cond->set_order('@uri ASCD'), 'cond set_order');
163     ok($cond->add_attr('@title STRINC Material'), 'cond add_attr');
164    
165 dpavlin 53 cmp_ok($node->cond_to_query( $cond ), 'eq' , 'phrase=girl&attr1=%40title%20STRINC%20Material&order=%40uri%20ASCD&max='.$max.'&wwidth=480&hwidth=96&awidth=96', 'cond_to_query');
166 dpavlin 51
167 dpavlin 91 ok( my $nres = $node->search( $cond, 0 ), 'search');
168 dpavlin 51
169 dpavlin 91 isa_ok( $nres, 'Search::Estraier::NodeResult' );
170 dpavlin 51
171 dpavlin 91 cmp_ok($nres->doc_num, '==', $max, "doc_num = $max");
172 dpavlin 53
173 dpavlin 100 cmp_ok($nres->hits, '==', $data_max, "hits");
174    
175 dpavlin 115 for my $i ( 0 .. ($nres->hits - 1) ) {
176     my $uri = 'test' . ($i + $data_max + 1);
177    
178     if ($i < $nres->doc_num) {
179     ok( my $rdoc = $nres->get_doc( $i ), "get_doc $i");
180    
181     cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri");
182     ok( my $k = $rdoc->keywords( $id ), "rdoc keywords");
183     }
184    
185 dpavlin 103 ok( my $id = $node->uri_to_id( $uri ), "uri_to_id($uri) = $id");
186 dpavlin 46 ok( $node->get_doc( $id ), "get_doc $id");
187 dpavlin 44 ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri");
188 dpavlin 49 cmp_ok( $node->get_doc_attr( $id, '@uri' ), 'eq', $uri, "get_doc_attr $id");
189     cmp_ok( $node->get_doc_attr_by_uri( $uri, '@uri' ), 'eq', $uri, "get_doc_attr $id");
190 dpavlin 115 ok( my $k1 = $node->etch_doc( $id ), "etch_doc_by_uri $uri");
191 dpavlin 49 ok( my $k2 = $node->etch_doc_by_uri( $uri ), "etch_doc_by_uri $uri");
192     #diag Dumper($k, $k2);
193 dpavlin 115 ok( eq_hash( $k1, $k2 ), "keywords");
194 dpavlin 43 }
195 dpavlin 48
196 dpavlin 91 ok(my $hints = $nres->hints, 'hints');
197     diag Dumper($hints);
198    
199 dpavlin 72 ok($node->_set_info, "refresh _set_info");
200    
201 dpavlin 48 my $v;
202     ok($v = $node->name, "name: $v");
203     ok($v = $node->label, "label: $v");
204     ok($v = $node->doc_num, "doc_num: $v");
205 dpavlin 110 ok(defined($v = $node->word_num), "word_num: $v");
206 dpavlin 48 ok($v = $node->size, "size: $v");
207    
208 dpavlin 55 ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width");
209    
210 dpavlin 56 # user doesn't exist
211     ok(! $node->set_user('foobar', 1), 'set_user');
212    
213 dpavlin 94 ok(my $node2 = new Search::Estraier::Node( "http://localhost:1978/node/$test2_node" ), "new $test2_node");
214     ok($node2->set_auth('admin','admin'), "set_auth $test2_node");
215 dpavlin 57
216 dpavlin 78 # croak_on_error
217    
218 dpavlin 94 ok($node = new Search::Estraier::Node( url => "http://localhost:1978/non-existant", croak_on_error => 1 ), "new non-existant");
219     throws_ok { $node->name } qr/404/, 'croak on error';
220 dpavlin 78
221 dpavlin 103 # croak_on_error
222 dpavlin 106 ok($node = new Search::Estraier::Node( url => "http://localhost:1978/node/$test1_node", croak_on_error => 1 ), "new $test1_node");
223 dpavlin 94
224 dpavlin 103 ok(! $node->uri_to_id('foobar'), 'uri_to_id without croak');
225    
226 dpavlin 137
227 dpavlin 107 # test users
228     ok(! $node->admins, 'no admins');
229     ok(! $node->guests, 'no guests');
230    
231 dpavlin 137
232 dpavlin 129 # test search without results
233     ok($cond = new Search::Estraier::Condition, 'new cond');
234     ok($cond->set_phrase('this_is_phrase_which_does_not_exits'), 'cond set_phrase');
235    
236     ok($nres = $node->search( $cond, 0 ), 'search');
237    
238 dpavlin 137 # now, test links
239     my $test2_label = "$test2_node label";
240     my $link_url = "http://localhost:1978/node/$test2_node";
241     ok($node->set_link( $link_url, $test2_label, 42), "set_link $test2_node ($test2_label) 42");
242     ok(my $links = $node->links, 'links');
243     cmp_ok($#{$links}, '==', 0, 'one link');
244     like($links->[0], qr/^$link_url/, 'link correct');
245     ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 0), "set_link $test2_node ($test2_label) delete");
246 dpavlin 72
247 dpavlin 137 # cleanup test nodes
248     foreach my $node_name ( $test1_node , $test2_node ) {
249     ok($msg = $node->master(
250     action => 'nodedel',
251     name => $node_name,
252     ), "nodedel $node_name: $msg");
253     }
254 dpavlin 107
255 dpavlin 55 diag "over";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26