diff --git a/ui-v2/GNUmakefile b/ui-v2/GNUmakefile index 6236ecf99..1789a9cd4 100644 --- a/ui-v2/GNUmakefile +++ b/ui-v2/GNUmakefile @@ -73,8 +73,8 @@ specify-coverage: test-coverage: deps specify-coverage yarn run test:coverage -test-view-coverage: deps specify-coverage - yarn run test:view:coverage +test-coverage-view: deps specify-coverage + yarn run test:coverage:view test-parallel: deps yarn run test:parallel diff --git a/ui-v2/app/utils/components/discovery-chain/index.js b/ui-v2/app/utils/components/discovery-chain/index.js index cf5577315..0263ced36 100644 --- a/ui-v2/app/utils/components/discovery-chain/index.js +++ b/ui-v2/app/utils/components/discovery-chain/index.js @@ -39,7 +39,7 @@ export const getSplitters = function(nodes) { // Splitters need IDs adding so we can find them in the DOM later // splitters have a service.nspace as a name // do the reverse dance to ensure we don't mess up any - // serivice names with dots in them + // service names with dots in them const temp = item.Name.split('.'); temp.reverse(); temp.shift(); diff --git a/ui-v2/package.json b/ui-v2/package.json index 214e0f4ba..53a2cf712 100644 --- a/ui-v2/package.json +++ b/ui-v2/package.json @@ -30,7 +30,7 @@ "test:oss:view": "CONSUL_NSPACES_ENABLED=0 ember test --server --test-port=${EMBER_TEST_PORT:-7357}", "test:node": "tape ./node-tests/**/*.js", "test:coverage": "COVERAGE=true ember test --environment test --filter=Unit --test-port=${EMBER_TEST_PORT:-7357}", - "test:view:coverage": "COVERAGE=true ember test --server --environment test --filter=Unit --test-port=${EMBER_TEST_PORT:-7357}", + "test:coverage:view": "COVERAGE=true ember test --server --environment test --filter=Unit --test-port=${EMBER_TEST_PORT:-7357}", "steps:list": "node ./lib/commands/bin/list.js" }, "husky": { diff --git a/ui-v2/tests/unit/utils/components/discovery-chain/get-resolvers-test.js b/ui-v2/tests/unit/utils/components/discovery-chain/get-resolvers-test.js index 7463bcc12..8223d60c3 100644 --- a/ui-v2/tests/unit/utils/components/discovery-chain/get-resolvers-test.js +++ b/ui-v2/tests/unit/utils/components/discovery-chain/get-resolvers-test.js @@ -105,7 +105,7 @@ module('Unit | Utility | components/discovery-chain/get-resolvers', function() { Type: 'resolver', Name: 'v2.dc-failover.default.dc-1', Resolver: { - Target: 'v2.dc-failover.defauilt.dc-1', + Target: 'v2.dc-failover.default.dc-1', Failover: { Targets: ['v2.dc-failover.default.dc-5', 'v2.dc-failover.default.dc-6'], }, @@ -166,7 +166,7 @@ module('Unit | Utility | components/discovery-chain/get-resolvers', function() { Type: 'resolver', Name: 'dc-failover.default.dc-1', Resolver: { - Target: 'dc-failover.defauilt.dc-1', + Target: 'dc-failover.default.dc-1', Failover: { Targets: ['dc-failover.default.dc-5', 'dc-failover.default.dc-6'], }, @@ -196,4 +196,60 @@ module('Unit | Utility | components/discovery-chain/get-resolvers', function() { assert.deepEqual(actual[0], expected); }); }); + test('it finds services with redirects with failovers correctly', function(assert) { + return Promise.resolve({ + Chain: { + ServiceName: 'service-name', + Namespace: 'default', + Datacenter: 'dc-1', + Protocol: 'http', + StartNode: '', + Nodes: { + 'resolver:dc-failover.default.redirect-dc-1': { + Type: 'resolver', + Name: 'dc-failover.default.redirect-dc-1', + Resolver: { + Target: 'dc-failover.default.redirect-dc-1', + Failover: { + Targets: ['dc-failover.default.redirect-dc-5', 'dc-failover.default.redirect-dc-6'], + }, + }, + }, + }, + Targets: { + 'dc-failover.default.redirect-dc-1': { + ID: 'dc-failover.default.redirect-dc-1', + Service: 'dc-failover', + Namespace: 'default', + Datacenter: 'redirect-dc-1', + }, + }, + }, + }).then(function({ Chain }) { + const actual = getResolvers(dc, nspace, Chain.Targets, Chain.Nodes); + // Both the parent and the child should have a Failover property + // as in order for a redirect to have failovers it must redirect to a + // service that already has failovers + const expected = { + ID: 'dc-failover.default.dc-1', + Name: 'dc-failover', + Failover: { + Targets: ['redirect-dc-5', 'redirect-dc-6'], + Type: 'Datacenter', + }, + Children: [ + { + Failover: { + Targets: ['redirect-dc-5', 'redirect-dc-6'], + Type: 'Datacenter', + }, + ID: 'dc-failover.default.redirect-dc-1', + Name: 'redirect-dc-1', + Redirect: true, + }, + ], + }; + assert.deepEqual(actual[0], expected); + }); + }); }); diff --git a/ui-v2/tests/unit/utils/components/discovery-chain/get-splitters-test.js b/ui-v2/tests/unit/utils/components/discovery-chain/get-splitters-test.js new file mode 100644 index 000000000..ca1dc500d --- /dev/null +++ b/ui-v2/tests/unit/utils/components/discovery-chain/get-splitters-test.js @@ -0,0 +1,54 @@ +import { getSplitters } from 'consul-ui/utils/components/discovery-chain/index'; +import { module, test } from 'qunit'; + +module('Unit | Utility | components/discovery-chain/get-splitters', function() { + test('it collects and correctly parses splitter Names', function(assert) { + const actual = getSplitters({ + 'splitter:splitter-name.default': { + Type: 'splitter', + Name: 'splitter-name.default', + Splits: [ + { + Weight: 50, + NextNode: '', + }, + { + Weight: 50, + NextNode: '', + }, + ], + }, + 'splitter:not-splitter-name.default': { + Type: 'not-splitter', + Name: 'splitter-name.default', + Splits: [ + { + Weight: 50, + NextNode: '', + }, + { + Weight: 50, + NextNode: '', + }, + ], + }, + }); + const expected = { + Type: 'splitter', + Name: 'splitter-name', + ID: 'splitter:splitter-name.default', + Splits: [ + { + Weight: 50, + NextNode: '', + }, + { + Weight: 50, + NextNode: '', + }, + ], + }; + assert.equal(actual.length, 1); + assert.deepEqual(actual[0], expected); + }); +});