use strict; use warnings; use Plack::Test; use Plack::Builder; use HTTP::Request::Common; use Test::More; use Test::MockObject; my $INFO = { 'redis_version' => '0.1.99', 'db0' => 'keys=167,expires=145', 'db1' => 'keys=75,expires=0', 'uptime_in_seconds' => '1591647', 'role' => 'master', }; my $fakeredis = Test::MockObject->new; Test::MockObject->fake_module('Redis', new => sub { $fakeredis }, VERSION => sub { '1.955' }); $fakeredis->set_true('select', 'quit', 'ping'); $fakeredis->mock('info', sub { $INFO }); { my $app = builder { enable 'Debug', panels => [ [ 'Redis::Info', server => 'localhost:6379' ], ]; sub { [ 200, [ 'Content-Type' => 'text/html' ], [ 'OK' ] ]; }; }; test_psgi $app, sub { my ($cb) = @_; my $res = $cb->(GET '/'); is $res->code, 200, 'Redis-Info: response code 200'; like $res->content, qr||m, 'Redis-Info: panel found'; like $res->content, qr|Version: \d\.\d{1,2}\.\d{1,2}|, 'Redis-Info: subtitle points to redis version'; like $res->content, qr|db0_expires[.\s\n\r]*145|m, 'Redis-Info: 145 expires keys in db0'; like $res->content, qr|db0_keys[.\s\n\r]*167|m, 'Redis-Info: 167 total keys in db0'; like $res->content, qr|db1_expires[.\s\n\r]*0|m, 'Redis-Info: 0 expires keys in db1'; like $res->content, qr|db1_keys[.\s\n\r]*75|m, 'Redis-Info: 75 total keys in db1'; like $res->content, qr|redis_version[.\s\n\r]*\d\.\d{1,2}\.\d{1,2}|m, 'Redis-Info: Redis version presented'; like $res->content, qr|uptime_in_seconds[.\s\n\r]*1591647|m, 'Redis-Info: server uptime match'; like $res->content, qr|role[.\s\n\r]*master|m, 'Redis-Info: server role match'; }; } done_testing();