Use MediaWikiCoversValidator for tests that don't use MediaWikiTestCase
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / DnsSrvDiscovererTest.php
index f768d06..bc20c4c 100644 (file)
@@ -1,16 +1,18 @@
 <?php
 
 class DnsSrvDiscovererTest extends PHPUnit_Framework_TestCase {
+
+       use MediaWikiCoversValidator;
+
        /**
         * @covers DnsSrvDiscoverer
         * @dataProvider provideRecords
         */
        public function testPickServer( $params, $expected ) {
-               $discoverer = new DnsSrvDiscoverer( '_etcd._tcp.eqiad.wmnet' );
+               $discoverer = new DnsSrvDiscoverer( 'etcd-tcp.example.net' );
                $record = $discoverer->pickServer( $params );
 
                $this->assertEquals( $expected, $record );
-
        }
 
        public static function provideRecords() {
@@ -18,26 +20,26 @@ class DnsSrvDiscovererTest extends PHPUnit_Framework_TestCase {
                        [
                                [ // record list
                                        [
-                                               'target' => 'conf1003.eqiad.wmnet',
+                                               'target' => 'conf03.example.net',
                                                'port' => 'SRV',
                                                'pri' => 0,
                                                'weight' => 1,
                                        ],
                                        [
-                                               'target' => 'conf1002.eqiad.wmnet',
+                                               'target' => 'conf02.example.net',
                                                'port' => 'SRV',
                                                'pri' => 1,
                                                'weight' => 1,
                                        ],
                                        [
-                                               'target' => 'conf1001.eqiad.wmnet',
+                                               'target' => 'conf01.example.net',
                                                'port' => 'SRV',
                                                'pri' => 2,
                                                'weight' => 1,
                                        ],
                                ], // selected record
                                [
-                                       'target' => 'conf1003.eqiad.wmnet',
+                                       'target' => 'conf03.example.net',
                                        'port' => 'SRV',
                                        'pri' => 0,
                                        'weight' => 1,
@@ -46,38 +48,38 @@ class DnsSrvDiscovererTest extends PHPUnit_Framework_TestCase {
                        [
                                [ // record list
                                        [
-                                               'target' => 'conf1003or2.eqiad.wmnet',
+                                               'target' => 'conf03or2.example.net',
                                                'port' => 'SRV',
                                                'pri' => 0,
                                                'weight' => 1,
                                        ],
                                        [
-                                               'target' => 'conf1003or2.eqiad.wmnet',
+                                               'target' => 'conf03or2.example.net',
                                                'port' => 'SRV',
                                                'pri' => 0,
                                                'weight' => 1,
                                        ],
                                        [
-                                               'target' => 'conf1001.eqiad.wmnet',
+                                               'target' => 'conf01.example.net',
                                                'port' => 'SRV',
                                                'pri' => 2,
                                                'weight' => 1,
                                        ],
                                        [
-                                               'target' => 'conf1004.eqiad.wmnet',
+                                               'target' => 'conf04.example.net',
                                                'port' => 'SRV',
                                                'pri' => 2,
                                                'weight' => 1,
                                        ],
                                        [
-                                               'target' => 'conf1005.eqiad.wmnet',
+                                               'target' => 'conf05.example.net',
                                                'port' => 'SRV',
                                                'pri' => 3,
                                                'weight' => 1,
                                        ],
                                ], // selected record
                                [
-                                       'target' => 'conf1003or2.eqiad.wmnet',
+                                       'target' => 'conf03or2.example.net',
                                        'port' => 'SRV',
                                        'pri' => 0,
                                        'weight' => 1,
@@ -85,4 +87,56 @@ class DnsSrvDiscovererTest extends PHPUnit_Framework_TestCase {
                        ],
                ];
        }
+
+       public function testRemoveServer() {
+               $dsd = new DnsSrvDiscoverer( 'localhost' );
+
+               $servers = [
+                       [
+                               'target' => 'conf01.example.net',
+                               'port' => 35,
+                               'pri' => 2,
+                               'weight' => 1,
+                       ],
+                       [
+                               'target' => 'conf04.example.net',
+                               'port' => 74,
+                               'pri' => 2,
+                               'weight' => 1,
+                       ],
+                       [
+                               'target' => 'conf05.example.net',
+                               'port' => 77,
+                               'pri' => 3,
+                               'weight' => 1,
+                       ],
+               ];
+               $server = $servers[1];
+
+               $expected = [
+                       [
+                               'target' => 'conf01.example.net',
+                               'port' => 35,
+                               'pri' => 2,
+                               'weight' => 1,
+                       ],
+                       [
+                               'target' => 'conf05.example.net',
+                               'port' => 77,
+                               'pri' => 3,
+                               'weight' => 1,
+                       ],
+               ];
+
+               $this->assertEquals(
+                       $expected,
+                       $dsd->removeServer( $server, $servers ),
+                       "Correct server removed"
+               );
+               $this->assertEquals(
+                       $expected,
+                       $dsd->removeServer( $server, $servers ),
+                       "Nothing to remove"
+               );
+       }
 }