Skip to content

Commit d19313a

Browse files
committed
Update integration test runner (#1085)
* Improved user and roles handling * Avoid deleting internal indices * Updated skip version handling * Fix leftover * Improved indices and aliases cleanup * Clean also internal indices * Restore previous index/alias cleanup * Ignore 404
1 parent 874b04f commit d19313a

File tree

2 files changed

+23
-64
lines changed

2 files changed

+23
-64
lines changed

test/integration/helper.js

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,6 @@
44

55
'use strict'
66

7-
const esDefaultRoles = [
8-
'apm_system',
9-
'apm_user',
10-
'beats_admin',
11-
'beats_system',
12-
'code_admin',
13-
'code_user',
14-
'data_frame_transforms_admin',
15-
'data_frame_transforms_user',
16-
'enrich_user',
17-
'ingest_admin',
18-
'kibana_dashboard_only_user',
19-
'kibana_system',
20-
'kibana_user',
21-
'logstash_admin',
22-
'logstash_system',
23-
'machine_learning_admin',
24-
'machine_learning_user',
25-
'monitoring_user',
26-
'remote_monitoring_agent',
27-
'remote_monitoring_collector',
28-
'reporting_user',
29-
'rollup_admin',
30-
'rollup_user',
31-
'snapshot_user',
32-
'superuser',
33-
'transform_admin',
34-
'transform_user',
35-
'transport_client',
36-
'watcher_admin',
37-
'watcher_user'
38-
]
39-
40-
const esDefaultUsers = [
41-
'apm_system',
42-
'beats_system',
43-
'elastic',
44-
'logstash_system',
45-
'kibana',
46-
'remote_monitoring_user'
47-
]
48-
497
function runInParallel (client, operation, options, clientOptions) {
508
if (options.length === 0) return Promise.resolve()
519
const operations = options.map(opts => {
@@ -76,4 +34,4 @@ function to (promise) {
7634

7735
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
7836

79-
module.exports = { runInParallel, esDefaultRoles, esDefaultUsers, delve, to, sleep }
37+
module.exports = { runInParallel, delve, to, sleep }

test/integration/test-runner.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,19 @@ function build (opts = {}) {
3838
* @returns {Promise}
3939
*/
4040
async function cleanup () {
41-
// // tap.comment('Cleanup')
42-
4341
response = null
4442
stash.clear()
4543

4644
try {
47-
await client.indices.delete({ index: '_all' }, { ignore: 404 })
45+
await client.indices.deleteAlias({ index: '_all', name: '_all' }, { ignore: 404 })
4846
} catch (err) {
49-
assert.ifError(err, 'should not error: indices.delete')
47+
assert.ifError(err, 'should not error: indices.deleteAlias')
5048
}
5149

5250
try {
53-
await client.indices.deleteAlias({ index: '_all', name: '_all' }, { ignore: 404 })
51+
await client.indices.delete({ index: '_all' }, { ignore: 404 })
5452
} catch (err) {
55-
assert.ifError(err, 'should not error: indices.deleteAlias')
53+
assert.ifError(err, 'should not error: indices.delete')
5654
}
5755

5856
try {
@@ -91,7 +89,7 @@ function build (opts = {}) {
9189

9290
try {
9391
const { body } = await client.security.getRole()
94-
const roles = Object.keys(body).filter(n => helper.esDefaultRoles.indexOf(n) === -1)
92+
const roles = Object.keys(body).filter(n => !body[n].metadata._reserved)
9593
await helper.runInParallel(
9694
client, 'security.deleteRole',
9795
roles.map(r => ({ name: r }))
@@ -102,7 +100,7 @@ function build (opts = {}) {
102100

103101
try {
104102
const { body } = await client.security.getUser()
105-
const users = Object.keys(body).filter(n => helper.esDefaultUsers.indexOf(n) === -1)
103+
const users = Object.keys(body).filter(n => !body[n].metadata._reserved)
106104
await helper.runInParallel(
107105
client, 'security.deleteUser',
108106
users.map(r => ({ username: r }))
@@ -836,19 +834,22 @@ function shouldSkip (esVersion, action) {
836834
// skip based on the version
837835
if (action.version) {
838836
if (action.version.trim() === 'all') return true
839-
const [min, max] = action.version.split('-').map(v => v.trim())
840-
// if both `min` and `max` are specified
841-
if (min && max) {
842-
shouldSkip = semver.satisfies(esVersion, action.version)
843-
// if only `min` is specified
844-
} else if (min) {
845-
shouldSkip = semver.gte(esVersion, min)
846-
// if only `max` is specified
847-
} else if (max) {
848-
shouldSkip = semver.lte(esVersion, max)
849-
// something went wrong!
850-
} else {
851-
throw new Error(`skip: Bad version range: ${action.version}`)
837+
const versions = action.version.split(',').filter(Boolean)
838+
for (const version of versions) {
839+
const [min, max] = version.split('-').map(v => v.trim())
840+
// if both `min` and `max` are specified
841+
if (min && max) {
842+
shouldSkip = semver.satisfies(esVersion, action.version)
843+
// if only `min` is specified
844+
} else if (min) {
845+
shouldSkip = semver.gte(esVersion, min)
846+
// if only `max` is specified
847+
} else if (max) {
848+
shouldSkip = semver.lte(esVersion, max)
849+
// something went wrong!
850+
} else {
851+
throw new Error(`skip: Bad version range: ${action.version}`)
852+
}
852853
}
853854
}
854855

0 commit comments

Comments
 (0)