Skip to content

Commit

Permalink
Merge pull request #40 from pine613/develop
Browse files Browse the repository at this point in the history
Update version to v1.1.5
  • Loading branch information
pine committed Feb 16, 2016
2 parents 17cb018 + 5335b02 commit 69b8308
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/CrystalBuild.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use strict;
use warnings;
use utf8;
use feature qw/say/;
our $VERSION = '1.1.4';
our $VERSION = '1.1.5';

use File::Path qw/rmtree mkpath/;
use JSON::PP;
Expand Down
4 changes: 2 additions & 2 deletions lib/CrystalBuild/Installer/Shards.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ sub _resolve {
my ($self, $crystal_version) = @_;

return CrystalBuild::Resolver::Shards->new(
fetcher => $self->fetcher,
shards_url => $self->shards_url,
fetcher => $self->fetcher,
shards_releases_url => $self->shards_url,
)->resolve($crystal_version);
}

Expand Down
18 changes: 9 additions & 9 deletions lib/CrystalBuild/Resolver/Shards.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ sub new {
return bless { %opt } => $class;
}

sub fetcher { shift->{fetcher} }
sub shards_url { shift->{shards_url} }
sub fetcher { shift->{fetcher} }
sub shards_releases_url { shift->{shards_releases_url} }

sub resolve {
my ($self, $crystal_version) = @_;

my $shards_releases = $self->_fetch;
return unless ref($shards_releases) eq 'HASH';

return $shards_releases->{default}
unless defined $shards_releases->{$crystal_version};
if (defined $shards_releases->{$crystal_version}) {
my $tarball_url = $shards_releases->{$crystal_version};
return $tarball_url unless ref $tarball_url;
}

my $tarball_url = $shards_releases->{$crystal_version};
return if ref $tarball_url;

return $tarball_url;
return $shards_releases->{default} if defined $shards_releases->{default};
return undef;
}

sub _fetch {
my $self = shift;
my $response = $self->fetcher->fetch($self->shards_url);
my $response = $self->fetcher->fetch($self->shards_releases_url);
return decode_json($response);
}

Expand Down
4 changes: 2 additions & 2 deletions t/crystal_build/installer/shards/_resolve.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ subtest basic => sub {
new => sub {
my ($class, %opt) = @_;

is $opt{fetcher}, $fetcher;
is $opt{shards_url}, $shards_url;
is $opt{fetcher}, $fetcher;
is $opt{shards_releases_url}, $shards_url;

return $resolver;
},
Expand Down
29 changes: 29 additions & 0 deletions t/crystal_build/resolver/shards/_fetch.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use strict;
use warnings;
use utf8;

use Test::MockObject;

use t::Util;
use CrystalBuild::Resolver::Shards;

subtest basic => sub {
my $url = Test::MockObject->new;
my $fetcher = Test::MockObject->new;
$fetcher->mock(fetch => sub {
is $_[1], $url;
return do { local $/; <DATA> };
});

my $resolver = CrystalBuild::Resolver::Shards->new(
fetcher => $fetcher,
shards_releases_url => $url,
);

cmp_deeply $resolver->_fetch, { result => "ok" };
ok $fetcher->called('fetch');
};

done_testing;
__DATA__
{ "result": "ok" }
20 changes: 20 additions & 0 deletions t/crystal_build/resolver/shards/new.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use strict;
use warnings;
use utf8;

use t::Util;
use CrystalBuild::Resolver::Shards;

subtest basic => sub {
my $resolver = CrystalBuild::Resolver::Shards->new(
fetcher => '__FETCHER__',
shards_releases_url => '__SHARDS_RELEASES_URL__',
);

isa_ok $resolver, 'CrystalBuild::Resolver::Shards';

is $resolver->fetcher, '__FETCHER__';
is $resolver->shards_releases_url, '__SHARDS_RELEASES_URL__';
};

done_testing;
48 changes: 48 additions & 0 deletions t/crystal_build/resolver/shards/resolve.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use strict;
use warnings;
use utf8;

use Test::Mock::Guard qw/mock_guard/;

use t::Util;
use CrystalBuild::Resolver::Shards;

subtest basic => sub {
my $releases;
my $guard = mock_guard('CrystalBuild::Resolver::Shards', {
_fetch => sub { $releases },
});
my $resolver = CrystalBuild::Resolver::Shards->new;

subtest '#ok' => sub {
$releases = { '0.11.0' => '__URL__' };
is $resolver->resolve('0.11.0'), '__URL__';
};

subtest '#ok ... default' => sub {
$releases = { 'default' => '__URL__' };
is $resolver->resolve('0.10.0'), '__URL__';
};

subtest '#ng ... not found' => sub {
$releases = { '0.11.0' => '__URL__' };
is $resolver->resolve('0.10.0'), undef;
};

subtest '#ng ... null' => sub {
$releases = undef;
is $resolver->resolve('0.11.0'), undef;
};

subtest '#ng ... string' => sub {
$releases = 'STRING';
is $resolver->resolve('0.11.0'), undef;
};

subtest '#ng ... array' => sub {
$releases = [];
is $resolver->resolve('0.11.0'), undef;
};
};

done_testing;

0 comments on commit 69b8308

Please sign in to comment.