From c6442cc3814edb6df6fdaf18ffe1c81d56d17376 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Tue, 19 Mar 2013 17:13:50 +0100 Subject: [PATCH] Provide test to check web sites --- debian/control | 2 + debian/copyright | 2 +- pro/03_sites-ok.t | 92 ++++++++++++++++++++++++++++++++++++++++++++ pro/test-server.yaml | 11 ++++++ 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 pro/03_sites-ok.t diff --git a/debian/control b/debian/control index 07f3c2c..3d912fb 100644 --- a/debian/control +++ b/debian/control @@ -11,6 +11,8 @@ Architecture: all Depends: libfilesys-diskspace-perl, libproc-processtable-perl, libtest-server-perl, + libtest-www-mechanize-perl, + perl-modules, ${misc:Depends}, ${perl:Depends} Description: run system tests against NGCP systems diff --git a/debian/copyright b/debian/copyright index 39a9b48..b04d0d0 100644 --- a/debian/copyright +++ b/debian/copyright @@ -3,7 +3,7 @@ Upstream-Name: ngcp-system-tests Source: http://github.com/sipwise/system-tests/ Upstream-Contact: Michael Prokop -Files: {ce,pro}/01_hostname-and-interfaces.t ce/01_running-processes.t ce/02_disk-free.t pro/03_open-ports.t +Files: {ce,pro}/01_hostname-and-interfaces.t ce/01_running-processes.t ce/02_disk-free.t pro/03_open-ports.t pro/03_sites-ok.t Copyright: Jozef Kutej License: Artistic or GPL-1+ diff --git a/pro/03_sites-ok.t b/pro/03_sites-ok.t new file mode 100644 index 0000000..d714b76 --- /dev/null +++ b/pro/03_sites-ok.t @@ -0,0 +1,92 @@ +#!/usr/bin/perl + +=head1 NAME + +sites-ok.t - check web sites + +=head SYNOPSIS + + cat >> test-server.yaml << __YAML_END__ + sites-ok: + sites: + http://ant.local: + content: It works! + http://debrepo.ant.local/debian/: + title : Index of /[a-z]+ + content: Parent Directory + __YAML_END__ + +=cut + +use strict; +use warnings; + +use Test::More; +use Test::Differences; +use YAML::Syck 'LoadFile'; +use FindBin '$Bin'; + + +eval "use Test::WWW::Mechanize"; +plan 'skip_all' => "need Test::WWW::Mechanize to run web tests" if $@; + +my $config = LoadFile($Bin.'/test-server.yaml'); +plan 'skip_all' => "no configuration sections for 'sites-ok'" + if (not $config or not $config->{'sites-ok'}); + + +exit main(); + +sub main { + plan 'no_plan'; + + my $mech = Test::WWW::Mechanize->new; + my $sites = $config->{'sites-ok'}->{'sites'}; + + # loop through sites that needs to be working + foreach my $base_url (keys %$sites) { + $mech->get_ok($base_url, 'fetch '.$base_url); + + # test site title + my %site = %{$sites->{$base_url}}; + + # check title + like($mech->title, qr/$site{'title'}/, 'check title') + if exists $site{'title'}; + + #check content + like($mech->content, qr/$site{'content'}/, 'check content') + if exists $site{'content'}; + + # fetch site links + my $INTERNAL_LINKS_QR = qr{ + ^ + ( + $base_url # links starting with base url + | + (?![a-zA-Z]+:) # and NOT starting with http: or mailto: or ftp: or ... + ) + }xms; + + $mech->links_ok( + # match the links that starts with base url or are without http(s) in the beginning + [ $mech->find_all_links( url_regex => $INTERNAL_LINKS_QR ) ], + 'check all internal page links', + ); + } + + return 0; +} + + +__END__ + +=head1 NOTE + +Web checking depends on L. + +=head1 AUTHOR + +Jozef Kutej + +=cut diff --git a/pro/test-server.yaml b/pro/test-server.yaml index cc51708..793acd1 100644 --- a/pro/test-server.yaml +++ b/pro/test-server.yaml @@ -88,3 +88,14 @@ open-ports: 6379: redis-server deb.sipwise.com: 80: http + +sites-ok: + sites: + https://localhost/login/: + title: "Sipwise NGCP CSC" + content: "Self-Administration Login" + https://localhost:1443/: + title: "Sipwise NGCP admin interface" + content: "Sipwise NGCP Administration Interface" + https://localhost:2443/SOAP/Provisioning.wsdl: + content: "xmlns:tns=\"http://dev.sipwise.com/SOAP/Provisioning\""