Skip to content

Commit 39128d4

Browse files
committed
Reintroduce ndjson detection
1 parent ed2b8be commit 39128d4

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ node_modules
22
npm-debug.log
33
.git
44
.nyc_output
5+
lib
6+
yaml-rest-tests
7+
junit-output
8+
rest-api-spec

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ lib
6666
yaml-rest-tests
6767
cloud.json
6868
junit-output
69+
rest-api-spec

scripts/download-artifacts.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const unzip = promisify(crossZip.unzip)
3333
const testYamlFolder = join(__dirname, '..', 'yaml-rest-tests')
3434
const zipFile = join(__dirname, '..', 'serverless-clients-tests.zip')
3535

36+
const specFolder = join(__dirname, '..', 'rest-api-spec')
37+
3638
async function downloadArtifacts () {
3739
const log = ora('Checking out spec and test').start()
3840

@@ -49,7 +51,7 @@ async function downloadArtifacts () {
4951
process.exit(1)
5052
}
5153

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

75+
log.text = 'Fetching Elasticsearch spec info'
76+
await rimraf(specFolder)
77+
await mkdir(specFolder, { recursive: true })
78+
79+
response = await fetch('https://artifacts-api.elastic.co/v1/versions')
80+
let data = await response.json()
81+
const latest = data.versions[data.versions.length - 1]
82+
response = await fetch(`https://artifacts-api.elastic.co/v1/versions/${latest}`)
83+
data = await response.json()
84+
const latestBuild = data.version.builds
85+
.filter(build => build.projects.elasticsearch !== null)
86+
.sort((a, b) => new Date(b.start_time) - new Date(a.start_time))[0]
87+
88+
const buildZip = Object.keys(latestBuild.projects.elasticsearch.packages)
89+
.find(key => key.startsWith('rest-resources-zip-') && key.endsWith('.zip'))
90+
const zipUrl = latestBuild.projects.elasticsearch.packages[buildZip].url
91+
92+
log.test = 'Fetching Elasticsearch spec zip'
93+
response = await fetch(zipUrl)
94+
95+
log.text = 'Downloading spec zip'
96+
const specZipFile = join(specFolder, 'rest-api-spec.zip')
97+
await pipeline(response.body, createWriteStream(specZipFile))
98+
99+
log.text = 'Unzipping spec'
100+
await unzip(specZipFile, specFolder)
101+
102+
log.text = 'Cleanup'
103+
await rimraf(specZipFile)
104+
73105
log.succeed('Done')
74106
}
75107

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

92124
module.exports = downloadArtifacts
93-
module.exports.locations = { testYamlFolder, zipFile }
125+
module.exports.locations = { testYamlFolder, zipFile, specFolder }

test/integration/test-runner.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323

2424
const chai = require('chai')
2525
const semver = require('semver')
26+
const { join } = require('path')
27+
const fs = require('fs')
2628
const helper = require('./helper')
29+
const { locations } = require('../../scripts/download-artifacts')
2730

2831
chai.config.showDiff = true
2932
chai.config.truncateThreshold = 0
@@ -805,7 +808,10 @@ function shouldSkip (esVersion, action) {
805808
}
806809

807810
function isNDJson (api) {
808-
return false
811+
const specPath = join(locations.specFolder, 'rest-api-spec', 'api', `${api}.json`)
812+
const spec = JSON.parse(fs.readFileSync(specPath, 'utf8'))
813+
const { content_type } = spec[Object.keys(spec)[0]].headers
814+
return Boolean(content_type && content_type.includes('application/x-ndjson'))
809815
}
810816

811817
/**

0 commit comments

Comments
 (0)