Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: Pass through default environment settings when when booting dev/test #14519

Merged
merged 2 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const selectors = {
$: '.consul-peer-list',
collection: {
$: '[data-test-list-row]',
peer: {
$: 'li'
},
}
};
export default (collection, isPresent) => () => {
return collection(`${selectors.$} ${selectors.collection.$}`, {
peer: isPresent(selectors.collection.peer.$),
});
};
3 changes: 3 additions & 0 deletions ui/packages/consul-ui/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module.exports = function(environment, $ = process.env) {
SSOEnabled: false,
PeeringEnabled: false,
PartitionsEnabled: false,
HCPEnabled: false,
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),
APIPrefix: env('CONSUL_API_PREFIX', '')
Expand All @@ -110,6 +111,7 @@ module.exports = function(environment, $ = process.env) {
// in testing peering feature is on by default
PeeringEnabled: env('CONSUL_PEERINGS_ENABLED', true),
PartitionsEnabled: env('CONSUL_PARTITIONS_ENABLED', false),
HCPEnabled: env('CONSUL_HCP_ENABLED', false),
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),
APIPrefix: env('CONSUL_API_PREFIX', '')
Expand Down Expand Up @@ -163,6 +165,7 @@ module.exports = function(environment, $ = process.env) {
SSOEnabled: env('CONSUL_SSO_ENABLED', true),
PeeringEnabled: env('CONSUL_PEERINGS_ENABLED', true),
PartitionsEnabled: env('CONSUL_PARTITIONS_ENABLED', true),
HCPEnabled: env('CONSUL_HCP_ENABLED', false),
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),
APIPrefix: env('CONSUL_API_PREFIX', '')
Expand Down
31 changes: 23 additions & 8 deletions ui/packages/consul-ui/lib/startup/templates/body.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,37 @@ ${
(
function(get, obj) {
Object.entries(obj).forEach(([key, value]) => {
if(get(key) || (key === 'CONSUL_NSPACES_ENABLE' && ${
if(value.default || get(key) || (key === 'CONSUL_NSPACES_ENABLE' && ${
env('CONSUL_NSPACES_ENABLED') === '1' ? `true` : `false`
})) {
document.write(\`\\x3Cscript src="${rootURL}assets/\${value}/services.js">\\x3C/script>\`);
document.write(\`\\x3Cscript src="${rootURL}assets/\${value}/routes.js">\\x3C/script>\`);
document.write(\`\\x3Cscript src="${rootURL}assets/\${value.name}/services.js">\\x3C/script>\`);
document.write(\`\\x3Cscript src="${rootURL}assets/\${value.name}/routes.js">\\x3C/script>\`);
}
});
}
)(
key => document.cookie.split('; ').find(item => item.startsWith(\`\${key}=\`)),
{
'CONSUL_ACLS_ENABLE': 'consul-acls',
'CONSUL_PEERINGS_ENABLE': 'consul-peerings',
'CONSUL_PARTITIONS_ENABLE': 'consul-partitions',
'CONSUL_NSPACES_ENABLE': 'consul-nspaces',
'CONSUL_HCP_ENABLE': 'consul-hcp'
'CONSUL_ACLS_ENABLE': {
name: 'consul-acls',
default: ${config.operatorConfig.ACLsEnabled}
},
'CONSUL_PEERINGS_ENABLE': {
name: 'consul-peerings',
default: ${config.operatorConfig.PeeringEnabled}
},
'CONSUL_PARTITIONS_ENABLE': {
name: 'consul-partitions',
default: ${config.operatorConfig.PartitionsEnabled}
},
'CONSUL_NSPACES_ENABLE': {
name: 'consul-nspaces',
default: ${config.operatorConfig.NamespacesEnabled}
},
'CONSUL_HCP_ENABLE': {
name: 'consul-hcp',
default: ${config.operatorConfig.HCPEnabled}
}
}
);
</script>
Expand Down
4 changes: 4 additions & 0 deletions ui/packages/consul-ui/node-tests/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ test(
SSOEnabled: false,
PartitionsEnabled: false,
PeeringEnabled: true,
HCPEnabled: false,
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
APIPrefix: '',
Expand All @@ -41,6 +42,7 @@ test(
SSOEnabled: false,
PartitionsEnabled: false,
PeeringEnabled: true,
HCPEnabled: false,
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
APIPrefix: '',
Expand All @@ -58,6 +60,7 @@ test(
SSOEnabled: true,
PartitionsEnabled: false,
PeeringEnabled: true,
HCPEnabled: false,
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
APIPrefix: '',
Expand All @@ -72,6 +75,7 @@ test(
SSOEnabled: true,
PartitionsEnabled: true,
PeeringEnabled: true,
HCPEnabled: false,
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
APIPrefix: '',
Expand Down
19 changes: 19 additions & 0 deletions ui/packages/consul-ui/tests/acceptance/dc/peers/index.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@setupApplicationTest
Feature: dc / peers / index: Peers List
Background:
And 1 datacenter model with the value "dc-1"
And 3 peer models from yaml
---
- Name: a-peer
- Name: b-peer
- Name: z-peer
---
When I visit the peers page for yaml
---
dc: dc-1
---
Then the url should be /dc-1/peers
And the title should be "Peers - Consul"
Scenario:
Then I see 3 peer models

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import steps from '../../steps';

// step definitions that are shared between features should be moved to the
// tests/acceptance/steps/steps.js file

export default function(assert) {
return steps(assert)
.then('I should find a file', function() {
assert.ok(true, this.step);
});
}
3 changes: 3 additions & 0 deletions ui/packages/consul-ui/tests/helpers/set-cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export default function(type, value, doc = document) {
case 'nspace':
key = 'CONSUL_NSPACE_COUNT';
break;
case 'peer':
key = 'CONSUL_PEER_COUNT';
break;
}
if (key) {
obj[key] = value;
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/consul-ui/tests/helpers/type-to-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export default function(type) {
case 'nspace':
requests = ['/v1/namespaces', '/v1/namespace/'];
break;
case 'peer':
requests = ['/v1/peers', '/v1/peer/'];
break;
case 'topology':
requests = ['/v1/internal/ui/service-topology'];
break;
Expand Down
7 changes: 7 additions & 0 deletions ui/packages/consul-ui/tests/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import consulPolicyListFactory from 'consul-ui/components/consul/policy/list/pag
import consulAuthMethodListFactory from 'consul-ui/components/consul/auth-method/list/pageobject';
import consulIntentionListFactory from 'consul-ui/components/consul/intention/list/pageobject';
import consulNspaceListFactory from 'consul-ui/components/consul/nspace/list/pageobject';
import consulPeerListFactory from 'consul-ui/components/consul/peer/list/test-support';
import consulKvListFactory from 'consul-ui/components/consul/kv/list/pageobject';

// pages
Expand Down Expand Up @@ -73,6 +74,7 @@ import intentions from 'consul-ui/tests/pages/dc/intentions/index';
import intention from 'consul-ui/tests/pages/dc/intentions/edit';
import nspaces from 'consul-ui/tests/pages/dc/nspaces/index';
import nspace from 'consul-ui/tests/pages/dc/nspaces/edit';
import peers from 'consul-ui/tests/pages/dc/peers/index';

// utils
const deletable = createDeletable(clickable);
Expand Down Expand Up @@ -109,6 +111,10 @@ const consulNspaceList = consulNspaceListFactory(
text,
morePopoverMenu
);
const consulPeerList = consulPeerListFactory(
collection,
isPresent
);
const consulKvList = consulKvListFactory(collection, clickable, attribute, deletable);
const consulTokenList = consulTokenListFactory(
collection,
Expand Down Expand Up @@ -230,6 +236,7 @@ export default {
nspace: create(
nspace(visitable, submitable, deletable, cancelable, policySelector, roleSelector)
),
peers: create(peers(visitable, creatable, consulPeerList, popoverSelect)),
settings: create(settings(visitable, submitable, isPresent)),
routingConfig: create(routingConfig(visitable, text)),
};
7 changes: 7 additions & 0 deletions ui/packages/consul-ui/tests/pages/dc/peers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function(visitable, creatable, items, popoverSelect) {
return creatable({
visit: visitable('/:dc/peers'),
peers: items(),
sort: popoverSelect('[data-test-sort-control]'),
});
}