Dist-Zilla-PluginBundle-Codeberg

 view release on metacpan or  search on metacpan

t/tests/dist/zilla/plugin/codeberg/update.t  view on Meta::CPAN

use Modern::Perl;
use Test2::V0;
use Test2::Tools::Compare qw/hash array bag match/;
use Test2::Tools::Explain;
use Test2::Tools::JSON;
use FindBin;
use lib "$FindBin::Bin/../lib";
use Path::Tiny;
use Test::DZil;

use Dist::Zilla::Plugin::Codeberg;
my $mock_dist_zilla_plugin_codeberg
   = mock 'Dist::Zilla::Plugin::Codeberg' => (
   override => [
      _build_credentials =>
         sub { return { login => 'bob', token => 'AbC00ToKeN' } },
      _get_repo_name => sub { return 'bob/My-Stuff' },
   ],
   );

my $http_request;

use HTTP::Tiny;
my $mock_http_tiny = mock 'HTTP::Tiny' => (
   override => [
      request => sub {
         my $self = shift;
         $http_request = \@_;
         return +{
            success => 1,
            content => '{}',
         };
      }
   ]
);

# TODO Add more tests here
#  - no update needed

my @tests = (
   {
      test_name    => 'update needed',
      config       => { remote => 'origin' },
      log_messages => [
         '[Codeberg::Update] Updating Codeberg repository info',
         '[Codeberg::Update] Sending GET https://codeberg.org/api/v1/repos/bob/My-Stuff',
         '[Codeberg::Update] Sending PATCH https://codeberg.org/api/v1/repos/bob/My-Stuff'
      ],
      errors           => match(qr/Error:/),
      expected_request => [
         'PATCH',
         'https://codeberg.org/api/v1/repos/bob/My-Stuff',
         {
            headers => {
               'content-type'  => 'application/json',
               'Authorization' => 'token AbC00ToKeN',
            },
            content => json(
               {
                  name        => 'My-Stuff',
                  description => 'Sample DZ Dist',
               }
            ),
         },
      ],
   },
);

plan( tests => scalar @tests );

foreach my $test (@tests) {
   subtest $test->{test_name} => sub {
      plan( tests => 5 );

      my $tzil = Builder->from_config(



( run in 1.250 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )