Skip to content

Commit

Permalink
ui: Upgrade ember-cli-api-double. Adds new staging env (#6136)
Browse files Browse the repository at this point in the history
ember-cli-api-double has been upgraded for 3 things:

1. Use the correct configuration flags
2. Automatically include the necessary files to enable the api doubles
without requiring a server. This can be disabled to provide custom
functionality (so we can stitch our BDD style testing in with this)
3. When used statically, read the cookies from the users browser to
enable basic ad-hoc double editing (e.g. CONSUL_SERVICE_COUNT=100000)

Once upgraded we've now moved the config to the correct place, added a
new environment (staging) to use the static-style of doubles
The test environment continues to use custom cookie setting and url
checking so we disable this 'auto importing' by setting 'auto-import' to
false for the configuration for the addon.

We also added a couple of new package script targets to explicitly serve
or build the UI with the entirely static UI.
  • Loading branch information
johncowen authored and John Cowen committed Sep 4, 2019
1 parent a263bff commit 3a0d083
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 176 deletions.
12 changes: 9 additions & 3 deletions ui-v2/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ module.exports = function(environment) {
CONSUL_COPYRIGHT_URL: 'https://www.hashicorp.com',
CONSUL_COPYRIGHT_YEAR: '2019',
});

if (environment === 'development') {
// ENV.APP.LOG_RESOLVER = true;
// ENV.APP.LOG_ACTIVE_GENERATION = true;
Expand All @@ -90,8 +89,15 @@ module.exports = function(environment) {

ENV.APP.rootElement = '#ember-testing';
ENV.APP.autoboot = false;
ENV['ember-cli-api-double'] = {
reader: 'html',
ENV['@hashicorp/ember-cli-api-double'] = {
'auto-import': false,
enabled: true,
endpoints: ['/node_modules/@hashicorp/consul-api-double/v1'],
};
}
if (environment === 'staging') {
ENV['@hashicorp/ember-cli-api-double'] = {
enabled: true,
endpoints: ['/node_modules/@hashicorp/consul-api-double/v1'],
};
}
Expand Down
5 changes: 3 additions & 2 deletions ui-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
"repository": "",
"scripts": {
"build": "ember build --environment production",
"build:staging": "ember build --environment staging",
"build-ci": "ember build --environment test",
"lint:dev:js": "eslint -c .dev.eslintrc.js --fix ./*.js ./.*.js app config lib server tests",
"lint:js": "eslint -c .eslintrc.js --fix ./*.js ./.*.js app config lib server tests",
"format:js": "prettier --write \"{app,config,lib,server,tests}/**/*.js\" ./*.js ./.*.js",
"format:css": "prettier --write \"app/styles/**/*.*\"",
"start": "ember serve --port=${EMBER_SERVE_PORT:-4200} --live-reload-port=${EMBER_LIVE_RELOAD_PORT:-7020}",
"start:staging": "ember serve --port=${EMBER_SERVE_PORT:-4200} --live-reload-port=${EMBER_LIVE_RELOAD_PORT:-7020} --environment staging",
"start:api": "api-double --dir ./node_modules/@hashicorp/consul-api-double",
"test": "ember test --test-port=${EMBER_TEST_PORT:-7357}",
"test-parallel": "EMBER_EXAM_PARALLEL=true ember exam --split=4 --parallel",
Expand Down Expand Up @@ -50,7 +52,7 @@
"devDependencies": {
"@babel/core": "^7.2.2",
"@hashicorp/consul-api-double": "^2.0.1",
"@hashicorp/ember-cli-api-double": "^1.3.0",
"@hashicorp/ember-cli-api-double": "^2.0.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"base64-js": "^1.3.0",
"broccoli-asset-rev": "^2.4.5",
Expand All @@ -64,7 +66,6 @@
"ember-cli-app-version": "^3.0.0",
"ember-cli-autoprefixer": "^0.8.1",
"ember-cli-babel": "^6.6.0",
"ember-cli-cjs-transform": "^1.2.0",
"ember-cli-code-coverage": "^1.0.0-beta.4",
"ember-cli-dependency-checker": "^2.0.0",
"ember-cli-eslint": "^4.2.1",
Expand Down
21 changes: 9 additions & 12 deletions ui-v2/tests/helpers/api.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import getAPI from '@hashicorp/ember-cli-api-double';
import config from 'consul-ui/config/environment';

import apiDouble from '@hashicorp/ember-cli-api-double';
import setCookies from 'consul-ui/tests/helpers/set-cookies';
import typeToURL from 'consul-ui/tests/helpers/type-to-url';
import config from 'consul-ui/config/environment';
const apiConfig = config['ember-cli-api-double'];
let path = '/consul-api-double';
let reader;
if (apiConfig) {
const temp = apiConfig.endpoints[0].split('/');
reader = apiConfig.reader;
temp.pop();
path = temp.join('/');
}
const api = getAPI(path, setCookies, typeToURL, reader);

const addon = config['@hashicorp/ember-cli-api-double'];
const temp = addon.endpoints[0].split('/');
temp.pop();
const path = temp.join('/');
const api = apiDouble(path, setCookies, typeToURL);
export const get = function(_url, options = { headers: { cookie: {} } }) {
const url = new URL(_url, 'http://localhost');
return new Promise(function(resolve) {
Expand Down
87 changes: 45 additions & 42 deletions ui-v2/tests/helpers/set-cookies.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
export default function(type, count, obj) {
var key = '';
obj['CONSUL_ACLS_ENABLE'] = 1;
switch (type) {
case 'dc':
key = 'CONSUL_DATACENTER_COUNT';
break;
case 'service':
key = 'CONSUL_SERVICE_COUNT';
break;
case 'node':
case 'instance':
key = 'CONSUL_NODE_COUNT';
break;
case 'kv':
key = 'CONSUL_KV_COUNT';
break;
case 'acl':
key = 'CONSUL_ACL_COUNT';
obj['CONSUL_ACLS_ENABLE'] = 1;
break;
case 'session':
key = 'CONSUL_SESSION_COUNT';
break;
case 'intention':
key = 'CONSUL_INTENTION_COUNT';
break;
case 'policy':
key = 'CONSUL_POLICY_COUNT';
obj['CONSUL_ACLS_ENABLE'] = 1;
break;
case 'role':
key = 'CONSUL_ROLE_COUNT';
obj['CONSUL_ACLS_ENABLE'] = 1;
break;
case 'token':
key = 'CONSUL_TOKEN_COUNT';
obj['CONSUL_ACLS_ENABLE'] = 1;
break;
}
if (key) {
obj[key] = count;
export default function(type, value) {
const obj = {};
if (type !== '*') {
let key = '';
obj['CONSUL_ACLS_ENABLE'] = 1;
switch (type) {
case 'dc':
key = 'CONSUL_DATACENTER_COUNT';
break;
case 'service':
key = 'CONSUL_SERVICE_COUNT';
break;
case 'node':
case 'instance':
key = 'CONSUL_NODE_COUNT';
break;
case 'kv':
key = 'CONSUL_KV_COUNT';
break;
case 'acl':
key = 'CONSUL_ACL_COUNT';
obj['CONSUL_ACLS_ENABLE'] = 1;
break;
case 'session':
key = 'CONSUL_SESSION_COUNT';
break;
case 'intention':
key = 'CONSUL_INTENTION_COUNT';
break;
case 'policy':
key = 'CONSUL_POLICY_COUNT';
obj['CONSUL_ACLS_ENABLE'] = 1;
break;
case 'role':
key = 'CONSUL_ROLE_COUNT';
obj['CONSUL_ACLS_ENABLE'] = 1;
break;
case 'token':
key = 'CONSUL_TOKEN_COUNT';
obj['CONSUL_ACLS_ENABLE'] = 1;
break;
}
if (key) {
obj[key] = value;
}
}
return obj;
}
Loading

0 comments on commit 3a0d083

Please sign in to comment.