Add drone.yml and fix tests to be compatable with docker pipeline (#1)
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is failing

init drone file
allow testing on custom host/port

Co-authored-by: James <inbox.dev@jhodges.co.uk>
Reviewed-on: #1
Co-Authored-By: James <jhodges@noreply@git.jhodges.co.uk>
Co-Committed-By: James <jhodges@noreply@git.jhodges.co.uk>
This commit is contained in:
James 2020-09-30 15:13:56 +01:00
parent dbe1481e5c
commit 069e951f3d
4 changed files with 126 additions and 94 deletions

35
.drone.yml Normal file
View File

@ -0,0 +1,35 @@
kind: pipeline
type: docker
name: testsuite
steps:
- name: composer install
image: chialab/php
commands:
- composer install
volumes:
- name: composer-cache
path: /root/.composer/cache/
- name: wait for test server
image: alpine
commands:
- echo "Waiting for server to launch on testserver:8080..."
- while ! nc -z testserver 8080; do sleep 0.1 ; done
- echo "Ready!"
- name: run tests
image: chialab/php
commands:
- URL=http://testserver:8080 vendor/bin/phpunit tests
services:
- name: testserver
image: node
detach: true
commands:
- cd tests/server/
- npm install
- node server.js

View File

@ -37,7 +37,8 @@ Start the test server, will listen on localhost:8080
```plain
cd tests/server
./start_server.sh
npm install
node server.js
```
Run the tests:

View File

@ -6,188 +6,197 @@ use GuzzleHttp\RequestOptions;
class CrawlerTest extends TestCase{
private $url='http://localhost:8080';
public function __construct(){
parent::__construct();
if(getenv('URL')){
$this->url=getenv('URL');
}
}
public function testFullSite(){
$crawler=new Crawler([RequestOptions::CONNECT_TIMEOUT => 3, RequestOptions::TIMEOUT => 3]);
$crawler->crawl('http://localhost:8080/');
$crawler->crawl($this->url);
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://example.com/' => ['code' => 200],
'http://localhost:8080/deeplink1' => ['code' => 200],
'http://localhost:8080/deeplink2' => ['code' => 200],
'http://localhost:8080/deeplink3' => ['code' => 200],
'http://localhost:8080/externalLink' => ['code' => 200],
'http://localhost:8080/found' => ['code' => 200],
'http://localhost:8080/interlinked1' => ['code' => 200],
'http://localhost:8080/interlinked2' => ['code' => 200],
'http://localhost:8080/interlinked3' => ['code' => 200],
'http://localhost:8080/internalServerError' => ['code' => 500],
'http://localhost:8080/invalidStatusCode' => ['code' => '---'],
'http://localhost:8080/notFound' => ['code' => 404],
'http://localhost:8080/redirect1' => ['code' => 302],
'http://localhost:8080/redirect2' => ['code' => 302],
'http://localhost:8080/redirectLoop' => ['code' => '---'],
'http://localhost:8080/redirectToFound' => ['code' => 302 ],
'http://localhost:8080/redirectToNotFound' => ['code' => 302 ],
'http://localhost:8080/redirectToRedirectToNotFound' => ['code' => 302],
'http://localhost:8080/timeout' => ['code' => '---'],
'http://localhost:8080/twoRedirectsToSameLocation' => ['code' => 200],
$this->url.'/deeplink1' => ['code' => 200],
$this->url.'/deeplink2' => ['code' => 200],
$this->url.'/deeplink3' => ['code' => 200],
$this->url.'/externalLink' => ['code' => 200],
$this->url.'/found' => ['code' => 200],
$this->url.'/interlinked1' => ['code' => 200],
$this->url.'/interlinked2' => ['code' => 200],
$this->url.'/interlinked3' => ['code' => 200],
$this->url.'/internalServerError' => ['code' => 500],
$this->url.'/invalidStatusCode' => ['code' => '---'],
$this->url.'/notFound' => ['code' => 404],
$this->url.'/redirect1' => ['code' => 302],
$this->url.'/redirect2' => ['code' => 302],
$this->url.'/redirectLoop' => ['code' => '---'],
$this->url.'/redirectToFound' => ['code' => 302 ],
$this->url.'/redirectToNotFound' => ['code' => 302 ],
$this->url.'/redirectToRedirectToNotFound' => ['code' => 302],
$this->url.'/timeout' => ['code' => '---'],
$this->url.'/twoRedirectsToSameLocation' => ['code' => 200],
], print_r($sitemap,true));
}
public function testFound(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/found');
$crawler->crawl($this->url.'/found');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/found' => ['code' => 200],
$this->url.'/found' => ['code' => 200],
], print_r($sitemap,true));
}
public function testNotFound(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/notFound');
$crawler->crawl($this->url.'/notFound');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/notFound' => ['code' => 404],
$this->url.'/notFound' => ['code' => 404],
], print_r($sitemap,true));
}
public function testExternalLink(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/externalLink');
$crawler->crawl($this->url.'/externalLink');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/externalLink' => ['code' => 200],
$this->url.'/externalLink' => ['code' => 200],
'http://example.com/' => ['code' => 200],
], print_r($sitemap,true));
}
public function testDeeplink(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/deeplink1');
$crawler->crawl($this->url.'/deeplink1');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/deeplink1' => ['code' => 200],
'http://localhost:8080/deeplink2' => ['code' => 200],
'http://localhost:8080/deeplink3' => ['code' => 200],
$this->url.'/deeplink1' => ['code' => 200],
$this->url.'/deeplink2' => ['code' => 200],
$this->url.'/deeplink3' => ['code' => 200],
], print_r($sitemap,true));
}
public function testInterlinked(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/interlinked1');
$crawler->crawl('http://localhost:8080/interlinked4'); //this ensures the order or results for the URL tracking test PART2
$crawler->crawl($this->url.'/interlinked1');
$crawler->crawl($this->url.'/interlinked4'); //this ensures the order or results for the URL tracking test PART2
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/interlinked1' => ['code' => 200 , 'foundOn' => [
'http://localhost:8080/interlinked1' => 1,
'http://localhost:8080/interlinked2' => 1,
'http://localhost:8080/interlinked3' => 1,
'http://localhost:8080/interlinked4' => 1,
$this->url.'/interlinked1' => ['code' => 200 , 'foundOn' => [
$this->url.'/interlinked1' => 1,
$this->url.'/interlinked2' => 1,
$this->url.'/interlinked3' => 1,
$this->url.'/interlinked4' => 1,
]],
'http://localhost:8080/interlinked2' => ['code' => 200 , 'foundOn' => [
'http://localhost:8080/interlinked1' => 1,
'http://localhost:8080/interlinked2' => 1,
'http://localhost:8080/interlinked3' => 1,
'http://localhost:8080/interlinked4' => 1,
$this->url.'/interlinked2' => ['code' => 200 , 'foundOn' => [
$this->url.'/interlinked1' => 1,
$this->url.'/interlinked2' => 1,
$this->url.'/interlinked3' => 1,
$this->url.'/interlinked4' => 1,
]],
'http://localhost:8080/interlinked3' => ['code' => 200 , 'foundOn' => [
'http://localhost:8080/interlinked1' => 1,
'http://localhost:8080/interlinked2' => 1,
'http://localhost:8080/interlinked3' => 1,
'http://localhost:8080/interlinked4' => 1,
$this->url.'/interlinked3' => ['code' => 200 , 'foundOn' => [
$this->url.'/interlinked1' => 1,
$this->url.'/interlinked2' => 1,
$this->url.'/interlinked3' => 1,
$this->url.'/interlinked4' => 1,
]],
'http://localhost:8080/found' => ['code' => 200 , 'foundOn' => [
'http://localhost:8080/interlinked1' => 1,
'http://localhost:8080/interlinked2' => 1,
'http://localhost:8080/interlinked3' => 1,
'http://localhost:8080/interlinked4' => 1,
$this->url.'/found' => ['code' => 200 , 'foundOn' => [
$this->url.'/interlinked1' => 1,
$this->url.'/interlinked2' => 1,
$this->url.'/interlinked3' => 1,
$this->url.'/interlinked4' => 1,
]],
'http://localhost:8080/redirectToFound' => ['code' => 302 , 'foundOn' => [
'http://localhost:8080/interlinked1' => 1,
'http://localhost:8080/interlinked2' => 1,
'http://localhost:8080/interlinked3' => 1,
'http://localhost:8080/interlinked4' => 1,
$this->url.'/redirectToFound' => ['code' => 302 , 'foundOn' => [
$this->url.'/interlinked1' => 1,
$this->url.'/interlinked2' => 1,
$this->url.'/interlinked3' => 1,
$this->url.'/interlinked4' => 1,
]],
], print_r($sitemap,true));
}
public function testRedirectToFound(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/redirectToFound');
$crawler->crawl($this->url.'/redirectToFound');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/redirectToFound' => ['code' => 302],
'http://localhost:8080/found' => ['code' => 200 ],
$this->url.'/redirectToFound' => ['code' => 302],
$this->url.'/found' => ['code' => 200 ],
], print_r($sitemap,true));
}
public function testRedirectToNotFound(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/redirectToNotFound');
$crawler->crawl($this->url.'/redirectToNotFound');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/redirectToNotFound' => ['code' => 302],
'http://localhost:8080/notFound' => ['code' => 404 ],
$this->url.'/redirectToNotFound' => ['code' => 302],
$this->url.'/notFound' => ['code' => 404 ],
], print_r($sitemap,true));
}
public function testRedirectToRedirectToNotFound(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/redirectToRedirectToNotFound');
$crawler->crawl($this->url.'/redirectToRedirectToNotFound');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/redirectToRedirectToNotFound' => ['code' => 302],
'http://localhost:8080/redirectToNotFound' => ['code' => 302],
'http://localhost:8080/notFound' => ['code' => 404],
$this->url.'/redirectToRedirectToNotFound' => ['code' => 302],
$this->url.'/redirectToNotFound' => ['code' => 302],
$this->url.'/notFound' => ['code' => 404],
], print_r($sitemap,true));
}
public function testTwoRedirectsToSameLocation(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/twoRedirectsToSameLocation');
$crawler->crawl($this->url.'/twoRedirectsToSameLocation');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/twoRedirectsToSameLocation' => ['code' => 200],
'http://localhost:8080/redirect1' => ['code' => 302],
'http://localhost:8080/redirect2' => ['code' => 302],
'http://localhost:8080/found' => ['code' => 200],
$this->url.'/twoRedirectsToSameLocation' => ['code' => 200],
$this->url.'/redirect1' => ['code' => 302],
$this->url.'/redirect2' => ['code' => 302],
$this->url.'/found' => ['code' => 200],
], print_r($sitemap,true));
}
public function testTimeout(){
$crawler=new Crawler([RequestOptions::CONNECT_TIMEOUT => 3, RequestOptions::TIMEOUT => 3]);
$crawler->crawl('http://localhost:8080/timeout');
$crawler->crawl($this->url.'/timeout');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/timeout' => ['code' => '---'],
$this->url.'/timeout' => ['code' => '---'],
], print_r($sitemap,true));
}
public function testRedirectLoop(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/redirectLoop');
$crawler->crawl($this->url.'/redirectLoop');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/redirectLoop' => ['code' => '---'],
$this->url.'/redirectLoop' => ['code' => '---'],
], print_r($sitemap,true));
}
public function testInternalServerError(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/internalServerError');
$crawler->crawl($this->url.'/internalServerError');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/internalServerError' => ['code' => 500],
$this->url.'/internalServerError' => ['code' => 500],
], print_r($sitemap,true));
}
public function testInvalidStatusCode(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/invalidStatusCode');
$crawler->crawl($this->url.'/invalidStatusCode');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/invalidStatusCode' => ['code' => '---'],
$this->url.'/invalidStatusCode' => ['code' => '---'],
], print_r($sitemap,true));
}

View File

@ -1,13 +0,0 @@
#!/usr/bin/env bash
npm install
if [ -z ${TRAVIS_JOB_ID} ]; then
# not running under travis, stay in foreground until stopped
node server.js
else
cd tests/server
# running under travis, daemonize
(node server.js &) || /bin/true
fi