Skip to content

Commit

Permalink
Add test for fallback to blocking resolver (#108)
Browse files Browse the repository at this point in the history
Co-authored-by: Niklas Keller <[email protected]>
  • Loading branch information
danog and kelunik committed Jan 21, 2023
1 parent f528711 commit e42876a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Amp\Cache\NullCache;
use Amp\Dns;
use Amp\Dns\DnsConfigException;
use Amp\Dns\DnsException;
use Amp\Dns\DnsRecord;
use Amp\Dns\UnixDnsConfigLoader;
Expand Down Expand Up @@ -139,6 +140,28 @@ public function testResolveWithRotateList(): void
self::assertNotSame($record1->getValue(), $record2->getValue());
}

public function testResolveWithBlockingResolver(): void
{
/** @var Dns\DnsConfigLoader|MockObject $configLoader */
$configLoader = $this->createMock(Dns\DnsConfigLoader::class);
$configLoader->expects(self::once())
->method('loadConfig')
->willThrowException(new DnsConfigException("Can't access /etc/resolv.conf!"));

$resolver = new Dns\Rfc1035StubDnsResolver(new NullCache(), $configLoader);

$records = $resolver->query('google.com', Dns\DnsRecord::A);

foreach ($records as $record) {
self::assertSame(DnsRecord::A, $record->getType());
$inAddr = \inet_pton($record->getValue());
self::assertNotFalse(
$inAddr,
"Server name google.com did not resolve to a valid IP address"
);
}
}

public function testPtrLookup(): void
{
$result = Dns\query("8.8.4.4", DnsRecord::PTR);
Expand Down

0 comments on commit e42876a

Please sign in to comment.