diff --git a/.changes/nextrelease/endpoints-tests.json b/.changes/nextrelease/endpoints-tests.json new file mode 100644 index 0000000000..ca830e40a4 --- /dev/null +++ b/.changes/nextrelease/endpoints-tests.json @@ -0,0 +1,7 @@ +[ + { + "type": "enhancement", + "category": "EndpointV2", + "description": "Adds terminal failure if endpoints file cannot be found" + } +] \ No newline at end of file diff --git a/src/EndpointV2/EndpointDefinitionProvider.php b/src/EndpointV2/EndpointDefinitionProvider.php index aee14b5eee..6da2685cea 100644 --- a/src/EndpointV2/EndpointDefinitionProvider.php +++ b/src/EndpointV2/EndpointDefinitionProvider.php @@ -8,14 +8,14 @@ */ class EndpointDefinitionProvider { - public static function getEndpointRuleset($service, $apiVersion) + public static function getEndpointRuleset($service, $apiVersion, $baseDir = null) { - return self::getData($service, $apiVersion, 'ruleset'); + return self::getData($service, $apiVersion, 'ruleset', $baseDir); } - public static function getEndpointTests($service, $apiVersion) + public static function getEndpointTests($service, $apiVersion, $baseDir = null) { - return self::getData($service, $apiVersion, 'tests'); + return self::getData($service, $apiVersion, 'tests', $baseDir); } public static function getPartitions() @@ -30,9 +30,9 @@ public static function getPartitions() } } - private static function getData($service, $apiVersion, $type) + private static function getData($service, $apiVersion, $type, $baseDir) { - $basePath = __DIR__ . '/../data'; + $basePath = $baseDir ? $baseDir : __DIR__ . '/../data'; $serviceDir = $basePath . "/{$service}"; if (!is_dir($serviceDir)) { throw new \InvalidArgumentException( @@ -54,8 +54,12 @@ private static function getData($service, $apiVersion, $type) if (file_exists($rulesetPath . $fileName . '.json.php')) { return require($rulesetPath . $fileName . '.json.php'); - } else { + } elseif (file_exists($rulesetPath . $fileName . '.json')) { return json_decode(file_get_contents($rulesetPath . $fileName . '.json'), true); + } else { + throw new \InvalidArgumentException( + 'Specified ' . $type . ' endpoint file for ' . $service . ' with api version ' . $apiVersion . ' does not exist.' + ); } } diff --git a/tests/EndpointV2/EndpointDefinitionProviderTest.php b/tests/EndpointV2/EndpointDefinitionProviderTest.php index 359d604dad..953099bc36 100644 --- a/tests/EndpointV2/EndpointDefinitionProviderTest.php +++ b/tests/EndpointV2/EndpointDefinitionProviderTest.php @@ -45,4 +45,33 @@ public function testThrowsExceptionOnInvalidApiVersion() $this->expectExceptionMessage('Invalid api version.'); EndpointDefinitionProvider::getEndpointRuleset('s3', '10-22-2022'); } + + public function getEndpointFileProvider() + { + return [ + ['Ruleset'], + ['Tests'] + ]; + } + + /** + * @dataProvider getEndpointFileProvider + * + * @param $type + */ + public function testThrowsExceptionOnMissingFiles($type) + { + $method = 'getEndpoint' . $type; + $type = strtolower($type); + $tmpdir = sys_get_temp_dir(); + if (!is_dir($tmpdir . '/data/foo-service/08-05-1989/')) { + mkdir($tmpdir . '/data/foo-service/08-05-1989/', 0777, true); + } + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("Specified {$type} endpoint file for foo-service with api version 08-05-1989 does not exist."); + EndpointDefinitionProvider::$method('foo-service', '08-05-1989', $tmpdir . '/data'); + rmdir($tmpdir . 'data/' . 's3/' . '/08-05-1989'); + rmdir($tmpdir . 'data/' . 's3/'); + rmdir($tmpdir . 'data'); + } } \ No newline at end of file