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 )
false // retry
],
],
- '200 OK - Skip dir' => [
+ '200 OK - Empty dir' => [
'http' => [
'code' => 200,
'reason' => 'OK',
],
[
'key' => '/example/sub',
- 'dir' => true
+ 'dir' => true,
+ 'nodes' => [],
],
[
'key' => '/example/bar',
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,
],
'expect' => [
null, // data
- "Unexpected JSON response; missing 'nodes' list.",
+ "Error unserializing JSON response.",
false // retry
],
],
/**
* @covers EtcdConfig::fetchAllFromEtcdServer
* @covers EtcdConfig::unserialize
+ * @covers EtcdConfig::parseResponse
+ * @covers EtcdConfig::parseDirectory
+ * @covers EtcdConfigParseError
* @dataProvider provideFetchFromServer
*/
public function testFetchFromServer( array $httpResponse, array $expected ) {