2020-03-24 23:22:16 +00:00
|
|
|
import generateExecUrl from 'nomad-ui/utils/generate-exec-url';
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
|
|
|
|
const emptyOptions = { queryParams: {} };
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Unit | Utility | generate-exec-url', function (hooks) {
|
|
|
|
hooks.beforeEach(function () {
|
2020-03-24 23:22:16 +00:00
|
|
|
this.urlForSpy = sinon.spy();
|
|
|
|
this.router = { urlFor: this.urlForSpy, currentRoute: { queryParams: {} } };
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it generates an exec job URL', function (assert) {
|
2020-04-29 12:54:04 +00:00
|
|
|
generateExecUrl(this.router, { job: { plainId: 'job-name' } });
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
assert.ok(this.urlForSpy.calledWith('exec', 'job-name', emptyOptions));
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it generates an exec job URL with an allocation and task group when there are multiple tasks', function (assert) {
|
2020-07-20 21:07:39 +00:00
|
|
|
generateExecUrl(this.router, {
|
|
|
|
job: { plainId: 'job-name' },
|
|
|
|
allocation: {
|
|
|
|
shortId: 'allocation-short-id',
|
|
|
|
taskGroup: { name: 'task-group-name', tasks: [0, 1, 2] },
|
|
|
|
},
|
|
|
|
});
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
assert.ok(
|
2021-12-28 16:08:12 +00:00
|
|
|
this.urlForSpy.calledWith(
|
|
|
|
'exec.task-group',
|
|
|
|
'job-name',
|
|
|
|
'task-group-name',
|
|
|
|
{
|
|
|
|
queryParams: { allocation: 'allocation-short-id' },
|
|
|
|
}
|
|
|
|
)
|
2020-03-24 23:22:16 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it generates an exec job URL with an allocation, task group, and task when there is only one task', function (assert) {
|
2020-07-20 21:07:39 +00:00
|
|
|
generateExecUrl(this.router, {
|
|
|
|
job: { plainId: 'job-name' },
|
|
|
|
allocation: {
|
|
|
|
shortId: 'allocation-short-id',
|
|
|
|
taskGroup: { name: 'task-group-name', tasks: [{ name: 'task-name' }] },
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
this.urlForSpy.calledWith(
|
|
|
|
'exec.task-group.task',
|
|
|
|
'job-name',
|
|
|
|
'task-group-name',
|
|
|
|
'task-name',
|
|
|
|
{
|
|
|
|
queryParams: { allocation: 'allocation-short-id' },
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it generates an exec task group URL', function (assert) {
|
2020-07-20 21:07:39 +00:00
|
|
|
generateExecUrl(this.router, {
|
|
|
|
job: { plainId: 'job-name' },
|
|
|
|
taskGroup: { name: 'task-group-name' },
|
|
|
|
});
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
assert.ok(
|
2021-12-28 16:08:12 +00:00
|
|
|
this.urlForSpy.calledWith(
|
|
|
|
'exec.task-group',
|
|
|
|
'job-name',
|
|
|
|
'task-group-name',
|
|
|
|
emptyOptions
|
|
|
|
)
|
2020-03-24 23:22:16 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it generates an exec task URL', function (assert) {
|
2020-03-24 23:22:16 +00:00
|
|
|
generateExecUrl(this.router, {
|
2020-04-29 12:54:04 +00:00
|
|
|
allocation: { shortId: 'allocation-short-id' },
|
|
|
|
job: { plainId: 'job-name' },
|
|
|
|
taskGroup: { name: 'task-group-name' },
|
|
|
|
task: { name: 'task-name' },
|
2020-03-24 23:22:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
this.urlForSpy.calledWith(
|
|
|
|
'exec.task-group.task',
|
|
|
|
'job-name',
|
|
|
|
'task-group-name',
|
|
|
|
'task-name',
|
|
|
|
{ queryParams: { allocation: 'allocation-short-id' } }
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it generates an exec task URL without an allocation', function (assert) {
|
2020-09-15 19:48:29 +00:00
|
|
|
generateExecUrl(this.router, {
|
|
|
|
job: { plainId: 'job-name' },
|
|
|
|
taskGroup: { name: 'task-group-name' },
|
|
|
|
task: { name: 'task-name' },
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.ok(
|
2021-12-28 16:08:12 +00:00
|
|
|
this.urlForSpy.calledWith(
|
|
|
|
'exec.task-group.task',
|
|
|
|
'job-name',
|
|
|
|
'task-group-name',
|
|
|
|
'task-name'
|
|
|
|
)
|
2020-09-15 19:48:29 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it includes job namespace and region when they exist', function (assert) {
|
2020-07-20 21:07:39 +00:00
|
|
|
generateExecUrl(this.router, {
|
2021-02-04 19:14:15 +00:00
|
|
|
job: {
|
|
|
|
namespace: {
|
|
|
|
name: 'a-namespace',
|
|
|
|
},
|
|
|
|
plainId: 'job-name',
|
|
|
|
region: 'a-region',
|
|
|
|
},
|
2021-12-28 16:08:12 +00:00
|
|
|
allocation: {
|
|
|
|
shortId: 'id',
|
|
|
|
taskGroup: { name: 'task-group-name', tasks: [0, 1] },
|
|
|
|
},
|
2020-07-20 21:07:39 +00:00
|
|
|
});
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
assert.ok(
|
2021-12-28 16:08:12 +00:00
|
|
|
this.urlForSpy.calledWith(
|
|
|
|
'exec.task-group',
|
|
|
|
'job-name',
|
|
|
|
'task-group-name',
|
|
|
|
{
|
|
|
|
queryParams: {
|
|
|
|
allocation: 'id',
|
|
|
|
namespace: 'a-namespace',
|
|
|
|
region: 'a-region',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
2020-03-24 23:22:16 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|