App-Adenosine

 view release on metacpan or  search on metacpan

t/basic.t  view on Meta::CPAN

* Closing connection #0
BLUUU

%TestAdenosine::host_config = ( 'google.com' => <<'CONFIG' );
 GET -H 'Accept: text/html'

 POST -u foo:bar
CONFIG

$TestAdenosine::curl_stdout = <<'BLUU2';
{"some":"json"}
BLUU2

my $exit_code = TestAdenosine->new({ argv => ['GET'], @noxdg });
cmp_deeply(\@TestAdenosine::curl_options, [
   qw(curl -sLv -X GET -b), $c, '-c', $c, '-H', 'Accept: text/html',
   'https://google.com/user//1',
], 'GET');
is($TestAdenosine::stdout, $TestAdenosine::curl_stdout, 'output the right stuff!');

ok(!$exit_code, '200 means exit with 0');

$TestAdenosine::curl_stderr =~ s[(< HTTP/1\.1 )2][${1}5];
$exit_code = TestAdenosine->new({
   argv => [qw(GET 1 -v)],
   plugins => [{ '::Plugin2' => {} }],
   @noxdg,
});
cmp_deeply(\@TestAdenosine::curl_options, [
   qw(curl -sLv -X GET -b), $c, '-c', $c, '-H', 'Accept: text/html',
   'https://google.com/user/1/1',
], 'GET 1');
is($exit_code, 5, '500 exits correctly');
is($TestAdenosine::stderr, "'curl' '-sLv' '-X' 'GET' '-b' '$c' '-c' '$c' '-H' 'Accept: text/html' 'https://google.com/user/1/1'
$TestAdenosine::curl_stderr", '-v works');

TestAdenosine->new({ argv => [qw(POST 2), '{"foo":"bar"}'], @noxdg });
cmp_deeply(\@TestAdenosine::curl_options, [
   qw(curl -sLv {"foo":"bar"} -X POST -b ), $c, '-c', $c, qw(
      --data-binary -u foo:bar https://google.com/user/2/1),
], 'POST 2 $data');

if ($^O ne 'MSWin32') {
   TestAdenosine->new({ argv => [qw(POST 2), '-V'], @noxdg });
   cmp_deeply(\@TestAdenosine::curl_options, [
      qw(curl -sLv), '["frew","bar","baz"]', qw(-X POST -b ), $c, '-c', $c, qw(
         --data-binary -u foo:bar https://google.com/user/2/1),
   ], 'POST -V $data');
}

TestAdenosine->new({ argv => [qw(HEAD -u)], @noxdg });
cmp_deeply(\@TestAdenosine::curl_options, [
   qw(curl -sLv -X HEAD -b), $c, '-c', $c, qw(
     -u -I https://google.com/user//1),
], 'HEAD adds -I');

TestAdenosine->new({ argv => [qw(GET -q foo&bar)], @noxdg });
cmp_deeply(\@TestAdenosine::curl_options, [
   qw(curl -sLv -X GET -b), $c, '-c', $c, qw(
      -H ), 'Accept: text/html', 'https://google.com/user//1?foo%26bar',
], 'GET escaped');

TestAdenosine->new({ argv => [qw(GET -Q -q foo&bar)], @noxdg });
cmp_deeply(\@TestAdenosine::curl_options, [
   qw(curl -sLv -X GET -b), $c, '-c', $c, qw(
      -H ), 'Accept: text/html', 'https://google.com/user//1?foo&bar',
], 'GET not escaped');

{
local $ENV{XDG_CONFIG_HOME} = "$ENV{HOME}/.config";
my $c = "$ENV{XDG_CONFIG_HOME}/resty/c/google.com";
$c =~ s(/)(\\)g if $^O eq 'MSWin32';
TestAdenosine->new({ argv => [qw(GET foo)], });
cmp_deeply(\@TestAdenosine::curl_options, [
   qw(curl -sLv -X GET -b), $c, '-c', $c, qw(
      -H ), 'Accept: text/html', 'https://google.com/user/foo/1',
], 'GET not escaped');
}
done_testing;

BEGIN {
   package TestAdenosine;

   use strict;
   use warnings;

   if ($] >= 5.010) {
     require mro;
   } else {
     require MRO::Compat;
   }

   use lib 'lib';
   use base 'App::Adenosine';

   our @curl_options;
   our $stdout = '';
   our $stderr = '';
   our $curl_stderr;
   our $curl_stdout;
   our $uri_base;
   our %host_config;
   our @extra_options;

   sub _set_uri_base { $uri_base = $_[1] }
   sub _get_uri_base { $uri_base }
   sub _load_host_method_config { split /\n/, $host_config{$_[1]} }

   sub new {
      my $self = shift;

      $stdout = '';
      $stderr = '';

      $self->next::method(@_)
   }

   sub capture_curl {
      my $self = shift;
      @curl_options = @_;

      return ($curl_stdout, $curl_stderr, 0);
   }

   sub stdout { $stdout .= $_[1] }
   sub stderr { $stderr .= $_[1] }

   sub _set_extra_options { my $self = shift; @extra_options = @_ }
   sub _get_extra_options { @extra_options }

   package Plugin1;

   $INC{'Plugin1.pm'} = __FILE__;
   use Moo;

   with 'App::Adenosine::Role::FiltersStdErr';



( run in 0.684 second using v1.01-cache-2.11-cpan-39bf76dae61 )