Updated test
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('assert')
|
||||
const { readFileSync, accessSync, mkdirSync, readdirSync } = require('fs')
|
||||
const { join } = require('path')
|
||||
const { readFileSync, accessSync, mkdirSync, readdirSync, statSync } = require('fs')
|
||||
const { join, sep } = require('path')
|
||||
const yaml = require('js-yaml')
|
||||
const Git = require('simple-git')
|
||||
const ora = require('ora')
|
||||
@ -14,6 +14,7 @@ const TestRunner = require('./test-runner')
|
||||
const esRepo = 'https://github.com/elastic/elasticsearch.git'
|
||||
const esFolder = join(__dirname, '..', '..', 'elasticsearch')
|
||||
const yamlFolder = join(esFolder, 'rest-api-spec', 'src', 'main', 'resources', 'rest-api-spec', 'test')
|
||||
// const xPackYamlFolder = join(esFolder, 'x-pack', 'plugin', 'src', 'test', 'resources', 'rest-api-spec', 'test')
|
||||
|
||||
function Runner (opts) {
|
||||
if (!(this instanceof Runner)) {
|
||||
@ -33,7 +34,6 @@ function Runner (opts) {
|
||||
* Runs the test suite
|
||||
*/
|
||||
Runner.prototype.start = function () {
|
||||
const getTest = this.getTest.bind(this)
|
||||
const parse = this.parse.bind(this)
|
||||
const client = this.client
|
||||
|
||||
@ -51,57 +51,58 @@ Runner.prototype.start = function () {
|
||||
return
|
||||
}
|
||||
const { number: version, build_hash: sha } = body.version
|
||||
|
||||
// Set the repository to the given sha and run the test suite
|
||||
this.withSHA(sha, () => {
|
||||
this.log.succeed('Done!')
|
||||
runTest.call(this, version)
|
||||
})
|
||||
|
||||
// client.xpack.license.postStartTrial({ acknowledge: true }, (err, { body }) => {
|
||||
// if (err) {
|
||||
// this.log.fail(err.message)
|
||||
// return
|
||||
// }
|
||||
// })
|
||||
})
|
||||
|
||||
function runTest (version) {
|
||||
const testFolders = getTest()
|
||||
testFolders.forEach(runTestFolder.bind(this))
|
||||
function runTestFolder (testFolder) {
|
||||
// if (testFolder !== 'tasks.get') return
|
||||
const files = []
|
||||
.concat(getAllFiles(yamlFolder))
|
||||
// .concat(getAllFiles(xPackYamlFolder))
|
||||
.filter(t => !/(README|TODO)/g.test(t))
|
||||
|
||||
files.forEach(runTestFile.bind(this))
|
||||
function runTestFile (file) {
|
||||
// create a subtest for the specific folder
|
||||
tap.test(testFolder, { jobs: 1 }, tap1 => {
|
||||
const files = getTest(testFolder)
|
||||
files.forEach(file => {
|
||||
// if (file !== '20_typed_keys.yml') return
|
||||
// create a subtest for the specific folder + test file
|
||||
tap1.test(file.slice(0, -4), { jobs: 1 }, tap2 => {
|
||||
const path = join(yamlFolder, testFolder, file)
|
||||
// read the yaml file
|
||||
const data = readFileSync(path, 'utf8')
|
||||
// get the test yaml (as object), some file has multiple yaml documents inside,
|
||||
// every document is separated by '---', so we split on the separator
|
||||
// and then we remove the empty strings, finally we parse them
|
||||
const tests = data
|
||||
.split('---')
|
||||
.map(s => s.trim())
|
||||
.filter(Boolean)
|
||||
.map(parse)
|
||||
tap.test(file.slice(file.indexOf(`${sep}elasticsearch${sep}`)), { jobs: 1 }, tap1 => {
|
||||
// read the yaml file
|
||||
const data = readFileSync(file, 'utf8')
|
||||
// get the test yaml (as object), some file has multiple yaml documents inside,
|
||||
// every document is separated by '---', so we split on the separator
|
||||
// and then we remove the empty strings, finally we parse them
|
||||
const tests = data
|
||||
.split('---')
|
||||
.map(s => s.trim())
|
||||
.filter(Boolean)
|
||||
.map(parse)
|
||||
|
||||
// get setup and teardown if present
|
||||
var setupTest = null
|
||||
var teardownTest = null
|
||||
tests.forEach(test => {
|
||||
if (test.setup) setupTest = test.setup
|
||||
if (test.teardown) teardownTest = test.teardown
|
||||
})
|
||||
// get setup and teardown if present
|
||||
var setupTest = null
|
||||
var teardownTest = null
|
||||
tests.forEach(test => {
|
||||
if (test.setup) setupTest = test.setup
|
||||
if (test.teardown) teardownTest = test.teardown
|
||||
})
|
||||
|
||||
// run the tests
|
||||
tests.forEach(test => {
|
||||
const name = Object.keys(test)[0]
|
||||
if (name === 'setup' || name === 'teardown') return
|
||||
// create a subtest for the specific folder + test file + test name
|
||||
tap2.test(name, { jobs: 1, bail: this.bailout }, tap3 => {
|
||||
const testRunner = TestRunner({ client, version, tap: tap3 })
|
||||
testRunner.run(setupTest, test[name], teardownTest, () => tap3.end())
|
||||
})
|
||||
})
|
||||
|
||||
tap2.end()
|
||||
// run the tests
|
||||
tests.forEach(test => {
|
||||
const name = Object.keys(test)[0]
|
||||
if (name === 'setup' || name === 'teardown') return
|
||||
// create a subtest for the specific folder + test file + test name
|
||||
tap1.test(name, { jobs: 1, bail: this.bailout }, tap2 => {
|
||||
const testRunner = TestRunner({ client, version, tap: tap2 })
|
||||
testRunner.run(setupTest, test[name], teardownTest, () => tap2.end())
|
||||
})
|
||||
})
|
||||
|
||||
@ -127,14 +128,12 @@ Runner.prototype.parse = function (data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content of the `yamlFolder`.
|
||||
* If a folder name is given as parameter, it will return
|
||||
* the content of join(yamlFolder, folder)
|
||||
* Returns the filtered content of a given folder
|
||||
* @param {string} folder
|
||||
* @returns {Array} The content of the given folder
|
||||
*/
|
||||
Runner.prototype.getTest = function (folder) {
|
||||
const tests = readdirSync(join(yamlFolder, folder || ''))
|
||||
const tests = readdirSync(folder)
|
||||
return tests.filter(t => !/(README|TODO)/g.test(t))
|
||||
}
|
||||
|
||||
@ -238,6 +237,7 @@ if (require.main === module) {
|
||||
string: ['host', 'version'],
|
||||
boolean: ['bailout'],
|
||||
default: {
|
||||
// host: 'http://elastic:passw0rd@localhost:9200',
|
||||
host: 'http://localhost:9200',
|
||||
version: '6.4',
|
||||
bailout: false
|
||||
@ -248,4 +248,11 @@ if (require.main === module) {
|
||||
runner.start()
|
||||
}
|
||||
|
||||
const getAllFiles = dir =>
|
||||
readdirSync(dir).reduce((files, file) => {
|
||||
const name = join(dir, file)
|
||||
const isDirectory = statSync(name).isDirectory()
|
||||
return isDirectory ? [...files, ...getAllFiles(name)] : [...files, name]
|
||||
}, [])
|
||||
|
||||
module.exports = Runner
|
||||
|
||||
Reference in New Issue
Block a user