1use strict;
2use warnings;
3use Test::More;
4use Test::MockObject;
5use Test::MockObject::Extends;
6use Net::Gnats;
7
8
9use File::Basename;
10use lib dirname(__FILE__);
11use Net::Gnats::TestData::Gtdata qw(connect_standard_wauth conn user schema1);
12
13Net::Gnats->verbose(1);
14Net::Gnats->verbose_level(1);
15
16my $module = Test::MockObject::Extends->new('IO::Socket::INET');
17$module->fake_new( 'IO::Socket::INET' );
18$module->set_true( 'print' );
19$module->set_series( 'getline',
20                     @{ connect_standard_wauth() },
21                     "301 List follows.\r\n",
22                     "default\r\n",
23                     ".\r\n",
24                     "301 List follows.\r\n",
25                     "default\r\n",
26                     ".\r\n",
27                     "301 List follows.\r\n",
28                     "default\r\n",
29                     ".\r\n",
30                     "600 Unauthorized.\r\n",
31                     "301 List follows.\r\n",
32                     "default\r\n",
33                     ".\r\n",
34                     "301 List follows.\r\n",
35                     "default\r\n",
36                     "default2\r\n",
37                     ".\r\n",
38                     @{ conn() },
39                     @{ user() },
40                     "210-Now accessing GNATS database 'default'\r\n",
41                     "210 User access level set to 'admin'\r\n",
42                     @{ schema1() },
43                     "301 List follows.\r\n",
44                     "default\r\n",
45                     "default2\r\n",
46                     ".\r\n",
47                   );
48
49my $g = Net::Gnats::Session->new(username => 'madmin', password => 'madmin');
50$g->gconnect;
51
52my $c1 = Net::Gnats::Command->dbls();
53my $c2 = Net::Gnats::Command->dbls('garbage');
54my $c3 = Net::Gnats::Command->dbls(garbage => 'garbage');
55my $c4_bad = Net::Gnats::Command->dbls();
56
57is $g->issue($c1)->is_ok, 1, 'c1 is OK';
58is $g->issue($c2)->is_ok, 1, 'c2 is OK';
59is $g->issue($c3)->is_ok, 1, 'c3 is OK';
60is $g->issue($c4_bad)->is_ok, 0, 'c4 is not OK';
61
62
63is_deeply $g->issue($c1)->response->as_list, ['default'], 'c1 list is OK';
64is_deeply $g->issue($c1)->response->as_list, ['default', 'default2'], 'c1 list multi is OK';
65
66# Via Net::Gnats
67isa_ok my $ng = Net::Gnats->new('localhost', '1529'), 'Net::Gnats';
68is $ng->gnatsd_connect, 1, 'gnatsd_connect success';
69is $ng->login('default','madmin','madmin'), 1, 'logged in';
70is_deeply $ng->get_dbnames, ['default','default2'], 'retrieve list of names';
71
72done_testing();
73