mirror of
https://github.com/kemko/nomad.git
synced 2026-01-09 11:55:42 +03:00
This closes #10513, thanks to @bastelfreak for the report. GET /status/leader returns an IPv6 host with square brackets around the IP address as expected, but the rpcAddr property on the agent model does not. This fixes rpcAddr, updates the Mirage /status/leader mock to properly format an IPv6 host, and changes the agent factory to sometimes produce IPv6 addresses. I added a formatHost utility function to centralise the conditional square bracket-wrapping that would have otherwise been further scattered around.
89 lines
2.9 KiB
JavaScript
89 lines
2.9 KiB
JavaScript
import { currentURL } from '@ember/test-helpers';
|
|
import { module, test } from 'qunit';
|
|
import { setupApplicationTest } from 'ember-qunit';
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
|
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
|
|
import { findLeader } from '../../mirage/config';
|
|
import ServersList from 'nomad-ui/tests/pages/servers/list';
|
|
import formatHost from 'nomad-ui/utils/format-host';
|
|
|
|
const minimumSetup = () => {
|
|
server.createList('node', 1);
|
|
server.createList('agent', 1);
|
|
};
|
|
|
|
const agentSort = leader => (a, b) => {
|
|
if (formatHost(a.address, a.tags.port) === leader) {
|
|
return 1;
|
|
} else if (formatHost(b.address, b.tags.port) === leader) {
|
|
return -1;
|
|
}
|
|
return 0;
|
|
};
|
|
|
|
module('Acceptance | servers list', function(hooks) {
|
|
setupApplicationTest(hooks);
|
|
setupMirage(hooks);
|
|
|
|
test('it passes an accessibility audit', async function(assert) {
|
|
minimumSetup();
|
|
await ServersList.visit();
|
|
await a11yAudit(assert);
|
|
});
|
|
|
|
test('/servers should list all servers', async function(assert) {
|
|
server.createList('node', 1);
|
|
server.createList('agent', 10);
|
|
|
|
const leader = findLeader(server.schema);
|
|
const sortedAgents = server.db.agents.sort(agentSort(leader)).reverse();
|
|
|
|
await ServersList.visit();
|
|
|
|
assert.equal(ServersList.servers.length, ServersList.pageSize, 'List is stopped at pageSize');
|
|
|
|
ServersList.servers.forEach((server, index) => {
|
|
assert.equal(server.name, sortedAgents[index].name, 'Servers are ordered');
|
|
});
|
|
|
|
assert.equal(document.title, 'Servers - Nomad');
|
|
});
|
|
|
|
test('each server should show high-level info of the server', async function(assert) {
|
|
minimumSetup();
|
|
const agent = server.db.agents[0];
|
|
|
|
await ServersList.visit();
|
|
|
|
const agentRow = ServersList.servers.objectAt(0);
|
|
|
|
assert.equal(agentRow.name, agent.name, 'Name');
|
|
assert.equal(agentRow.status, agent.status, 'Status');
|
|
assert.equal(agentRow.leader, 'True', 'Leader?');
|
|
assert.equal(agentRow.address, agent.address, 'Address');
|
|
assert.equal(agentRow.serfPort, agent.serfPort, 'Serf Port');
|
|
assert.equal(agentRow.datacenter, agent.tags.dc, 'Datacenter');
|
|
});
|
|
|
|
test('each server should link to the server detail page', async function(assert) {
|
|
minimumSetup();
|
|
const agent = server.db.agents[0];
|
|
|
|
await ServersList.visit();
|
|
await ServersList.servers.objectAt(0).clickRow();
|
|
|
|
assert.equal(currentURL(), `/servers/${agent.name}`, 'Now at the server detail page');
|
|
});
|
|
|
|
test('when accessing servers is forbidden, show a message with a link to the tokens page', async function(assert) {
|
|
server.create('agent');
|
|
server.pretender.get('/v1/agent/members', () => [403, {}, null]);
|
|
|
|
await ServersList.visit();
|
|
assert.equal(ServersList.error.title, 'Not Authorized');
|
|
|
|
await ServersList.error.seekHelp();
|
|
assert.equal(currentURL(), '/settings/tokens');
|
|
});
|
|
});
|