-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
36 changed files
with
780 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import expect from 'expect.js'; | ||
import { dirname, resolve } from 'path'; | ||
import { writeFile, readFileSync } from 'fs'; | ||
import { fromNode as fcb, promisify } from 'bluebird'; | ||
import mkdirp from 'mkdirp'; | ||
import del from 'del'; | ||
|
||
const writeFileAsync = promisify(writeFile); | ||
|
||
export async function SnapshotsProvider({ getService }) { | ||
const log = getService('log'); | ||
const config = getService('config'); | ||
|
||
const SESSION_DIRECTORY = resolve(config.get('snapshots.directory'), 'session'); | ||
const BASELINE_DIRECTORY = resolve(config.get('snapshots.directory'), 'baseline'); | ||
await del([SESSION_DIRECTORY]); | ||
|
||
class Snapshots { | ||
|
||
/** | ||
* | ||
* @param name {string} name of the file to use for comparison | ||
* @param value {object} value to compare to baseline. | ||
* @param updateBaselines {boolean} optional, pass true to update the baseline snapshot. | ||
* @return {Promise.<number>} returns 0 if successful. | ||
*/ | ||
async compareAgainstBaseline(name, value, updateBaselines) { | ||
log.debug('compareAgainstBaseline'); | ||
const sessionPath = resolve(SESSION_DIRECTORY, `${name}.json`); | ||
await this._take(sessionPath, value); | ||
|
||
const baselinePath = resolve(BASELINE_DIRECTORY, `${name}.json`); | ||
|
||
if (updateBaselines) { | ||
await writeFileAsync(baselinePath, readFileSync(sessionPath)); | ||
return 0; | ||
} else { | ||
log.debug('comparing'); | ||
return this._compare(sessionPath, baselinePath); | ||
} | ||
} | ||
|
||
_compare(sessionPath, baselinePath) { | ||
const currentObject = readFileSync(sessionPath, { encoding: 'utf8' }); | ||
const baselineObject = readFileSync(baselinePath, { encoding: 'utf8' }); | ||
expect(currentObject).to.eql(baselineObject); | ||
return 0; | ||
} | ||
|
||
async take(name) { | ||
return await this._take(resolve(SESSION_DIRECTORY, `${name}.json`)); | ||
} | ||
|
||
async _take(path, snapshot) { | ||
try { | ||
await fcb(cb => mkdirp(dirname(path), cb)); | ||
await fcb(cb => writeFile(path, JSON.stringify(snapshot), 'utf8', cb)); | ||
} catch (err) { | ||
log.error('SNAPSHOT FAILED'); | ||
log.error(err); | ||
} | ||
} | ||
} | ||
|
||
return new Snapshots(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Interpreter Functional Tests | ||
|
||
This folder contains interpreter functional tests. | ||
|
||
Add new test suites into the `test_suites` folder and reference them from the | ||
`config.js` file. These test suites work the same as regular functional test. | ||
|
||
## Run the test | ||
|
||
To run these tests during development you can use the following commands: | ||
|
||
``` | ||
# Start the test server (can continue running) | ||
node scripts/functional_tests_server.js --config test/interpreter_functional/config.js | ||
# Start a test run | ||
node scripts/functional_test_runner.js --config test/interpreter_functional/config.js | ||
``` | ||
|
||
# Writing tests | ||
|
||
Look into test_suites/run_pipeline/basic.js for examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import path from 'path'; | ||
import fs from 'fs'; | ||
|
||
export default async function ({ readConfigFile }) { | ||
const functionalConfig = await readConfigFile(require.resolve('../functional/config')); | ||
|
||
// Find all folders in ./plugins since we treat all them as plugin folder | ||
const allFiles = fs.readdirSync(path.resolve(__dirname, 'plugins')); | ||
const plugins = allFiles.filter(file => fs.statSync(path.resolve(__dirname, 'plugins', file)).isDirectory()); | ||
|
||
return { | ||
testFiles: [ | ||
require.resolve('./test_suites/run_pipeline'), | ||
], | ||
services: functionalConfig.get('services'), | ||
pageObjects: functionalConfig.get('pageObjects'), | ||
servers: functionalConfig.get('servers'), | ||
esTestCluster: functionalConfig.get('esTestCluster'), | ||
apps: functionalConfig.get('apps'), | ||
esArchiver: { | ||
directory: path.resolve(__dirname, '../es_archives') | ||
}, | ||
screenshots: functionalConfig.get('screenshots'), | ||
snapshots: { | ||
directory: path.resolve(__dirname, 'snapshots'), | ||
}, | ||
junit: { | ||
reportName: 'Interpreter Functional Tests', | ||
}, | ||
kbnTestServer: { | ||
...functionalConfig.get('kbnTestServer'), | ||
serverArgs: [ | ||
...functionalConfig.get('kbnTestServer.serverArgs'), | ||
...plugins.map(pluginDir => `--plugin-path=${path.resolve(__dirname, 'plugins', pluginDir)}`), | ||
], | ||
}, | ||
}; | ||
} |
Oops, something went wrong.