Skip to content

Commit 152027d

Browse files
authored
Migrate integration tests to built JS files (#2750) (#2781)
1 parent 60af770 commit 152027d

File tree

12 files changed

+631
-1751
lines changed

12 files changed

+631
-1751
lines changed

.buildkite/pipeline.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
---
2+
agents:
3+
provider: "gcp"
4+
image: family/core-ubuntu-2204
5+
memory: "8G"
6+
cpu: "2"
7+
28
steps:
3-
- label: ":elasticsearch: :javascript: ES JavaScript ({{ matrix.nodejs }}) Test Suite: {{ matrix.suite }}"
4-
agents:
5-
provider: "gcp"
9+
- label: ":elasticsearch: :javascript: ES JavaScript ({{ matrix.nodejs }})"
610
env:
711
NODE_VERSION: "{{ matrix.nodejs }}"
8-
TEST_SUITE: "{{ matrix.suite }}"
9-
STACK_VERSION: 8.16.0
12+
TEST_SUITE: "platinum"
13+
STACK_VERSION: 9.0.0
14+
GITHUB_TOKEN_PATH: "secret/ci/elastic-elasticsearch-js/github-token"
15+
TEST_ES_STACK: "1"
1016
matrix:
1117
setup:
12-
suite:
13-
- "free"
14-
- "platinum"
1518
nodejs:
1619
- "18"
1720
- "20"
@@ -21,9 +24,6 @@ steps:
2124
- wait: ~
2225
continue_on_failure: true
2326
- label: ":junit: Test results"
24-
agents:
25-
provider: "gcp"
26-
image: family/core-ubuntu-2204
2727
plugins:
2828
- junit-annotate#v2.6.0:
2929
artifacts: "junit-output/junit-*.xml"

.buildkite/run-client.sh

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,29 @@ export NODE_VERSION=${NODE_VERSION:-18}
1010

1111
echo "--- :javascript: Building Docker image"
1212
docker build \
13-
--file "$script_path/Dockerfile" \
14-
--tag elastic/elasticsearch-js \
15-
--build-arg NODE_VERSION="$NODE_VERSION" \
16-
.
13+
--file "$script_path/Dockerfile" \
14+
--tag elastic/elasticsearch-js \
15+
--build-arg NODE_VERSION="$NODE_VERSION" \
16+
.
1717

18-
echo "--- :javascript: Running $TEST_SUITE tests"
18+
GITHUB_TOKEN=$(vault read -field=token "$GITHUB_TOKEN_PATH")
19+
export GITHUB_TOKEN
20+
21+
echo "--- :javascript: Running tests"
1922
mkdir -p "$repo/junit-output"
2023
docker run \
21-
--network="${network_name}" \
22-
--env "TEST_ES_SERVER=${elasticsearch_url}" \
23-
--env "ELASTIC_PASSWORD=${elastic_password}" \
24-
--env "TEST_SUITE=${TEST_SUITE}" \
25-
--env "ELASTIC_USER=elastic" \
26-
--env "BUILDKITE=true" \
27-
--volume "$repo/junit-output:/junit-output" \
28-
--name elasticsearch-js \
29-
--rm \
30-
elastic/elasticsearch-js \
31-
bash -c "npm run test:integration; [ -f ./$TEST_SUITE-report-junit.xml ] && mv ./$TEST_SUITE-report-junit.xml /junit-output/junit-$BUILDKITE_JOB_ID.xml || echo 'No JUnit artifact found'"
24+
--network="${network_name}" \
25+
--env TEST_ES_STACK \
26+
--env STACK_VERSION \
27+
--env GITHUB_TOKEN \
28+
--env "TEST_ES_SERVER=${elasticsearch_url}" \
29+
--env "ELASTIC_PASSWORD=${elastic_password}" \
30+
--env "ELASTIC_USER=elastic" \
31+
--env "BUILDKITE=true" \
32+
--volume "/usr/src/app/node_modules" \
33+
--volume "$repo:/usr/src/app" \
34+
--volume "$repo/junit-output:/junit-output" \
35+
--name elasticsearch-js \
36+
--rm \
37+
elastic/elasticsearch-js \
38+
bash -c "npm run test:integration; [ -f ./report-junit.xml ] && mv ./report-junit.xml /junit-output/junit-$BUILDKITE_JOB_ID.xml || echo 'No JUnit artifact found'"

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ elasticsearch
66
lib
77
junit-output
88
.tap
9+
rest-api-spec
10+
yaml-rest-tests
11+
generated-tests

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@ bun.lockb
6868
test-results
6969
processinfo
7070
.tap
71+
rest-api-spec
72+
yaml-rest-tests
73+
generated-tests
74+
schema

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,6 @@ CONTRIBUTING.md
7474
src
7575
bun.lockb
7676
.tap
77+
rest-api-spec
78+
yaml-rest-tests
79+
generated-tests

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"test:coverage-100": "npm run build && tap --coverage --100",
1919
"test:coverage-report": "npm run build && tap --coverage && nyc report --reporter=text-lcov > coverage.lcov",
2020
"test:coverage-ui": "npm run build && tap --coverage --coverage-report=html",
21-
"test:integration": "tsc && node test/integration/index.js",
21+
"test:integration-build": "npm run build && node test/integration/index.js",
22+
"test:integration": "npm run test:integration-build && env tap run --jobs=1 --reporter=junit --reporter-file=report-junit.xml generated-tests/",
2223
"lint": "ts-standard src",
2324
"lint:fix": "ts-standard --fix src",
2425
"license-checker": "license-checker --production --onlyAllow='MIT;Apache-2.0;Apache1.1;ISC;BSD-3-Clause;BSD-2-Clause;0BSD'",
@@ -77,8 +78,8 @@
7778
"node-fetch": "2.7.0",
7879
"ora": "5.4.1",
7980
"proxy": "1.0.2",
80-
"rimraf": "3.0.2",
81-
"semver": "7.6.3",
81+
"rimraf": "5.0.10",
82+
"semver": "7.7.1",
8283
"split2": "4.2.0",
8384
"stoppable": "1.1.0",
8485
"tap": "21.0.2",

scripts/download-artifacts.js

Lines changed: 55 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -3,162 +3,102 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
'use strict'
7-
86
const { join } = require('path')
9-
const minimist = require('minimist')
107
const stream = require('stream')
118
const { promisify } = require('util')
129
const { createWriteStream, promises } = require('fs')
13-
const rimraf = require('rimraf')
10+
const { rimraf } = require('rimraf')
1411
const fetch = require('node-fetch')
1512
const crossZip = require('cross-zip')
1613
const ora = require('ora')
1714

18-
const { mkdir, writeFile } = promises
15+
const { mkdir, cp } = promises
1916
const pipeline = promisify(stream.pipeline)
2017
const unzip = promisify(crossZip.unzip)
21-
const rm = promisify(rimraf)
22-
23-
const esFolder = join(__dirname, '..', 'elasticsearch')
24-
const zipFolder = join(esFolder, 'artifacts.zip')
25-
const specFolder = join(esFolder, 'rest-api-spec', 'api')
26-
const freeTestFolder = join(esFolder, 'rest-api-spec', 'test', 'free')
27-
const xPackTestFolder = join(esFolder, 'rest-api-spec', 'test', 'platinum')
28-
const artifactInfo = join(esFolder, 'info.json')
29-
30-
async function downloadArtifacts (opts) {
31-
if (typeof opts.version !== 'string') {
32-
throw new Error('Missing version')
33-
}
3418

35-
const log = ora('Checking out spec and test').start()
19+
const testYamlFolder = join(__dirname, '..', 'yaml-rest-tests')
20+
const zipFile = join(__dirname, '..', 'elasticsearch-clients-tests.zip')
3621

37-
log.text = 'Resolving versions'
38-
let resolved
39-
try {
40-
resolved = await resolve(opts.version, opts.hash)
41-
} catch (err) {
42-
log.fail(err.message)
43-
process.exit(1)
44-
}
22+
const schemaFolder = join(__dirname, '..', 'schema')
23+
const schemaJson = join(schemaFolder, 'schema.json')
4524

46-
opts.id = opts.id || resolved.id
47-
opts.hash = opts.hash || resolved.hash
48-
opts.version = resolved.version
25+
async function downloadArtifacts (localTests, version = 'main') {
26+
const log = ora('Checking out spec and test').start()
4927

50-
const info = loadInfo()
28+
const { GITHUB_TOKEN } = process.env
5129

52-
if (info && info.version === opts.version) {
53-
if (info.hash === opts.hash && info.id === opts.id) {
54-
log.succeed('The artifact copy present locally is already up to date')
55-
return
56-
}
30+
if (version !== 'main') {
31+
version = version.split('.').slice(0, 2).join('.')
5732
}
5833

59-
log.text = 'Cleanup checkouts/elasticsearch'
60-
await rm(esFolder)
61-
await mkdir(esFolder, { recursive: true })
34+
log.text = 'Clean tests folder'
35+
await rimraf(testYamlFolder)
36+
await mkdir(testYamlFolder, { recursive: true })
6237

63-
log.text = 'Downloading artifacts'
64-
const response = await fetch(resolved.url)
65-
if (!response.ok) {
66-
log.fail(`unexpected response ${response.statusText}`)
67-
process.exit(1)
68-
}
69-
await pipeline(response.body, createWriteStream(zipFolder))
38+
log.text = `Fetch test YAML files for version ${version}`
7039

71-
log.text = 'Unzipping'
72-
await unzip(zipFolder, esFolder)
40+
if (localTests) {
41+
log.text = `Copying local tests from ${localTests}`
42+
await cp(localTests, testYamlFolder, { recursive: true })
43+
} else {
44+
if (!GITHUB_TOKEN) {
45+
log.fail("Missing required environment variable 'GITHUB_TOKEN'")
46+
process.exit(1)
47+
}
7348

74-
log.text = 'Cleanup'
75-
await rm(zipFolder)
49+
const response = await fetch(`https://api.github.com/repos/elastic/elasticsearch-clients-tests/zipball/${version}`, {
50+
headers: {
51+
Authorization: `Bearer ${GITHUB_TOKEN}`,
52+
Accept: 'application/vnd.github+json'
53+
}
54+
})
7655

77-
log.text = 'Update info'
78-
await writeFile(artifactInfo, JSON.stringify(opts), 'utf8')
56+
if (!response.ok) {
57+
log.fail(`unexpected response ${response.statusText}`)
58+
process.exit(1)
59+
}
7960

80-
log.succeed('Done')
81-
}
61+
log.text = 'Downloading tests zipball'
62+
await pipeline(response.body, createWriteStream(zipFile))
8263

83-
function loadInfo () {
84-
try {
85-
return require(artifactInfo)
86-
} catch (err) {
87-
return null
88-
}
89-
}
64+
log.text = 'Unzipping tests'
65+
await unzip(zipFile, testYamlFolder)
9066

91-
async function resolve (version, hash) {
92-
const response = await fetch(`https://artifacts-api.elastic.co/v1/versions/${version}`)
93-
if (!response.ok) {
94-
throw new Error(`unexpected response ${response.statusText}`)
67+
log.text = 'Cleanup'
68+
await rimraf(zipFile)
9569
}
9670

97-
const data = await response.json()
98-
const esBuilds = data.version.builds
99-
.filter(build => build.projects.elasticsearch != null)
100-
.map(build => {
101-
return {
102-
projects: build.projects.elasticsearch,
103-
buildId: build.build_id,
104-
date: build.start_time,
105-
version: build.version
106-
}
107-
})
108-
.sort((a, b) => {
109-
const dA = new Date(a.date)
110-
const dB = new Date(b.date)
111-
if (dA > dB) return -1
112-
if (dA < dB) return 1
113-
return 0
114-
})
71+
log.text = 'Fetching Elasticsearch specification'
72+
await rimraf(schemaFolder)
73+
await mkdir(schemaFolder, { recursive: true })
11574

116-
if (hash != null) {
117-
const build = esBuilds.find(build => build.projects.commit_hash === hash)
118-
if (!build) {
119-
throw new Error(`Can't find any build with hash '${hash}'`)
120-
}
121-
const zipKey = Object.keys(build.projects.packages).find(key => key.startsWith('rest-resources-zip-') && key.endsWith('.zip'))
122-
return {
123-
url: build.projects.packages[zipKey].url,
124-
id: build.buildId,
125-
hash: build.projects.commit_hash,
126-
version: build.version
127-
}
75+
const response = await fetch(`https://raw.githubusercontent.com/elastic/elasticsearch-specification/${version}/output/schema/schema.json`)
76+
if (!response.ok) {
77+
log.fail(`unexpected response ${response.statusText}`)
78+
process.exit(1)
12879
}
12980

130-
const lastBuild = esBuilds[0]
131-
const zipKey = Object.keys(lastBuild.projects.packages).find(key => key.startsWith('rest-resources-zip-') && key.endsWith('.zip'))
132-
return {
133-
url: lastBuild.projects.packages[zipKey].url,
134-
id: lastBuild.buildId,
135-
hash: lastBuild.projects.commit_hash,
136-
version: lastBuild.version
137-
}
81+
log.text = 'Downloading schema.json'
82+
await pipeline(response.body, createWriteStream(schemaJson))
83+
84+
log.succeed('Done')
13885
}
13986

140-
async function main (options) {
141-
delete options._
142-
await downloadArtifacts(options)
87+
async function main () {
88+
await downloadArtifacts()
14389
}
90+
14491
if (require.main === module) {
14592
process.on('unhandledRejection', function (err) {
14693
console.error(err)
14794
process.exit(1)
14895
})
14996

150-
const options = minimist(process.argv.slice(2), {
151-
string: ['id', 'version', 'hash']
152-
})
153-
main(options).catch(t => {
97+
main().catch(t => {
15498
console.log(t)
15599
process.exit(2)
156100
})
157101
}
158102

159103
module.exports = downloadArtifacts
160-
module.exports.locations = {
161-
specFolder,
162-
freeTestFolder,
163-
xPackTestFolder
164-
}
104+
module.exports.locations = { testYamlFolder, zipFile, schemaJson }

scripts/generate-docs-examples.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
const { join } = require('path')
77
const { writeFile } = require('fs/promises')
88
const fetch = require('node-fetch')
9-
const rimraf = require('rimraf')
9+
const { rimraf } = require('rimraf')
1010
const ora = require('ora')
1111
const { convertRequests } = require('@elastic/request-converter')
1212
const minimist = require('minimist')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy