"Fossies" - the Fresh Open Source Software Archive 
Member "apache-zookeeper-3.8.1/zookeeper-contrib/zookeeper-contrib-zkperl/t/10_invalid.t" (25 Jan 2023, 18078 Bytes) of package /linux/misc/apache-zookeeper-3.8.1.tar.gz:
As a special service "Fossies" has tried to format the requested text file into HTML format (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the last
Fossies "Diffs" side-by-side code changes report for "10_invalid.t":
3.6.2_vs_3.7.0.
1 # Net::ZooKeeper - Perl extension for Apache ZooKeeper
2 #
3 # Licensed to the Apache Software Foundation (ASF) under one
4 # or more contributor license agreements. See the NOTICE file
5 # distributed with this work for additional information
6 # regarding copyright ownership. The ASF licenses this file
7 # to you under the Apache License, Version 2.0 (the
8 # "License"); you may not use this file except in compliance
9 # with the License. You may obtain a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18
19 use File::Spec;
20 use Test::More tests => 107;
21
22 BEGIN { use_ok('Net::ZooKeeper', qw(:all)) };
23
24
25 my $test_dir;
26 (undef, $test_dir, undef) = File::Spec->splitpath($0);
27 require File::Spec->catfile($test_dir, 'util.pl');
28
29 my($hosts, $root_path, $node_path) = zk_test_setup(1);
30
31
32 ## new()
33
34 eval {
35 Net::ZooKeeper->new();
36 };
37 like($@, qr/Usage: Net::ZooKeeper::new\(package, hosts, \.\.\.\)/,
38 'new(): no hostname specified');
39
40 eval {
41 Net::ZooKeeper->new($hosts, 'bar');
42 };
43 like($@, qr/invalid number of arguments/,
44 'new(): invalid number of arguments');
45
46 eval {
47 Net::ZooKeeper->new($hosts, 'session_timeout' => -3);
48 };
49 like($@, qr/invalid session timeout/,
50 'new(): invalid session timeout');
51
52 eval {
53 Net::ZooKeeper->new($hosts, 'session_timeout' => 0x4000_0000);
54 };
55 like($@, qr/invalid session timeout/,
56 'new(): invalid session timeout');
57
58 eval {
59 Net::ZooKeeper->new($hosts, 'session_id' => 'abcdef');
60 };
61 like($@, qr/invalid session ID/,
62 'new(): invalid session ID');
63
64 my $zkh = Net::ZooKeeper->new($hosts);
65 isa_ok($zkh, 'Net::ZooKeeper',
66 'new(): created handle');
67
68
69 ## DESTROY()
70
71 eval {
72 $zkh->DESTROY('foo');
73 };
74 like($@, qr/Usage: Net::ZooKeeper::DESTROY\(zkh\)/,
75 'DESTROY(): too many arguments');
76
77 my $bad_zkh = {};
78 $bad_zkh = bless($bad_zkh, 'Net::ZooKeeper');
79
80 my $ret = $bad_zkh->DESTROY();
81 ok(!$ret,
82 'DESTROY(): no action on invalid handle');
83
84
85 ## add_auth()
86
87 eval {
88 $zkh->add_auth();
89 };
90 like($@, qr/Usage: Net::ZooKeeper::add_auth\(zkh, scheme, cert\)/,
91 'add_auth(): no scheme specified');
92
93 eval {
94 $zkh->add_auth('foo');
95 };
96 like($@, qr/Usage: Net::ZooKeeper::add_auth\(zkh, scheme, cert\)/,
97 'add_auth(): no certificate specified');
98
99 eval {
100 $zkh->add_auth('foo', 'foo', 'bar');
101 };
102 like($@, qr/Usage: Net::ZooKeeper::add_auth\(zkh, scheme, cert\)/,
103 'add_auth(): too many arguments');
104
105 eval {
106 $bad_zkh->add_auth('foo', 'foo');
107 };
108 like($@, qr/invalid handle/,
109 'add_auth(): invalid handle');
110
111 eval {
112 Net::ZooKeeper::add_auth(1, 'foo', 'foo');
113 };
114 like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/,
115 'add_auth(): invalid hash reference');
116
117
118 ## create()
119
120 eval {
121 $zkh->create();
122 };
123 like($@, qr/Usage: Net::ZooKeeper::create\(zkh, path, buf, \.\.\.\)/,
124 'create(): no path specified');
125
126 eval {
127 $zkh->create($node_path);
128 };
129 like($@, qr/Usage: Net::ZooKeeper::create\(zkh, path, buf, \.\.\.\)/,
130 'create(): no data buffer specified');
131
132 eval {
133 $zkh->create($node_path, 'foo', 'bar');
134 };
135 like($@, qr/invalid number of arguments/,
136 'create(): invalid number of arguments');
137
138 eval {
139 $zkh->create($node_path, 'foo', 'path_read_len' => -3);
140 };
141 like($@, qr/invalid path read length/,
142 'create(): invalid path read length');
143
144 eval {
145 $zkh->create($node_path, 'foo', 'path_read_len' => 1);
146 };
147 like($@, qr/invalid path read length/,
148 'create(): invalid path read length');
149
150 eval {
151 $zkh->create($node_path, 'foo', 'flags' => 15);
152 };
153 like($@, qr/invalid create flags/,
154 'create(): invalid create flags');
155
156 eval {
157 $zkh->create($node_path, 'foo', 'flags' => ZOO_EPHEMERAL, 'acl', 'foo');
158 };
159 like($@, qr/invalid ACL array reference/,
160 'create(): invalid ACL array reference');
161
162 eval {
163 $zkh->create($node_path, 'foo', 'acl', {});
164 };
165 like($@, qr/invalid ACL array reference/,
166 'create(): invalid ACL array reference to hash');
167
168 eval {
169 my @acl = ('foo', 'bar');
170 $zkh->create($node_path, 'foo', 'acl', \@acl);
171 };
172 like($@, qr/invalid ACL entry hash reference/,
173 'create(): invalid ACL entry hash reference');
174
175 eval {
176 my @acl = ({ 'foo' => 'bar' });
177 $zkh->create($node_path, 'foo', 'acl', \@acl);
178 };
179 like($@, qr/no ACL entry perms element/,
180 'create(): no ACL entry perms element');
181
182 eval {
183 my @acl = (
184 {
185 'perms' => -1
186 }
187 );
188 $zkh->create($node_path, 'foo', 'acl', \@acl);
189 };
190 like($@, qr/invalid ACL entry perms/,
191 'create(): invalid ACL entry perms');
192
193 eval {
194 my @acl = (
195 {
196 'perms' => ZOO_PERM_ALL
197 }
198 );
199 $zkh->create($node_path, 'foo', 'acl', \@acl);
200 };
201 like($@, qr/no ACL entry scheme element/,
202 'create(): no ACL entry scheme element');
203
204 eval {
205 my @acl = (
206 {
207 'perms' => ZOO_PERM_ALL,
208 'scheme' => 'foo'
209 }
210 );
211 $zkh->create($node_path, 'foo', 'acl', \@acl);
212 };
213 like($@, qr/no ACL entry id element/,
214 'create(): no ACL entry id element');
215
216 eval {
217 my @acl = (
218 {
219 'perms' => ZOO_PERM_ALL,
220 'scheme' => 'foo',
221 'id' => 'bar'
222 },
223 'bar'
224 );
225 $zkh->create($node_path, 'foo', 'acl', \@acl);
226 };
227 like($@, qr/invalid ACL entry hash reference/,
228 'create(): invalid second ACL entry hash reference');
229
230 eval {
231 $bad_zkh->create($node_path, 'foo');
232 };
233 like($@, qr/invalid handle/,
234 'create(): invalid handle');
235
236 eval {
237 Net::ZooKeeper::create(1, $node_path, 'foo');
238 };
239 like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/,
240 'create(): invalid hash reference');
241
242
243 ## delete()
244
245 eval {
246 $zkh->delete();
247 };
248 like($@, qr/Usage: Net::ZooKeeper::delete\(zkh, path, \.\.\.\)/,
249 'delete(): no path specified');
250
251 eval {
252 $zkh->delete($node_path, 'bar');
253 };
254 like($@, qr/invalid number of arguments/,
255 'delete(): invalid number of arguments');
256
257 eval {
258 $zkh->delete($node_path, 'version' => -3);
259 };
260 like($@, qr/invalid version requirement/,
261 'delete(): invalid version requirement');
262
263 eval {
264 $bad_zkh->delete($node_path);
265 };
266 like($@, qr/invalid handle/,
267 'delete(): invalid handle');
268
269 eval {
270 Net::ZooKeeper::delete(1, $node_path);
271 };
272 like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/,
273 'delete(): invalid hash reference');
274
275
276 ## exists()
277
278 eval {
279 $zkh->exists();
280 };
281 like($@, qr/Usage: Net::ZooKeeper::exists\(zkh, path, \.\.\.\)/,
282 'exists(): no path specified');
283
284 eval {
285 $zkh->exists($node_path, 'bar');
286 };
287 like($@, qr/invalid number of arguments/,
288 'exists(): invalid number of arguments');
289
290 eval {
291 $zkh->exists($node_path, 'watch', 'bar');
292 };
293 like($@, qr/watch is not a hash reference of type Net::ZooKeeper::Watch/,
294 'exists(): invalid watch hash reference');
295
296 eval {
297 $zkh->exists($node_path, 'watch', []);
298 };
299 like($@, qr/watch is not a hash reference of type Net::ZooKeeper::Watch/,
300 'exists(): invalid watch hash reference to array');
301
302 eval {
303 $zkh->exists($node_path, 'stat', 'bar');
304 };
305 like($@, qr/stat is not a hash reference of type Net::ZooKeeper::Stat/,
306 'exists(): invalid stat hash reference');
307
308 eval {
309 $zkh->exists($node_path, 'stat', []);
310 };
311 like($@, qr/stat is not a hash reference of type Net::ZooKeeper::Stat/,
312 'exists(): invalid stat hash reference');
313
314 eval {
315 $bad_zkh->exists($node_path);
316 };
317 like($@, qr/invalid handle/,
318 'exists(): invalid handle');
319
320 eval {
321 Net::ZooKeeper::exists(1, $node_path);
322 };
323 like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/,
324 'exists(): invalid hash reference');
325
326
327 ## get_children()
328
329 eval {
330 $zkh->get_children();
331 };
332 like($@, qr/Usage: Net::ZooKeeper::get_children\(zkh, path, \.\.\.\)/,
333 'get_children(): no path specified');
334
335 eval {
336 $zkh->get_children($node_path, 'bar');
337 };
338 like($@, qr/invalid number of arguments/,
339 'get_children(): invalid number of arguments');
340
341 eval {
342 $zkh->get_children($node_path, 'watch', 'bar');
343 };
344 like($@, qr/watch is not a hash reference of type Net::ZooKeeper::Watch/,
345 'get_children(): invalid watch hash reference');
346
347 eval {
348 $zkh->get_children($node_path, 'watch', []);
349 };
350 like($@, qr/watch is not a hash reference of type Net::ZooKeeper::Watch/,
351 'get_children(): invalid watch ash reference to array');
352
353 eval {
354 $bad_zkh->get_children($node_path);
355 };
356 like($@, qr/invalid handle/,
357 'get_children(): invalid handle');
358
359 eval {
360 Net::ZooKeeper::get_children(1, $node_path);
361 };
362 like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/,
363 'get_children(): invalid hash reference');
364
365
366 ## get()
367
368 eval {
369 $zkh->get();
370 };
371 like($@, qr/Usage: Net::ZooKeeper::get\(zkh, path, \.\.\.\)/,
372 'get(): no path specified');
373
374 eval {
375 $zkh->get($node_path, 'bar');
376 };
377 like($@, qr/invalid number of arguments/,
378 'get(): invalid number of arguments');
379
380 eval {
381 $zkh->get($node_path, 'data_read_len' => -3);
382 };
383 like($@, qr/invalid data read length/,
384 'get(): invalid data read length');
385
386 eval {
387 $zkh->get($node_path, 'data_read_len' => 10, 'watch', 'bar');
388 };
389 like($@, qr/watch is not a hash reference of type Net::ZooKeeper::Watch/,
390 'get(): invalid watch hash reference');
391
392 eval {
393 $zkh->get($node_path, 'watch', []);
394 };
395 like($@, qr/watch is not a hash reference of type Net::ZooKeeper::Watch/,
396 'get(): invalid watch hash reference to array');
397
398 eval {
399 $zkh->get($node_path, 'stat', 'bar');
400 };
401 like($@, qr/stat is not a hash reference of type Net::ZooKeeper::Stat/,
402 'get(): invalid stat hash reference');
403
404 eval {
405 $zkh->get($node_path, 'stat', []);
406 };
407 like($@, qr/stat is not a hash reference of type Net::ZooKeeper::Stat/,
408 'get(): invalid stat hash reference');
409
410 eval {
411 $bad_zkh->get($node_path);
412 };
413 like($@, qr/invalid handle/,
414 'get(): invalid handle');
415
416 eval {
417 Net::ZooKeeper::get(1, $node_path);
418 };
419 like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/,
420 'get(): invalid hash reference');
421
422
423 ## set()
424
425 eval {
426 $zkh->set();
427 };
428 like($@, qr/Usage: Net::ZooKeeper::set\(zkh, path, buf, \.\.\.\)/,
429 'set(): no path specified');
430
431 eval {
432 $zkh->set($node_path);
433 };
434 like($@, qr/Usage: Net::ZooKeeper::set\(zkh, path, buf, \.\.\.\)/,
435 'set(): no data buffer specified');
436
437 eval {
438 $zkh->set($node_path, 'foo', 'bar');
439 };
440 like($@, qr/invalid number of arguments/,
441 'set(): invalid number of arguments');
442
443 eval {
444 $zkh->set($node_path, 'foo', 'version' => -3);
445 };
446 like($@, qr/invalid version requirement/,
447 'set(): invalid version requirement');
448
449 eval {
450 $zkh->set($node_path, 'foo', 'version', 0, 'stat', 'bar');
451 };
452 like($@, qr/stat is not a hash reference of type Net::ZooKeeper::Stat/,
453 'set(): invalid stat hash reference');
454
455 eval {
456 $zkh->set($node_path, 'foo', 'stat', []);
457 };
458 like($@, qr/stat is not a hash reference of type Net::ZooKeeper::Stat/,
459 'set(): invalid stat hash reference');
460
461 eval {
462 $bad_zkh->set($node_path, 'foo');
463 };
464 like($@, qr/invalid handle/,
465 'set(): invalid handle');
466
467 eval {
468 Net::ZooKeeper::set(1, $node_path, 'foo');
469 };
470 like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/,
471 'set(): invalid hash reference');
472
473
474 ## get_acl()
475
476 eval {
477 $zkh->get_acl();
478 };
479 like($@, qr/Usage: Net::ZooKeeper::get_acl\(zkh, path, \.\.\.\)/,
480 'get_acl(): no path specified');
481
482 eval {
483 $zkh->get_acl($node_path, 'bar');
484 };
485 like($@, qr/invalid number of arguments/,
486 'get_acl(): invalid number of arguments');
487
488 eval {
489 $zkh->get_acl($node_path, 'stat', 'bar');
490 };
491 like($@, qr/stat is not a hash reference of type Net::ZooKeeper::Stat/,
492 'get_acl(): invalid stat hash reference');
493
494 eval {
495 $zkh->get_acl($node_path, 'stat', []);
496 };
497 like($@, qr/stat is not a hash reference of type Net::ZooKeeper::Stat/,
498 'get_acl(): invalid stat hash reference');
499
500 eval {
501 $bad_zkh->get_acl($node_path);
502 };
503 like($@, qr/invalid handle/,
504 'get_acl(): invalid handle');
505
506 eval {
507 Net::ZooKeeper::get_acl(1, $node_path);
508 };
509 like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/,
510 'get_acl(): invalid hash reference');
511
512
513 ## set_acl()
514
515 eval {
516 $zkh->set_acl();
517 };
518 like($@, qr/Usage: Net::ZooKeeper::set_acl\(zkh, path, acl_arr, \.\.\.\)/,
519 'set_acl(): no path specified');
520
521 eval {
522 $zkh->set_acl($node_path);
523 };
524 like($@, qr/Usage: Net::ZooKeeper::set_acl\(zkh, path, acl_arr, \.\.\.\)/,
525 'set_acl(): no data buffer specified');
526
527 eval {
528 $zkh->set_acl($node_path, 'foo');
529 };
530 like($@, qr/acl_arr is not an array reference/i,
531 'set_acl(): invalid ACL array reference');
532
533 eval {
534 $zkh->set_acl($node_path, {});
535 };
536 like($@, qr/acl_arr is not an array reference/i,
537 'set_acl(): invalid ACL array reference to hash');
538
539 eval {
540 my @acl = ('foo', 'bar');
541 $zkh->set_acl($node_path, \@acl);
542 };
543 like($@, qr/invalid ACL entry hash reference/,
544 'set_acl(): invalid ACL entry hash reference');
545
546 eval {
547 my @acl = ({ 'foo' => 'bar' });
548 $zkh->set_acl($node_path, \@acl);
549 };
550 like($@, qr/no ACL entry perms element/,
551 'set_acl(): no ACL entry perms element');
552
553 eval {
554 my @acl = (
555 {
556 'perms' => -1
557 }
558 );
559 $zkh->set_acl($node_path, \@acl);
560 };
561 like($@, qr/invalid ACL entry perms/,
562 'set_acl(): invalid ACL entry perms');
563
564 eval {
565 my @acl = (
566 {
567 'perms' => ZOO_PERM_ALL
568 }
569 );
570 $zkh->set_acl($node_path, \@acl);
571 };
572 like($@, qr/no ACL entry scheme element/,
573 'set_acl(): no ACL entry scheme element');
574
575 eval {
576 my @acl = (
577 {
578 'perms' => ZOO_PERM_ALL,
579 'scheme' => 'foo'
580 }
581 );
582 $zkh->set_acl($node_path, \@acl);
583 };
584 like($@, qr/no ACL entry id element/,
585 'set_acl(): no ACL entry id element');
586
587 eval {
588 my @acl = (
589 {
590 'perms' => ZOO_PERM_ALL,
591 'scheme' => 'foo',
592 'id' => 'bar'
593 },
594 'bar'
595 );
596 $zkh->set_acl($node_path, \@acl);
597 };
598 like($@, qr/invalid ACL entry hash reference/,
599 'set_acl(): invalid second ACL entry hash reference');
600
601 eval {
602 $zkh->set_acl($node_path, [], 'bar');
603 };
604 like($@, qr/invalid number of arguments/,
605 'set_acl(): invalid number of arguments');
606
607 eval {
608 $zkh->set_acl($node_path, [], 'version' => -3);
609 };
610 like($@, qr/invalid version requirement/,
611 'set_acl(): invalid version requirement');
612
613 eval {
614 $bad_zkh->set_acl($node_path, []);
615 };
616 like($@, qr/invalid handle/,
617 'set_acl(): invalid handle');
618
619 eval {
620 Net::ZooKeeper::set_acl(1, $node_path, []);
621 };
622 like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/,
623 'set_acl(): invalid hash reference');
624
625
626 ## stat()
627
628 eval {
629 $zkh->stat('bar');
630 };
631 like($@, qr/Usage: Net::ZooKeeper::stat\(zkh\)/,
632 'stat(): too many arguments');
633
634 eval {
635 $bad_zkh->stat();
636 };
637 like($@, qr/invalid handle/,
638 'stat(): invalid handle');
639
640 eval {
641 Net::ZooKeeper::stat(1);
642 };
643 like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/,
644 'stat(): invalid hash reference');
645
646 my $stat = $zkh->stat();
647 isa_ok($stat, 'Net::ZooKeeper::Stat',
648 'stat(): created stat handle');
649
650
651 ## stat DESTROY()
652
653 eval {
654 $stat->DESTROY('foo');
655 };
656 like($@, qr/Usage: Net::ZooKeeper::Stat::DESTROY\(zksh\)/,
657 'stat DESTROY(): too many arguments');
658
659 my $bad_stat = {};
660 $bad_stat = bless($bad_stat, 'Net::ZooKeeper::Stat');
661
662 $ret = $bad_stat->DESTROY();
663 ok(!$ret,
664 'stat DESTROY(): no action on invalid handle');
665
666
667 ## watch()
668
669 eval {
670 $zkh->watch('bar');
671 };
672 like($@, qr/invalid number of arguments/,
673 'watch(): invalid number of arguments');
674
675 eval {
676 $bad_zkh->watch();
677 };
678 like($@, qr/invalid handle/,
679 'watch(): invalid handle');
680
681 eval {
682 Net::ZooKeeper::watch(1);
683 };
684 like($@, qr/zkh is not a hash reference of type Net::ZooKeeper/,
685 'watch(): invalid hash reference');
686
687 my $watch = $zkh->watch();
688 isa_ok($watch, 'Net::ZooKeeper::Watch',
689 'watch(): created watch handle');
690
691
692 ## watch DESTROY()
693
694 eval {
695 $watch->DESTROY('foo');
696 };
697 like($@, qr/Usage: Net::ZooKeeper::Watch::DESTROY\(zkwh\)/,
698 'watch DESTROY(): too many arguments');
699
700 my $bad_watch = {};
701 $bad_watch = bless($bad_watch, 'Net::ZooKeeper::Watch');
702
703 $ret = $bad_watch->DESTROY();
704 ok(!$ret,
705 'watch DESTROY(): no action on invalid handle');
706
707
708 ## wait()
709
710 eval {
711 $watch->wait('bar');
712 };
713 like($@, qr/invalid number of arguments/,
714 'wait(): invalid number of arguments');
715
716 eval {
717 $bad_watch->wait();
718 };
719 like($@, qr/invalid handle/,
720 'wait(): invalid watch handle');
721
722 eval {
723 Net::ZooKeeper::Watch::wait(1);
724 };
725 like($@, qr/zkwh is not a hash reference of type Net::ZooKeeper::Watch/,
726 'wait(): invalid watch hash reference');
727
728
729 ## set_log_level()
730
731 eval {
732 my $f = \&Net::ZooKeeper::set_log_level;
733 &$f();
734 };
735 like($@, qr/Usage: Net::ZooKeeper::set_log_level\(level\)/,
736 'set_log_level(): no level specified');
737
738 eval {
739 my $f = \&Net::ZooKeeper::set_log_level;
740 &$f(ZOO_LOG_LEVEL_OFF, 'foo');
741 };
742 like($@, qr/Usage: Net::ZooKeeper::set_log_level\(level\)/,
743 'set_log_level(): too many arguments');
744
745 eval {
746 Net::ZooKeeper::set_log_level((ZOO_LOG_LEVEL_OFF) - 1);
747 };
748 like($@, qr/invalid log level/,
749 'set_log_level(): invalid low log level');
750
751 eval {
752 Net::ZooKeeper::set_log_level((ZOO_LOG_LEVEL_DEBUG) + 1);
753 };
754 like($@, qr/invalid log level/,
755 'set_log_level(): invalid high log level');
756
757
758 ## set_deterministic_conn_order()
759
760 eval {
761 my $f = \&Net::ZooKeeper::set_deterministic_conn_order;
762 &$f();
763 };
764 like($@, qr/Usage: Net::ZooKeeper::set_deterministic_conn_order\(flag\)/,
765 'set_deterministic_conn_order(): no flag specified');
766
767 eval {
768 my $f = \&Net::ZooKeeper::set_deterministic_conn_order;
769 &$f(1, 'foo');
770 };
771 like($@, qr/Usage: Net::ZooKeeper::set_deterministic_conn_order\(flag\)/,
772 'set_deterministic_conn_order(): too many arguments');
773