Add functional tests for devstack gate

This patch adds 'functional' tests that will be run by DSVM gate.
A 'cloudsConfig.js' file reads 'clouds.yaml' and converts it to json.
'clouds.yaml' file is searched from the following locations:
 - current directory
 - ~/.config/openstack
 - /etc/openstack
The first file found wins.

For browser, webpack uses a 'yaml' loader and rewrites
'helper/cloudsConfig.js' requirement to 'json!yaml!clouds.yaml'.

A dummy test has been added to demonstrate use of devstack config.

Change-Id: I55909862c70a4cbe22b2820e51c2969d68d8154a
This commit is contained in:
Corentin Ardeois 2016-07-21 12:09:17 -04:00
parent 4e9cf48b43
commit bf8deba64e
9 changed files with 98 additions and 10 deletions

View File

@ -9,7 +9,7 @@ reporting:
reports:
- lcov
- html
dir: ./cover/node
dir: ./cover/unit/node
watermarks:
statements: [50, 90]
lines: [50, 90]

View File

@ -1,10 +1,14 @@
import webpackConfig from './webpack.config.babel';
import path from 'path';
export default (config) => {
// test mode based on basePath parameter (eg. test/unit, test/functional)
const testDir = config.basePath ? path.basename(config.basePath) : 'unit';
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
basePath: 'test/' + testDir,
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
@ -12,16 +16,18 @@ export default (config) => {
// list of files / patterns to load in the browser
files: [
'test/unit/**/*.js'
'**/*.js'
],
// list of files to exclude
exclude: [],
exclude: [
'helpers/**/*.js'
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'test/unit/**/*.js': ['webpack']
'**/*.js': ['webpack']
},
// test results reporter to use
@ -64,7 +70,7 @@ export default (config) => {
// Generate a coverage report in /cover/karma
coverageReporter: {
type: 'html', //produces a html document after code is run
dir: 'cover/browser/' //path to created html doc
dir: '../../cover/' + testDir + '/browser/' //path to created html doc
},
// The current coverage threshold values. These should never drop.

View File

@ -8,6 +8,9 @@
"test:node": "istanbul cover jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
"test:browser": "karma start",
"posttest:node": "istanbul check-coverage",
"functional-test": "npm run functional-test:node ; npm run functional-test:browser",
"functional-test:node": "istanbul cover --dir cover/functional/node jasmine JASMINE_CONFIG_PATH=test/functional/jasmine.json",
"functional-test:browser": "karma start --basePath test/functional/",
"lint": "eslint ./",
"prepublish": "nsp check; npm run build",
"build": "babel src -d dist && webpack",
@ -32,6 +35,7 @@
"babel-cli": "^6.10.1",
"babel-core": "^6.10.4",
"babel-loader": "^6.2.4",
"babel-plugin-transform-inline-environment-variables": "^6.8.0",
"babel-preset-es2015": "^6.9.0",
"babel-register": "^6.9.0",
"eslint": "^2.4.0",
@ -39,6 +43,8 @@
"fetch-mock": "^5.0.5",
"istanbul": "^1.0.0-alpha.2",
"jasmine": "^2.4.1",
"js-yaml": "^3.6.1",
"json-loader": "^0.5.4",
"karma": "^1.1.1",
"karma-chrome-launcher": "^1.0.1",
"karma-coverage": "^1.1.0",
@ -47,7 +53,8 @@
"karma-threshold-reporter": "^0.1.15",
"karma-webpack": "^1.7.0",
"nsp": "^2.4.0",
"webpack": "^1.13.1"
"webpack": "^1.13.1",
"yaml-loader": "^0.4.0"
},
"files": [
"dist"

View File

@ -0,0 +1,8 @@
/*eslint no-sync: "off"*/
import yaml from 'js-yaml';
import fs from 'fs';
import cloudsYamlPath from './cloudsYamlPath';
const clouds = yaml.safeLoad(fs.readFileSync(cloudsYamlPath, 'utf8'));
export default clouds;

View File

@ -0,0 +1,23 @@
/*eslint no-process-env: "off", no-sync: "off"*/
import fs from 'fs';
import path from 'path';
const resolvePaths = [
'./clouds.yaml',
process.env.HOME + '/.config/openstack/clouds.yaml',
'/etc/openstack/clouds.yaml'
];
function fileExists(path) {
try {
fs.statSync(path);
return true;
} catch(err) {
return false;
}
}
const cloudFiles = resolvePaths.filter(fileExists);
export default cloudFiles.length > 0 ? path.resolve(cloudFiles[0]) : 'clouds.yaml';

View File

@ -0,0 +1,23 @@
import Test from "../../src/index";
import config from "./helpers/cloudsConfig";
describe("Simple functional test", () => {
it("should call keystone URL", (done) => {
const testKeystone = function(response) {
expect(response.status).toBe(200);
done();
};
const failTest = function(error) {
expect(error).toBeUndefined();
done();
};
const t = new Test();
t.getUrl(config.clouds.devstack.auth.auth_url + '/v2.0')
.then(testKeystone)
.catch(failTest);
});
});

View File

@ -0,0 +1,11 @@
{
"spec_dir": "test/functional",
"spec_files": [
"**/*[tT]est.js"
],
"helpers": [
"../../node_modules/babel-register/lib/node.js"
],
"stopSpecOnExpectationFailure": false,
"random": false
}

View File

@ -1,4 +1,4 @@
import Test from "../../src/index.js";
import Test from "../../src/index";
const FetchMock = require('fetch-mock');

View File

@ -1,3 +1,6 @@
import webpack from 'webpack';
import cloudsYamlPath from './test/functional/helpers/cloudsYamlPath';
export default {
entry: ['./src/index.js'],
output: {
@ -11,8 +14,15 @@ export default {
{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/
exclude: /node_modules/,
query: {
plugins: ['transform-inline-environment-variables']
}
}
]
}
},
plugins: [
new webpack.NormalModuleReplacementPlugin(/helpers\/cloudsConfig/,
'json!yaml!' + cloudsYamlPath)
]
};