API-Docker

 view release on metacpan or  search on metacpan

t/entity_container.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More;
use lib 't/lib';
use Test::API::Docker::Mock;
use API::Docker::Role::Entity::Container;

# karr k79 step 6, for containers: the convenience methods live in
# API::Docker::Role::Entity::Container and are composed into the two generated
# classes the daemon answers container requests with. Nothing may be written
# into those classes by hand -- maint/spec-to-type.pl --verify compares them
# against the swagger byte for byte (t/spec_to_type.t) -- so this file is what
# proves the methods arrive anyway, and on both shapes.
#
# Fixture-only throughout: none of it needs a daemon, and the assertions are
# about the model rather than about anything an engine answers.

check_live_access();

my $SUMMARY = 'API::Docker::Type::ContainerSummary';
my $INSPECT = 'API::Docker::Type::ContainerInspectResponse';

subtest 'both container shapes carry the same methods' => sub {
  # Written out rather than derived from the role, so that a method quietly
  # disappearing from the role is a failure here and not a shorter list
  # compared against itself.
  my @methods = qw(
    attach changes export get_archive inspect is_running kill logs pause
    put_archive remove resize restart start stat_archive stats stop top
    unpause
  );
  is scalar @methods, 19, 'all nineteen of them are named here';

  for my $class ($SUMMARY, $INSPECT) {
    ok $class->does('API::Docker::Role::Entity::Container'),
      "$class does the container entity role";
    ok $class->does('API::Docker::Role::Entity'),
      "$class does the shared entity role with it";
    my @missing = grep { !$class->can($_) } @methods;
    is_deeply \@missing, [], "$class can every convenience method";
  }
};

subtest 'the generated classes are still the model, not a wrapper around it' => sub {
  plan skip_all => 'fixture-only' if is_live();

  # containers_list/container_inspect (karr k101 follow-up): a real
  # capture -- see t/containers.t.
  my $docker = test_docker(
    'GET /containers/json'          => load_fixture('containers_list'),
    'GET /containers/b20ac7508d80182ba3cd1cbd006ac10c8a15f4f7590fa89c2078d146caf96555/json'
      => load_fixture('container_inspect'),
  );

  my ($c) = @{ $docker->containers->list };
  isa_ok $c, $SUMMARY;
  is $c->id, 'b20ac7508d80182ba3cd1cbd006ac10c8a15f4f7590fa89c2078d146caf96555',
    'the daemon field is on the object itself';
  is $c->image_id,
    'sha256:28bd5fe8b56d1bd048e5babf5b10710ebe0bae67db86916198a6eec434943f8b',
    'including one whose Perl name is not its wire name (ImageID, not ImageId)';

  my $full = $docker->containers->inspect(
    'b20ac7508d80182ba3cd1cbd006ac10c8a15f4f7590fa89c2078d146caf96555');
  isa_ok $full, $INSPECT;



( run in 0.940 second using v1.01-cache-2.11-cpan-364913b4093 )