refactor tests that depend on Agent fixutres in Mirage
This commit is contained in:
parent
2efa6cc7e4
commit
46f8b3dc66
|
@ -39,7 +39,7 @@ export default class SystemService extends Service {
|
|||
.authorizedRawRequest(`/${namespace}/agent/self`)
|
||||
.then(jsonWithDefault({}))
|
||||
.then(agent => {
|
||||
if (agent.config.Version) {
|
||||
if (agent?.config?.Version) {
|
||||
const { Version, VersionPrerelease, VersionMetadata } = agent.config.Version;
|
||||
agent.version = Version;
|
||||
if (VersionPrerelease) agent.version = `${agent.version}-${VersionPrerelease}`;
|
||||
|
|
|
@ -9,7 +9,7 @@ import formatHost from 'nomad-ui/utils/format-host';
|
|||
|
||||
export function findLeader(schema) {
|
||||
const agent = schema.agents.first();
|
||||
return formatHost(agent.address, agent.tags.port);
|
||||
return formatHost(agent.member.Address, agent.member.Tags.port); // do we need to change this?
|
||||
}
|
||||
|
||||
export function filesForPath(allocFiles, filterPath) {
|
||||
|
|
|
@ -15,7 +15,7 @@ module('Acceptance | server detail', function(hooks) {
|
|||
hooks.beforeEach(async function() {
|
||||
server.createList('agent', 3);
|
||||
agent = server.db.agents[0];
|
||||
await ServerDetail.visit({ name: agent.name });
|
||||
await ServerDetail.visit({ name: agent.member.Name });
|
||||
});
|
||||
|
||||
test('it passes an accessibility audit', async function(assert) {
|
||||
|
@ -23,24 +23,27 @@ module('Acceptance | server detail', function(hooks) {
|
|||
});
|
||||
|
||||
test('visiting /servers/:server_name', async function(assert) {
|
||||
assert.equal(currentURL(), `/servers/${encodeURIComponent(agent.name)}`);
|
||||
assert.equal(document.title, `Server ${agent.name} - Nomad`);
|
||||
console.log('agent: ', agent);
|
||||
assert.equal(currentURL(), `/servers/${encodeURIComponent(agent.member.Name)}`);
|
||||
assert.equal(document.title, `Server ${agent.member.Name} - Nomad`);
|
||||
});
|
||||
|
||||
test('when the server is the leader, the title shows a leader badge', async function(assert) {
|
||||
assert.ok(ServerDetail.title.includes(agent.name));
|
||||
assert.ok(ServerDetail.title.includes(agent.member.Name));
|
||||
assert.ok(ServerDetail.hasLeaderBadge);
|
||||
});
|
||||
|
||||
test('the details ribbon displays basic information about the server', async function(assert) {
|
||||
assert.ok(ServerDetail.serverStatus.includes(agent.status));
|
||||
assert.ok(ServerDetail.address.includes(formatHost(agent.address, agent.tags.port)));
|
||||
assert.ok(ServerDetail.datacenter.includes(agent.tags.dc));
|
||||
assert.ok(ServerDetail.serverStatus.includes(agent.member.Status));
|
||||
assert.ok(
|
||||
ServerDetail.address.includes(formatHost(agent.member.Address, agent.member.Tags.port))
|
||||
);
|
||||
assert.ok(ServerDetail.datacenter.includes(agent.member.Tags.dc));
|
||||
});
|
||||
|
||||
test('the server detail page should list all tags for the server', async function(assert) {
|
||||
const tags = Object.keys(agent.tags)
|
||||
.map(name => ({ name, value: agent.tags[name] }))
|
||||
const tags = Object.keys(agent.member.Tags)
|
||||
.map(name => ({ name, value: agent.member.Tags[name] }))
|
||||
.sortBy('name');
|
||||
|
||||
assert.equal(ServerDetail.tags.length, tags.length, '# of tags');
|
||||
|
@ -52,7 +55,7 @@ module('Acceptance | server detail', function(hooks) {
|
|||
});
|
||||
|
||||
test('when the server is not the leader, there is no leader badge', async function(assert) {
|
||||
await ServerDetail.visit({ name: server.db.agents[1].name });
|
||||
await ServerDetail.visit({ name: server.db.agents[1].member.Name });
|
||||
assert.notOk(ServerDetail.hasLeaderBadge);
|
||||
});
|
||||
|
||||
|
|
|
@ -27,22 +27,22 @@ module('Acceptance | server monitor', function(hooks) {
|
|||
});
|
||||
|
||||
test('it passes an accessibility audit', async function(assert) {
|
||||
await ServerMonitor.visit({ name: agent.name });
|
||||
await ServerMonitor.visit({ name: agent.member.Name });
|
||||
await a11yAudit(assert);
|
||||
});
|
||||
|
||||
test('/servers/:id/monitor should have a breadcrumb trail linking back to servers', async function(assert) {
|
||||
await ServerMonitor.visit({ name: agent.name });
|
||||
await ServerMonitor.visit({ name: agent.member.Name });
|
||||
|
||||
assert.equal(Layout.breadcrumbFor('servers.index').text, 'Servers');
|
||||
assert.equal(Layout.breadcrumbFor('servers.server').text, agent.name);
|
||||
assert.equal(Layout.breadcrumbFor('servers.server').text, agent.member.name);
|
||||
|
||||
await Layout.breadcrumbFor('servers.index').visit();
|
||||
assert.equal(currentURL(), '/servers');
|
||||
});
|
||||
|
||||
test('the monitor page immediately streams agent monitor output at the info level', async function(assert) {
|
||||
await ServerMonitor.visit({ name: agent.name });
|
||||
await ServerMonitor.visit({ name: agent.member.Name });
|
||||
|
||||
const logRequest = server.pretender.handledRequests.find(req =>
|
||||
req.url.startsWith('/v1/agent/monitor')
|
||||
|
@ -53,15 +53,16 @@ module('Acceptance | server monitor', function(hooks) {
|
|||
});
|
||||
|
||||
test('switching the log level persists the new log level as a query param', async function(assert) {
|
||||
await ServerMonitor.visit({ name: agent.name });
|
||||
const name = agent.member.Name;
|
||||
await ServerMonitor.visit({ name: agent.member.Name });
|
||||
await ServerMonitor.selectLogLevel('Debug');
|
||||
assert.equal(currentURL(), `/servers/${agent.name}/monitor?level=debug`);
|
||||
assert.equal(currentURL(), `/servers/${name}/monitor?level=debug`);
|
||||
});
|
||||
|
||||
test('when the current access token does not include the agent:read rule, a descriptive error message is shown', async function(assert) {
|
||||
window.localStorage.nomadTokenSecret = clientToken.secretId;
|
||||
|
||||
await ServerMonitor.visit({ name: agent.name });
|
||||
await ServerMonitor.visit({ name: agent.member.Name });
|
||||
assert.notOk(ServerMonitor.logsArePresent);
|
||||
assert.ok(ServerMonitor.error.isShown);
|
||||
assert.equal(ServerMonitor.error.title, 'Not Authorized');
|
||||
|
|
|
@ -13,9 +13,9 @@ const minimumSetup = () => {
|
|||
};
|
||||
|
||||
const agentSort = leader => (a, b) => {
|
||||
if (formatHost(a.address, a.tags.port) === leader) {
|
||||
if (formatHost(a.member.Address, a.member.Tags.port) === leader) {
|
||||
return 1;
|
||||
} else if (formatHost(b.address, b.tags.port) === leader) {
|
||||
} else if (formatHost(b.member.Address, b.member.Tags.port) === leader) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -43,7 +43,7 @@ module('Acceptance | servers list', function(hooks) {
|
|||
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(server.name, sortedAgents[index].member.Name, 'Servers are ordered');
|
||||
});
|
||||
|
||||
assert.equal(document.title, 'Servers - Nomad');
|
||||
|
@ -57,12 +57,12 @@ module('Acceptance | servers list', function(hooks) {
|
|||
|
||||
const agentRow = ServersList.servers.objectAt(0);
|
||||
|
||||
assert.equal(agentRow.name, agent.name, 'Name');
|
||||
assert.equal(agentRow.status, agent.status, 'Status');
|
||||
assert.equal(agentRow.name, agent.member.Name, 'Name');
|
||||
assert.equal(agentRow.status, agent.member.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');
|
||||
assert.equal(agentRow.address, agent.member.Address, 'Address');
|
||||
assert.equal(agentRow.serfPort, agent.member.Port, 'Serf Port');
|
||||
assert.equal(agentRow.datacenter, agent.member.Tags.dc, 'Datacenter');
|
||||
});
|
||||
|
||||
test('each server should link to the server detail page', async function(assert) {
|
||||
|
@ -72,7 +72,7 @@ module('Acceptance | servers list', function(hooks) {
|
|||
await ServersList.visit();
|
||||
await ServersList.servers.objectAt(0).clickRow();
|
||||
|
||||
assert.equal(currentURL(), `/servers/${agent.name}`, 'Now at the server detail page');
|
||||
assert.equal(currentURL(), `/servers/${agent.member.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) {
|
||||
|
|
Loading…
Reference in New Issue