X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fconfig%2FEtcdConfigTest.php;h=3e70a07819b6c6bd54b44d0d3f6861c33b24d5fb;hb=64a38b3b854607498ea49342b68e9c44a0ea1390;hp=c13cf2517c2e98d3e5b35a7b9a44c478fc9f3024;hpb=20b0288ac360d791bd2af16586f91f62711c8a37;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/config/EtcdConfigTest.php b/tests/phpunit/includes/config/EtcdConfigTest.php index c13cf2517c..3e70a07819 100644 --- a/tests/phpunit/includes/config/EtcdConfigTest.php +++ b/tests/phpunit/includes/config/EtcdConfigTest.php @@ -2,7 +2,7 @@ use Wikimedia\TestingAccessWrapper; -class EtcConfigTest extends PHPUnit_Framework_TestCase { +class EtcdConfigTest extends PHPUnit_Framework_TestCase { private function createConfigMock( array $options = [] ) { return $this->getMockBuilder( EtcdConfig::class ) @@ -383,7 +383,7 @@ class EtcConfigTest extends PHPUnit_Framework_TestCase { false // retry ], ], - '200 OK - Skip dir' => [ + '200 OK - Empty dir' => [ 'http' => [ 'code' => 200, 'reason' => 'OK', @@ -395,7 +395,8 @@ class EtcConfigTest extends PHPUnit_Framework_TestCase { ], [ 'key' => '/example/sub', - 'dir' => true + 'dir' => true, + 'nodes' => [], ], [ 'key' => '/example/bar', @@ -410,6 +411,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 +516,7 @@ class EtcConfigTest extends PHPUnit_Framework_TestCase { ], 'expect' => [ null, // data - "Unexpected JSON response; missing 'nodes' list.", + "Error unserializing JSON response.", false // retry ], ], @@ -491,6 +554,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 ) {