3 |
use strict; |
use strict; |
4 |
use blib; |
use blib; |
5 |
|
|
6 |
use Test::More tests => 5; |
use Test::More tests => 52; |
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 |
ok(my $node = new Search::Estraier::Node, 'new'); |
my $debug = 0; |
13 |
|
|
14 |
|
# name of node for test |
15 |
|
my $test_node = 'Search-Estraier'; |
16 |
|
|
17 |
|
ok(my $node = new Search::Estraier::Node($debug), 'new'); |
18 |
isa_ok($node, 'Search::Estraier::Node'); |
isa_ok($node, 'Search::Estraier::Node'); |
19 |
|
|
20 |
ok($node->set_url('http://localhost:1978/'), 'set_url'); |
ok($node->set_url('http://localhost:1978/node/searchestraier'), 'set_url'); |
21 |
|
|
22 |
|
ok($node->set_proxy('', 8080), 'set_proxy'); |
23 |
|
throws_ok {$node->set_proxy('proxy.example.com', 'foo') } qr/port/, 'set_proxy port NaN'; |
24 |
|
|
25 |
|
ok($node->set_timeout(42), 'set_timeout'); |
26 |
|
throws_ok {$node->set_timeout('foo') } qr/timeout/, 'set_timeout NaN'; |
27 |
|
|
28 |
|
ok($node->set_auth('admin','admin'), 'set_auth'); |
29 |
|
|
30 |
|
cmp_ok($node->status, '==', -1, 'status'); |
31 |
|
|
32 |
|
my @res = ( -1, 200 ); |
33 |
|
|
34 |
|
my $nodelist; |
35 |
|
foreach my $url (qw{?action=nodelist http://localhost:1978/master?action=nodelist}) { |
36 |
|
cmp_ok( |
37 |
|
$node->shuttle_url( $url, 'text/plain', undef, \$nodelist) |
38 |
|
,'==', shift @res, 'nodelist'); |
39 |
|
} |
40 |
|
|
41 |
|
my $draft = <<'_END_OF_DRAFT_'; |
42 |
|
@uri=data001 |
43 |
|
@title=Material Girl |
44 |
|
|
45 |
|
Living in a material world |
46 |
|
And I am a material girl |
47 |
|
You know that we are living in a material world |
48 |
|
And I am a material girl |
49 |
|
_END_OF_DRAFT_ |
50 |
|
|
51 |
|
#diag "draft:\n$draft"; |
52 |
|
ok(my $doc = new Search::Estraier::Document($draft), 'new doc from draft'); |
53 |
|
|
54 |
|
ok( $node->put_doc($doc), "put_doc data001"); |
55 |
|
|
56 |
|
for ( 1 .. 10 ) { |
57 |
|
$doc->add_attr('@uri', 'test' . $_); |
58 |
|
ok( $node->put_doc($doc), "put_doc test$_"); |
59 |
|
#diag $doc->dump_draft; |
60 |
|
} |
61 |
|
|
62 |
|
ok(my $id = $node->uri_to_id( 'data001' ), 'uri_to_id'); |
63 |
|
|
64 |
|
ok( $node->out_doc( $id ), "out_doc $id"); |
65 |
|
|
66 |
|
for ( 1 .. 5 ) { |
67 |
|
ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_"); |
68 |
|
} |
69 |
|
|
70 |
|
$doc->add_attr('@uri', 'data001'); |
71 |
|
$doc->add_attr('foo', 'bar'); |
72 |
|
ok( $node->edit_doc( $doc ), 'edit_doc'); |
73 |
|
|
74 |
ok($node->set_proxy('proxy.example.com', 8080), 'set_proxy'); |
for ( 6 .. 10 ) { |
75 |
|
my $uri = 'test' . $_; |
76 |
|
ok( my $id = $node->uri_to_id( $uri ), "uri_to_id $uri"); |
77 |
|
ok( $node->get_doc( $id ), "get_doc $id"); |
78 |
|
ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri"); |
79 |
|
ok( my $k = $node->etch_doc_by_uri( $uri ), "etch_doc_by_uri $uri"); |
80 |
|
} |