Skip to content

Commit 6b7af38

Browse files
committed
Added XPack YAML tests in RunnerTest
1 parent 84c4ebb commit 6b7af38

File tree

1 file changed

+67
-28
lines changed

1 file changed

+67
-28
lines changed

tests/Elasticsearch/Tests/YamlRunnerTest.php

Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class YamlRunnerTest extends \PHPUnit\Framework\TestCase
6262
* @var string[] A list of supported features
6363
*/
6464
private static $supportedFeatures = [
65-
'stash_in_path', 'warnings', 'headers', 'contains'
65+
'stash_in_path', 'warnings', 'headers', 'contains', 'catch_unauthorized'
6666
];
6767

6868
/**
@@ -92,13 +92,44 @@ class YamlRunnerTest extends \PHPUnit\Framework\TestCase
9292
*/
9393
private static $skippedTestsIfPhpLessThan = [
9494
];
95+
9596
/**
9697
* @var array A list of skipped test with their reasons
9798
*/
9899
private static $skippedFiles = [
99100
'cat.nodeattrs/10_basic.yml' => 'Using java regex fails in PHP',
100101
'cat.repositories/10_basic.yml' => 'Using java regex fails in PHP',
101-
'indices.rollover/10_basic.yml' => 'Rollover test seems buggy atm'
102+
'indices.rollover/10_basic.yml' => 'Rollover test seems buggy atm',
103+
# Xpack
104+
'ml/*' => 'Skipped all tests',
105+
'security/*' => 'Skipped all tests',
106+
'rollup/*' => 'Skipped all tests',
107+
'async_search/*' => 'Skipped all tests',
108+
'transform/*' => 'Skipped all tests',
109+
'ssl/*' => 'Skipped all tests',
110+
'users/*' => 'Skipped all tests',
111+
'api_key/*' => 'Skipped all tests',
112+
'data_science/*' => 'Skipped all tests',
113+
'change_password/*' => 'Skipped all tests',
114+
'token/*' => 'Skipped all tests',
115+
'license/*' => 'Skipped all tests',
116+
'deprecation/*' => 'Skipped all tests',
117+
'analytics/*' => 'Skipped all tests',
118+
'vectors/*' => 'Skipped all tests',
119+
'authenticate/*' => 'Skipped all tests',
120+
'set_security_user/*' => 'Skipped all tests',
121+
'xpack/*' => 'Skipped all tests',
122+
'graph/*' => 'Skipped all tests',
123+
'roles/*' => 'Skipped all tests',
124+
'sql/sql.yml' => 'Unknown index [test]',
125+
'searchable_snapshots/10_usage.yml' => 'Expected [true] does not match [false]',
126+
'role_mapping/30_delete.yml' => 'Missing404Exception',
127+
'role_mapping/20_get_missing.yml' => 'Array to string conversion',
128+
'roles/20_get_missing.yml' => 'Array to string conversion',
129+
'wildcard/10_wildcard_basic.yml' => 'Number mismatch',
130+
'privileges/11_builtin.yml' => 'Count mismatch',
131+
'constant_keyword/10_basic.yml' => 'Count mismatch',
132+
'flattened/20_flattened_stats.yml' => 'Setup issue. Risky error'
102133
];
103134

104135
/**
@@ -108,7 +139,14 @@ class YamlRunnerTest extends \PHPUnit\Framework\TestCase
108139
'search/110_field_collapsing.yml' => 'Temporary: parse error, malformed inline yaml',
109140
'search/190_index_prefix_search.yml' => 'bad yaml array syntax',
110141
'search.aggregation/230_composite.yml' => 'bad yaml array syntax',
111-
'nodes.reload_secure_settings/10_basic.yml' => 'Malformed inline YAML string'
142+
'nodes.reload_secure_settings/10_basic.yml' => 'Malformed inline YAML string',
143+
# XPack
144+
'privileges/40_get_user_privs.yml' => 'Malformed inline YAML string',
145+
'privileges/20_has_application_privs.yml' => 'Malformed inline YAML string',
146+
'privileges/30_superuser.yml' => 'Malformed inline YAML string',
147+
'ml/jobs_crud.yml' => 'Malformed inline YAML string',
148+
'ml/custom_all_field.yml' => 'Malformed inline YAML string',
149+
'ml/data_frame_analytics_crud.yml' => 'Malformed inline YAML string',
112150
];
113151

114152
/**
@@ -175,6 +213,14 @@ public function testIntegration($testProcedure, bool $skip, $setupProcedure, $te
175213
if (array_key_exists($fileName, static::$skippedFiles)) {
176214
static::markTestSkipped(static::$skippedFiles[$fileName]);
177215
}
216+
// Check for wildchar in folder/* skippedFiles
217+
$posSlash = strpos($fileName, '/');
218+
if (false !== $posSlash) {
219+
$folder = substr($fileName, 0, $posSlash);
220+
if (isset(static::$skippedFiles[$folder . '/*'])) {
221+
static::markTestSkipped(static::$skippedFiles[$folder . '/*']);
222+
}
223+
}
178224

179225
if (null !== $setupProcedure) {
180226
$this->processProcedure(current($setupProcedure), 'setup', $fileName);
@@ -595,7 +641,6 @@ public function operationMatch($operation, $lastOperationResult, &$context, stri
595641
$match = $this->resolveValue($lastOperationResult, $key, $context);
596642
}
597643
}
598-
599644
// Special cases for responses
600645
// @todo We need to investigate more about this behaviour
601646
switch ($testName) {
@@ -763,25 +808,17 @@ public function operationSkip($operation, $lastOperationResult, string $testName
763808
if (isset($version[0]) && $version[0] == 'all') {
764809
static::markTestSkipped(sprintf('Skip test "%s", as all versions should be skipped (%s)', $testName, $operation->reason));
765810
}
766-
if (isset($version[0]) && !empty($version[0])) {
767-
if (version_compare(static::$esVersion, $version[0], '<')) {
768-
static::markTestSkipped(sprintf(
769-
"Skip test %s, as ES version %s should be skipped (%s)",
770-
$testName,
771-
static::$esVersion,
772-
$operation->reason
773-
));
774-
}
811+
if (empty($version[0])) {
812+
$version[0] = '0';
775813
}
776-
if (isset($version[1]) && !empty($version[1])) {
777-
if (version_compare(static::$esVersion, $version[1], '>')) {
778-
static::markTestSkipped(sprintf(
779-
"Skip test %s, as ES version %s should be skipped (%s)",
780-
$testName,
781-
static::$esVersion,
782-
$operation->reason
783-
));
784-
}
814+
if (version_compare(static::$esVersion, $version[0], '>=') &&
815+
version_compare(static::$esVersion, $version[1], '<=')) {
816+
static::markTestSkipped(sprintf(
817+
"Skip test %s, as ES version %s should be skipped (%s)",
818+
$testName,
819+
static::$esVersion,
820+
$operation->reason
821+
));
785822
}
786823
}
787824

@@ -801,8 +838,12 @@ public function operationContains($operation, $lastOperationResult, &$context, s
801838
$value = $this->resolveValue($lastOperationResult, key($operation), $context);
802839
$expected = current($operation);
803840

804-
$this->assertContains($expected, $value, 'Failed to contains in test ' . $testName);
805-
841+
if (is_array($expected)) {
842+
$this->assertContains($expected, $value, 'Failed to contains in test ' . $testName);
843+
} else {
844+
845+
}
846+
806847
return $lastOperationResult;
807848
}
808849

@@ -821,7 +862,7 @@ private function assertException(\Exception $exception, string $expectedError, s
821862
$this->assertRegExp($expectedError, $exception->getMessage(), 'Failed to catch error in test ' . $testName);
822863
} elseif ($exception instanceof BadRequest400Exception && $expectedError === 'bad_request') {
823864
$this->assertTrue(true);
824-
} elseif ($exception instanceof Unauthorized401Exception && $expectedError === 'unauthorized') {
865+
} elseif (false !== strpos($exception->getMessage(), '"status":401') && $expectedError === 'unauthorized') {
825866
$this->assertTrue(true);
826867
} elseif ($exception instanceof Missing404Exception && $expectedError === 'missing') {
827868
$this->assertTrue(true);
@@ -966,7 +1007,7 @@ private function resolveValue($result, $field, array &$context)
9661007
return $value;
9671008
}
9681009

969-
if (!array_key_exists($key, $value)) {
1010+
if (strpos($key, '$') !== 0 && !array_key_exists($key, $value)) {
9701011
return false;
9711012
}
9721013

@@ -1026,7 +1067,6 @@ function ($item) {
10261067
echo "Skipping: $fileName. ".static::$fatalFiles[$fileName]."\n";
10271068
return [];
10281069
}
1029-
10301070
if (null !== $filter && !preg_match('/'.preg_quote($filter, '/').'/', $fileName)) {
10311071
return [];
10321072
}
@@ -1091,7 +1131,6 @@ function ($item) {
10911131
$documentsParsed[] = [$documentParsed, $skip || $setupSkip, $setup, $teardown, $fileName];
10921132
}
10931133
}
1094-
10951134
return $documentsParsed;
10961135
}
10971136

0 commit comments

Comments
 (0)