2020-11-11 14:43:37 +00:00
|
|
|
import { getAlternateServices } from 'consul-ui/components/consul/discovery-chain/utils';
|
2020-01-16 16:31:09 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
|
2022-09-15 08:43:17 +00:00
|
|
|
module('Unit | Component | consul/discovery-chain/get-alternative-services', function () {
|
|
|
|
test('it guesses a different namespace', function (assert) {
|
2020-01-16 16:31:09 +00:00
|
|
|
const expected = {
|
|
|
|
Type: 'Namespace',
|
|
|
|
Targets: ['different-ns', 'different-ns2'],
|
|
|
|
};
|
|
|
|
const actual = getAlternateServices(
|
2021-12-06 10:22:09 +00:00
|
|
|
['service.different-ns.partition.dc', 'service.different-ns2.partition.dc'],
|
|
|
|
'service.namespace.partition.dc'
|
2020-01-16 16:31:09 +00:00
|
|
|
);
|
|
|
|
assert.equal(actual.Type, expected.Type);
|
|
|
|
assert.deepEqual(actual.Targets, expected.Targets);
|
|
|
|
});
|
2022-09-15 08:43:17 +00:00
|
|
|
test('it guesses a different datacenter', function (assert) {
|
2020-01-16 16:31:09 +00:00
|
|
|
const expected = {
|
|
|
|
Type: 'Datacenter',
|
|
|
|
Targets: ['dc1', 'dc2'],
|
|
|
|
};
|
|
|
|
const actual = getAlternateServices(
|
2021-12-06 10:22:09 +00:00
|
|
|
['service.namespace.partition.dc1', 'service.namespace.partition.dc2'],
|
|
|
|
'service.namespace.partition.dc'
|
2020-01-16 16:31:09 +00:00
|
|
|
);
|
|
|
|
assert.equal(actual.Type, expected.Type);
|
|
|
|
assert.deepEqual(actual.Targets, expected.Targets);
|
|
|
|
});
|
2022-09-15 08:43:17 +00:00
|
|
|
test('it guesses a different service', function (assert) {
|
2020-01-16 16:31:09 +00:00
|
|
|
const expected = {
|
|
|
|
Type: 'Service',
|
|
|
|
Targets: ['service-2', 'service-3'],
|
|
|
|
};
|
|
|
|
const actual = getAlternateServices(
|
2021-12-06 10:22:09 +00:00
|
|
|
['service-2.namespace.partition.dc', 'service-3.namespace.partition.dc'],
|
|
|
|
'service.namespace.partition.dc'
|
2020-01-16 16:31:09 +00:00
|
|
|
);
|
|
|
|
assert.equal(actual.Type, expected.Type);
|
|
|
|
assert.deepEqual(actual.Targets, expected.Targets);
|
|
|
|
});
|
2022-09-15 08:43:17 +00:00
|
|
|
test('it guesses a different subset', function (assert) {
|
2020-01-16 16:31:09 +00:00
|
|
|
const expected = {
|
|
|
|
Type: 'Subset',
|
|
|
|
Targets: ['v3', 'v2'],
|
|
|
|
};
|
|
|
|
const actual = getAlternateServices(
|
2021-12-06 10:22:09 +00:00
|
|
|
['v3.service.namespace.partition.dc', 'v2.service.namespace.partition.dc'],
|
|
|
|
'v1.service.namespace.partition.dc'
|
2020-01-16 16:31:09 +00:00
|
|
|
);
|
|
|
|
assert.equal(actual.Type, expected.Type);
|
|
|
|
assert.deepEqual(actual.Targets, expected.Targets);
|
|
|
|
});
|
|
|
|
});
|