From e42876aa8306c754abd1b3e71a44e13066909fd1 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 21 Jan 2023 17:00:09 +0100 Subject: [PATCH] Add test for fallback to blocking resolver (#108) Co-authored-by: Niklas Keller --- test/IntegrationTest.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/IntegrationTest.php b/test/IntegrationTest.php index f7bace8..efc245e 100644 --- a/test/IntegrationTest.php +++ b/test/IntegrationTest.php @@ -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; @@ -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);