You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gentoo-overlay/dev-perl/Feed-Find/files/Feed-Find-0.07-local-networ...

110 lines
3.1 KiB

From bea092aae37300053b971a12b6e37b6104df41f9 Mon Sep 17 00:00:00 2001
From: Nikolay Mishin <mi@ya.ru>
Date: Thu, 22 Oct 2015 02:59:04 +0400
Subject: Rework 01-find.t
Rework test to not rely on external web resources by mocking the setup
with a HTTP::Server::Simple derived webserver
Bug: https://github.com/btrott/Feed-Find/pull/2
Signed-off-by: Gary Greene <greeneg@tolharadys.net>
Signed-off-by: Kent Fredric <kentnl@gentoo.org>
---
t/01-find.t | 57 ++++++++++++++++++++++++++++++++------
t/htdocs/anchors-only.html | 9 ++++++
2 files changed, 58 insertions(+), 8 deletions(-)
create mode 100644 t/htdocs/anchors-only.html
diff --git a/t/01-find.t b/t/01-find.t
index 58549b5..22d0048 100644
--- a/t/01-find.t
+++ b/t/01-find.t
@@ -1,20 +1,61 @@
+use CGI::Application::Server;
+use Test::HTTP::Server::Simple;
+
+package My::WebServer {
+ use base qw/Test::HTTP::Server::Simple CGI::Application::Server/;
+}
+
+package main;
+
use strict;
-use Test::More tests => 4;
+use Test::More tests => 5;
use Feed::Find;
use LWP::UserAgent;
-use constant BASE => 'http://stupidfool.org/perl/feeds/';
+my $port = $ENV{CGI_APP_SERVER_TEST_PORT} || 40000 + int(rand(10000));
+
+my $s = My::WebServer->new($port);
+$s->document_root('./t/htdocs');
+
+my $url_root = $s->started_ok("start up my web server");
+
+# generate our anchors-only.html file to get the URL correct in the links
+my $anchor_html = <<"END";
+<html>
+ <head>
+ <link rel="alternate" title="my feed"
+ href="$url_root/ok.xml" type="application/xml" />
+ <head>
+ <body>
+ <a href="$url_root/ok.xml" type="application/xml">my feed</a>
+ </body>
+</html>
+END
-my(@feeds);
+open(my $fh, ">./t/htdocs/anchors-only.html") or
+ die "Cannot open file\n";
+print $fh <<"END";
+<html>
+ <head>
+ <link rel="alternate" title="my feed"
+ href="$url_root/ok.xml" type="application/xml" />
+ <head>
+ <body>
+ <a href="$url_root/ok.xml" type="application/xml">my feed</a>
+ </body>
+</html>
+END
+close $fh;
-@feeds = Feed::Find->find(BASE . 'anchors-only.html');
+my @feeds = ();
+@feeds = Feed::Find->find("$url_root/anchors-only.html");
is(scalar @feeds, 1);
-is($feeds[0], BASE . 'ok.xml');
+is($feeds[0], "$url_root/ok.xml");
my $ua = LWP::UserAgent->new;
$ua->env_proxy;
-my $req = HTTP::Request->new(GET => BASE . 'anchors-only.html');
+my $req = HTTP::Request->new(GET => "$url_root/anchors-only.html");
my $res = $ua->request($req);
-@feeds = Feed::Find->find_in_html(\$res->content, BASE . 'anchors-only.html');
+@feeds = Feed::Find->find_in_html(\$res->content, "$url_root/anchors-only.html");
is(scalar @feeds, 1);
-is($feeds[0], BASE . 'ok.xml');
+is($feeds[0], "$url_root/ok.xml");
diff --git a/t/htdocs/anchors-only.html b/t/htdocs/anchors-only.html
new file mode 100644
index 0000000..79f1df8
--- /dev/null
+++ b/t/htdocs/anchors-only.html
@@ -0,0 +1,9 @@
+<html>
+ <head>
+ <link rel="alternate" title="my feed"
+ href="http://localhost:45578/ok.xml" type="application/xml" />
+ <head>
+ <body>
+ <a href="http://localhost:45578/ok.xml" type="application/xml">my feed</a>
+ </body>
+</html>
--
2.28.0