wiki.techinc.nl/tests/phpunit/includes/libs/DnsSrvDiscovererTest.php
Kunal Mehta c186794722 Add class for service discovery using DNS SRV records
The SrvDiscoverer class can be used to find services (e.g. etcd) using
DNS SRV records.

Change-Id: Ia636d02535a3bb592eb896137cfb787a9ce6442a
2017-03-29 12:59:51 -07:00

88 lines
1.7 KiB
PHP

<?php
class DnsSrvDiscovererTest extends PHPUnit_Framework_TestCase {
/**
* @covers DnsSrvDiscoverer
* @dataProvider provideRecords
*/
public function testPickServer( $params, $expected ) {
$discoverer = new DnsSrvDiscoverer( '_etcd._tcp.eqiad.wmnet' );
$record = $discoverer->pickServer( $params );
$this->assertEquals( $expected, $record );
}
public static function provideRecords() {
return [
[
[ // record list
[
'target' => 'conf1003.eqiad.wmnet',
'port' => 'SRV',
'pri' => 0,
'weight' => 1,
],
[
'target' => 'conf1002.eqiad.wmnet',
'port' => 'SRV',
'pri' => 1,
'weight' => 1,
],
[
'target' => 'conf1001.eqiad.wmnet',
'port' => 'SRV',
'pri' => 2,
'weight' => 1,
],
], // selected record
[
'target' => 'conf1003.eqiad.wmnet',
'port' => 'SRV',
'pri' => 0,
'weight' => 1,
]
],
[
[ // record list
[
'target' => 'conf1003or2.eqiad.wmnet',
'port' => 'SRV',
'pri' => 0,
'weight' => 1,
],
[
'target' => 'conf1003or2.eqiad.wmnet',
'port' => 'SRV',
'pri' => 0,
'weight' => 1,
],
[
'target' => 'conf1001.eqiad.wmnet',
'port' => 'SRV',
'pri' => 2,
'weight' => 1,
],
[
'target' => 'conf1004.eqiad.wmnet',
'port' => 'SRV',
'pri' => 2,
'weight' => 1,
],
[
'target' => 'conf1005.eqiad.wmnet',
'port' => 'SRV',
'pri' => 3,
'weight' => 1,
],
], // selected record
[
'target' => 'conf1003or2.eqiad.wmnet',
'port' => 'SRV',
'pri' => 0,
'weight' => 1,
]
],
];
}
}