Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding unit tests for MDC module
  • Loading branch information
abeez8191 committed Oct 13, 2023
commit f2f9b9663ba86d90423e310fad25928afa9d707c
48 changes: 48 additions & 0 deletions t/072.MDC.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
BEGIN {
if($ENV{INTERNAL_DEBUG}) {
require Log::Log4perl::InternalDebug;
Log::Log4perl::InternalDebug->enable();
}
}

use strict;
use warnings;

use Test::More;
use Log::Log4perl::MDC;

Log::Log4perl::MDC::put('test-one', 'value-one');
is( Log::Log4perl::MDC::get('test-one'),
'value-one',
'Calling put/get class methods works with colon notation'
);

Log::Log4perl::MDC->put('test-two', 'value-two');
is( Log::Log4perl::MDC->get('test-two'),
'value-two',
'Calling put/get class methods works with arrow notation'
);

# We have verified both arrow and colon notation work. Sticking
# with arrow notation from now on.

Log::Log4perl::MDC->put('test-three' => 'value-three',
'test-three-part-two' => 'value-three-part-two');
is( Log::Log4perl::MDC->get('test-three') . Log::Log4perl::MDC->get('test-three-part-two'),
'value-threevalue-three-part-two',
'Calling put with multiple key/value pairs adds all to store'
);

Log::Log4perl::MDC->put({ 'test-four' => 'value-four',
'test-four-part-two' => 'value-four-part-two' });
is( Log::Log4perl::MDC->get('test-four') . Log::Log4perl::MDC->get('test-four-part-two'),
'value-fourvalue-four-part-two',
'Calling put with hashref adds all key/values to store'
);

is( Log::Log4perl::MDC->get('test-five'), undef, 'Calling get on unknown key returns undef');

Log::Log4perl::MDC->remove();
is_deeply(Log::Log4perl::MDC->get_context(), {}, 'Calling remove deletes all entries');

done_testing;