1use strict; 2use warnings; 3use Test::More; 4use Test::MockObject; 5use Test::MockObject::Extends; 6use Net::Gnats::Session; 7 8use File::Basename; 9use lib dirname(__FILE__); 10use Net::Gnats::TestData::Gtdata qw(connect_standard conn user schema1); 11 12Net::Gnats->verbose(1); 13Net::Gnats->verbose_level(1); 14 15my $module = Test::MockObject::Extends->new('IO::Socket::INET'); 16$module->fake_new( 'IO::Socket::INET' ); 17$module->set_true( 'print' ); 18$module->set_series( 'getline', 19 # gconnect 1 - with username 20 @{ conn() }, 21 @{ user() }, 22 "210-Now accessing GNATS database 'default'\r\n", 23 "210 User access level set to 'admin'\r\n", 24 @{ schema1() }, 25 # gconnect 2 - without username 26# "201 CODE_CLOSING\r\n", # reconnect issues quit 27 @{ conn() }, 28 @{ user() }, 29 ); 30 31isa_ok my $g1 = Net::Gnats::Session->new, 'Net::Gnats::Session'; 32is $g1->hostname('192.168.1.203'), '192.168.1.203'; 33is $g1->port, 1529; 34is $g1->username('madmin'), 'madmin'; 35is $g1->password('madmin'), 'madmin'; 36 37isa_ok $g1->gconnect, 'Net::Gnats::Session'; 38is $g1->is_connected, 1; 39is $g1->is_authenticated, 1; 40is $g1->access, 'admin'; 41is $g1->database, 'default'; 42 43isa_ok my $g2 = Net::Gnats::Session->new, 'Net::Gnats::Session'; 44is $g2->hostname, 'localhost', 'default is localhost'; 45is $g2->port, 1529, 'default is 1529'; 46is $g2->username, undef, 'username is not defined'; 47is $g2->password, undef, 'password is not defined'; 48 49isa_ok $g2->gconnect, 'Net::Gnats::Session'; 50is $g2->is_connected, 1; 51is $g2->is_authenticated, 0; 52 53 54 55done_testing; 56