X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fconfig%2FEtcdConfigTest.php;h=7a4d9d9f6fcf5ed596f1d39d175cb32a26c8ea82;hp=19cffa29b9702f0024ac4314934c920f534c4f10;hb=dbad540cd37617879aff6f28ce9c016dd8049d4e;hpb=fd98d9df75d1abb6cf12757058652b79f5044ea1 diff --git a/tests/phpunit/includes/config/EtcdConfigTest.php b/tests/phpunit/includes/config/EtcdConfigTest.php index 19cffa29b9..7a4d9d9f6f 100644 --- a/tests/phpunit/includes/config/EtcdConfigTest.php +++ b/tests/phpunit/includes/config/EtcdConfigTest.php @@ -2,7 +2,9 @@ use Wikimedia\TestingAccessWrapper; -class EtcConfigTest extends PHPUnit_Framework_TestCase { +class EtcdConfigTest extends PHPUnit_Framework_TestCase { + + use MediaWikiCoversValidator; private function createConfigMock( array $options = [] ) { return $this->getMockBuilder( EtcdConfig::class ) @@ -90,7 +92,7 @@ class EtcConfigTest extends PHPUnit_Framework_TestCase { */ public function testConstructCacheSpec() { $config = $this->createConfigMock( [ 'cache' => [ - 'class' => HashBagOStuff::class + 'class' => HashBagOStuff::class ] ] ); $config->expects( $this->once() )->method( 'fetchAllFromEtcd' ) ->willReturn( [ @@ -383,7 +385,7 @@ class EtcConfigTest extends PHPUnit_Framework_TestCase { false // retry ], ], - '200 OK - Skip dir' => [ + '200 OK - Empty dir' => [ 'http' => [ 'code' => 200, 'reason' => 'OK', @@ -395,7 +397,8 @@ class EtcConfigTest extends PHPUnit_Framework_TestCase { ], [ 'key' => '/example/sub', - 'dir' => true + 'dir' => true, + 'nodes' => [], ], [ 'key' => '/example/bar', @@ -410,6 +413,68 @@ class EtcConfigTest extends PHPUnit_Framework_TestCase { false // retry ], ], + '200 OK - Recursive' => [ + 'http' => [ + 'code' => 200, + 'reason' => 'OK', + 'headers' => [], + 'body' => json_encode( [ 'node' => [ 'nodes' => [ + [ + 'key' => '/example/a', + 'dir' => true, + 'nodes' => [ + [ + 'key' => 'b', + 'value' => json_encode( [ 'val' => true ] ), + ], + [ + 'key' => 'c', + 'value' => json_encode( [ 'val' => false ] ), + ], + ], + ], + ] ] ] ), + 'error' => '', + ], + 'expect' => [ + [ 'a/b' => true, 'a/c' => false ], // data + null, + false // retry + ], + ], + '200 OK - Missing nodes at second level' => [ + 'http' => [ + 'code' => 200, + 'reason' => 'OK', + 'headers' => [], + 'body' => json_encode( [ 'node' => [ 'nodes' => [ + [ + 'key' => '/example/a', + 'dir' => true, + ], + ] ] ] ), + 'error' => '', + ], + 'expect' => [ + null, + "Unexpected JSON response in dir 'a'; missing 'nodes' list.", + false // retry + ], + ], + '200 OK - Correctly encoded garbage response' => [ + 'http' => [ + 'code' => 200, + 'reason' => 'OK', + 'headers' => [], + 'body' => json_encode( [ 'foo' => 'bar' ] ), + 'error' => '', + ], + 'expect' => [ + null, + "Unexpected JSON response: Missing or invalid node at top level.", + false // retry + ], + ], '200 OK - Bad value' => [ 'http' => [ 'code' => 200, @@ -453,7 +518,7 @@ class EtcConfigTest extends PHPUnit_Framework_TestCase { ], 'expect' => [ null, // data - "Unexpected JSON response; missing 'nodes' list.", + "Error unserializing JSON response.", false // retry ], ], @@ -491,6 +556,9 @@ class EtcConfigTest extends PHPUnit_Framework_TestCase { /** * @covers EtcdConfig::fetchAllFromEtcdServer * @covers EtcdConfig::unserialize + * @covers EtcdConfig::parseResponse + * @covers EtcdConfig::parseDirectory + * @covers EtcdConfigParseError * @dataProvider provideFetchFromServer */ public function testFetchFromServer( array $httpResponse, array $expected ) {