1
0
mirror of https://github.com/danog/dns.git synced 2024-11-26 20:14:51 +01:00

Add HostLoader test

This commit is contained in:
Niklas Keller 2017-06-23 18:07:57 +02:00
parent 9ed331ae3d
commit 7ea775f741
3 changed files with 43 additions and 0 deletions

39
test/HostLoaderTest.php Normal file
View File

@ -0,0 +1,39 @@
<?php
namespace Amp\Dns\Test;
use Amp\Dns\HostLoader;
use Amp\Dns\Record;
use Amp\Loop;
use Amp\PHPUnit\TestCase;
class HostLoaderTest extends TestCase {
public function testIgnoresCommentsAndParsesBasicEntry() {
Loop::run(function () {
$loader = new HostLoader(__DIR__ . "/data/hosts");
$this->assertSame([
Record::A => [
"localhost" => "127.0.0.1",
],
], yield $loader->loadHosts());
});
}
public function testReturnsEmptyErrorOnFileNotFound() {
Loop::run(function () {
$loader = new HostLoader(__DIR__ . "/data/hosts.not.found");
$this->assertSame([], yield $loader->loadHosts());
});
}
public function testIgnoresInvalidNames() {
Loop::run(function () {
$loader = new HostLoader(__DIR__ . "/data/hosts.invalid.name");
$this->assertSame([
Record::A => [
"localhost" => "127.0.0.1",
],
], yield $loader->loadHosts());
});
}
}

2
test/data/hosts Normal file
View File

@ -0,0 +1,2 @@
# localhost
127.0.0.1 localhost

View File

@ -0,0 +1,2 @@
# aaa...aa is too long
127.0.0.1 localhost aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa