[Bps-public-commit] app-aws-cloudwatch-monitor branch 0.03/update-meta-data-caching-writes updated. 18bb6dcee2531066d6782dcc00cbbf0b43e112ec
BPS Git Server
git at git.bestpractical.com
Fri May 20 16:33:29 UTC 2022
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "app-aws-cloudwatch-monitor".
The branch, 0.03/update-meta-data-caching-writes has been updated
via 18bb6dcee2531066d6782dcc00cbbf0b43e112ec (commit)
via b7822965c87b23f020024529488b732a103910f8 (commit)
via 3233459b8271374db0a7a7566286e9611e94ef3c (commit)
from a77c977309e66ce3138d24213371eeb43dee2607 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 18bb6dcee2531066d6782dcc00cbbf0b43e112ec
Author: Blaine Motsinger <blaine at bestpractical.com>
Date: Fri May 20 11:33:19 2022 -0500
Add test dep for Test::Warnings
diff --git a/Makefile.PL b/Makefile.PL
index abd072b..0517062 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -29,6 +29,7 @@ WriteMakefile(
'File::Spec' => 0,
'Test::Exception' => '0.42', # recommended by Test2
'Test::More' => '0.98', # for subtest()
+ 'Test::Warnings',
},
PREREQ_PM => {
'base' => 0,
commit b7822965c87b23f020024529488b732a103910f8
Author: Blaine Motsinger <blaine at bestpractical.com>
Date: Fri May 20 11:29:31 2022 -0500
Add tests for get_meta_data
These tests verify the logic and return for get_meta_data
happens when expected:
- don't write cache if meta_data wasn't retrieved from mount
- get meta_data from mount when cache returns empty
- write the cache if meta_data was retrieved from mount
- warn if cache and mount both return no value
The cache read/write and GET requests to AWS are all mocked.
Integration testing to read/write the cache should happen in tests
for read_meta_data and write_meta_data.
diff --git a/t/cloudwatchclient-get_meta_data.t b/t/cloudwatchclient-get_meta_data.t
index 5374026..64b196b 100644
--- a/t/cloudwatchclient-get_meta_data.t
+++ b/t/cloudwatchclient-get_meta_data.t
@@ -94,7 +94,7 @@ my $warning = Test::Warnings::warning { App::AWS::CloudWatch::Monitor::CloudWatc
like(
$warning,
qr/^meta-data resource \/instance-id returned empty/,
- 'warning is generated if meta-data contains no value from cache and mount',
+ 'warning is generated if cache and mount return no meta-data',
);
done_testing();
commit 3233459b8271374db0a7a7566286e9611e94ef3c
Author: Blaine Motsinger <blaine at bestpractical.com>
Date: Fri May 20 11:22:44 2022 -0500
Add tests for get_meta_data
These tests verify the logic within get_meta_data happens when
expected:
- don't write cache if meta_data wasn't retrieved from mount
- get meta_data from mount when cache returns empty
diff --git a/t/cloudwatchclient-get_meta_data.t b/t/cloudwatchclient-get_meta_data.t
new file mode 100644
index 0000000..5374026
--- /dev/null
+++ b/t/cloudwatchclient-get_meta_data.t
@@ -0,0 +1,100 @@
+use strict;
+use warnings;
+
+use FindBin ();
+use lib "$FindBin::RealBin/../lib", "$FindBin::RealBin/lib";
+use App::AWS::CloudWatch::Monitor::Test;
+use Test::Warnings qw{:no_end_test};
+
+my $class = 'App::AWS::CloudWatch::Monitor::CloudWatchClient';
+use_ok($class);
+
+use constant {
+ DO_NOT_CACHE => 0,
+ USE_CACHE => 1,
+};
+
+my %meta_data_cache = (
+ '/instance-id' => 'i12345testcache',
+);
+
+my %meta_data_mount = (
+ '/instance-id' => 'i12345testmount',
+);
+
+my $return_empty_cache = 0;
+App::AWS::CloudWatch::Monitor::Test::override(
+ package => 'App::AWS::CloudWatch::Monitor::CloudWatchClient',
+ name => 'read_meta_data',
+ subref => sub {
+ my $resource = shift;
+ my $default_ttl = shift;
+ my $meta_data;
+ unless ($return_empty_cache) {
+ $meta_data = $meta_data_cache{$resource};
+ }
+ return $meta_data;
+ },
+);
+
+my $meta_data_was_written = 0;
+App::AWS::CloudWatch::Monitor::Test::override(
+ package => 'App::AWS::CloudWatch::Monitor::CloudWatchClient',
+ name => 'write_meta_data',
+ subref => sub {
+ my $resource = shift;
+ my $data_value = shift;
+ $meta_data_was_written = 1;
+ return;
+ },
+);
+
+my $return_empty_mount = 0;
+App::AWS::CloudWatch::Monitor::Test::override(
+ package => 'App::AWS::CloudWatch::Monitor::CloudWatchClient',
+ name => 'get', # get is imported from LWP::Simple
+ subref => sub {
+ my $uri = shift;
+ my $resource;
+ if ( $uri =~ /.latest\/meta-data(\/.+)/ ) {
+ $resource = $1;
+ }
+ my $meta_data;
+ unless ($return_empty_mount) {
+ $meta_data = $meta_data_mount{$resource};
+ }
+ return $meta_data;
+ },
+);
+
+note('get meta_data from cache');
+my $instance_id = App::AWS::CloudWatch::Monitor::CloudWatchClient::get_meta_data( '/instance-id', USE_CACHE );
+is( $instance_id, $meta_data_cache{'/instance-id'}, 'instance-id from cache returned expected' );
+is( $meta_data_was_written, 0, 'meta_data was not written' );
+
+note('get meta_data from mount');
+$return_empty_cache = 1;
+note("don't write the cache");
+$instance_id = App::AWS::CloudWatch::Monitor::CloudWatchClient::get_meta_data( '/instance-id', DO_NOT_CACHE );
+is( $instance_id, $meta_data_mount{'/instance-id'}, 'instance-id from mount returned expected' );
+is( $meta_data_was_written, 0, 'meta_data was not written' );
+
+note("write the cache");
+$instance_id = App::AWS::CloudWatch::Monitor::CloudWatchClient::get_meta_data( '/instance-id', USE_CACHE );
+is( $instance_id, $meta_data_mount{'/instance-id'}, 'instance-id from mount returned expected' );
+is( $meta_data_was_written, 1, 'meta_data was written' );
+$meta_data_was_written = 0;
+
+note("return empty from cache and mount");
+$return_empty_mount = 1;
+$instance_id = App::AWS::CloudWatch::Monitor::CloudWatchClient::get_meta_data( '/instance-id', USE_CACHE );
+is( $instance_id, undef, 'instance-id from mount returned empty' );
+is( $meta_data_was_written, 0, 'meta_data was not written' );
+my $warning = Test::Warnings::warning { App::AWS::CloudWatch::Monitor::CloudWatchClient::get_meta_data( '/instance-id', USE_CACHE ) };
+like(
+ $warning,
+ qr/^meta-data resource \/instance-id returned empty/,
+ 'warning is generated if meta-data contains no value from cache and mount',
+);
+
+done_testing();
-----------------------------------------------------------------------
Summary of changes:
Makefile.PL | 1 +
t/cloudwatchclient-get_meta_data.t | 100 +++++++++++++++++++++++++++++++++++++
2 files changed, 101 insertions(+)
create mode 100644 t/cloudwatchclient-get_meta_data.t
hooks/post-receive
--
app-aws-cloudwatch-monitor
More information about the Bps-public-commit
mailing list