/t/020_interface/poe-uri.t

http://github.com/http-engine/HTTP-Engine · Raku · 63 lines · 52 code · 10 blank · 1 comment · 2 complexity · 0e0685244737fcaec7f8fba5fe35ed7d MD5 · raw file

  1. use strict;
  2. use warnings;
  3. use Test::More;
  4. use Test::TCP;
  5. use HTTP::Engine;
  6. use Encode;
  7. eval "use POE;use POE::Session;";
  8. plan skip_all => "this test requires POE" if $@;
  9. eval "use POE::Component::Client::HTTP;";
  10. plan skip_all => "this test requires POE::Component::Client::HTTP" if $@;
  11. plan tests => 2;
  12. use_ok 'HTTP::Engine::Interface::POE';
  13. # my $port = empty_port;
  14. my $port = decode_utf8(empty_port);
  15. HTTP::Engine::Interface::POE->new(
  16. request_handler => sub {
  17. my $req = shift;
  18. HTTP::Engine::Response->new(
  19. status => 200,
  20. body => $req->param('channel'),
  21. );
  22. },
  23. alias => 'he',
  24. port => $port,
  25. )->run;
  26. POE::Component::Client::HTTP->spawn(
  27. Alias => 'ua',
  28. );
  29. POE::Session->create(
  30. inline_states => {
  31. _start => sub {
  32. my ($kernel, ) = @_[POE::Session::KERNEL()];
  33. my $req = HTTP::Request->new(
  34. 'GET',
  35. "http://localhost:$port/?channel=%23%E3%81%BB%E3%81%92",
  36. );
  37. $kernel->post(
  38. 'ua',
  39. 'request',
  40. 'response',
  41. $req,
  42. );
  43. },
  44. 'response' => sub {
  45. my ($kernel, ) = @_[POE::Session::KERNEL()];
  46. my $req = @_[POE::Session::ARG0()]->[0];
  47. my $res = @_[POE::Session::ARG1()]->[0];
  48. is($res->content, '#ほげ');
  49. $kernel->stop;
  50. },
  51. },
  52. );
  53. POE::Kernel->run;