2020-03-25 12:51:26 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupTest } from 'ember-qunit';
|
|
|
|
import VolumeModel from 'nomad-ui/models/volume';
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Unit | Serializer | Volume', function (hooks) {
|
2020-03-25 12:51:26 +00:00
|
|
|
setupTest(hooks);
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.beforeEach(function () {
|
2020-03-25 12:51:26 +00:00
|
|
|
this.store = this.owner.lookup('service:store');
|
|
|
|
this.subject = () => this.store.serializerFor('volume');
|
|
|
|
});
|
|
|
|
|
2020-04-01 21:44:22 +00:00
|
|
|
// Set the milliseconds to avoid possible floating point precision
|
|
|
|
// issue that arises from converting to nanos and back.
|
2020-03-25 12:51:26 +00:00
|
|
|
const REF_DATE = new Date();
|
2020-04-01 21:44:22 +00:00
|
|
|
REF_DATE.setMilliseconds(0);
|
2020-03-25 12:51:26 +00:00
|
|
|
|
|
|
|
const normalizationTestCases = [
|
|
|
|
{
|
2021-12-28 14:45:20 +00:00
|
|
|
name: '`default` is used as the namespace in the volume ID when there is no namespace in the payload',
|
2020-03-25 12:51:26 +00:00
|
|
|
in: {
|
|
|
|
ID: 'volume-id',
|
|
|
|
Name: 'volume-id',
|
|
|
|
PluginID: 'plugin-1',
|
|
|
|
ExternalID: 'external-uuid',
|
|
|
|
Topologies: {},
|
|
|
|
AccessMode: 'access-this-way',
|
|
|
|
AttachmentMode: 'attach-this-way',
|
|
|
|
Schedulable: true,
|
|
|
|
Provider: 'abc.123',
|
|
|
|
Version: '1.0.29',
|
|
|
|
ControllerRequired: true,
|
|
|
|
ControllersHealthy: 1,
|
|
|
|
ControllersExpected: 1,
|
|
|
|
NodesHealthy: 1,
|
|
|
|
NodesExpected: 2,
|
|
|
|
CreateIndex: 1,
|
|
|
|
ModifyIndex: 38,
|
|
|
|
WriteAllocs: {},
|
|
|
|
ReadAllocs: {},
|
|
|
|
},
|
|
|
|
out: {
|
|
|
|
data: {
|
|
|
|
id: '["csi/volume-id","default"]',
|
|
|
|
type: 'volume',
|
|
|
|
attributes: {
|
|
|
|
plainId: 'volume-id',
|
|
|
|
name: 'volume-id',
|
|
|
|
externalId: 'external-uuid',
|
|
|
|
topologies: {},
|
|
|
|
accessMode: 'access-this-way',
|
|
|
|
attachmentMode: 'attach-this-way',
|
|
|
|
schedulable: true,
|
|
|
|
provider: 'abc.123',
|
|
|
|
version: '1.0.29',
|
|
|
|
controllerRequired: true,
|
|
|
|
controllersHealthy: 1,
|
|
|
|
controllersExpected: 1,
|
|
|
|
nodesHealthy: 1,
|
|
|
|
nodesExpected: 2,
|
|
|
|
createIndex: 1,
|
|
|
|
modifyIndex: 38,
|
|
|
|
},
|
|
|
|
relationships: {
|
|
|
|
plugin: {
|
|
|
|
data: {
|
|
|
|
id: 'csi/plugin-1',
|
|
|
|
type: 'plugin',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
readAllocations: {
|
|
|
|
data: [],
|
|
|
|
},
|
|
|
|
writeAllocations: {
|
|
|
|
data: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
included: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
name: 'The ID of the record is a composite of both the name and the namespace',
|
|
|
|
in: {
|
|
|
|
ID: 'volume-id',
|
|
|
|
Name: 'volume-id',
|
|
|
|
Namespace: 'namespace-2',
|
|
|
|
PluginID: 'plugin-1',
|
|
|
|
ExternalID: 'external-uuid',
|
|
|
|
Topologies: {},
|
|
|
|
AccessMode: 'access-this-way',
|
|
|
|
AttachmentMode: 'attach-this-way',
|
|
|
|
Schedulable: true,
|
|
|
|
Provider: 'abc.123',
|
|
|
|
Version: '1.0.29',
|
|
|
|
ControllerRequired: true,
|
|
|
|
ControllersHealthy: 1,
|
|
|
|
ControllersExpected: 1,
|
|
|
|
NodesHealthy: 1,
|
|
|
|
NodesExpected: 2,
|
|
|
|
CreateIndex: 1,
|
|
|
|
ModifyIndex: 38,
|
|
|
|
WriteAllocs: {},
|
|
|
|
ReadAllocs: {},
|
|
|
|
},
|
|
|
|
out: {
|
|
|
|
data: {
|
|
|
|
id: '["csi/volume-id","namespace-2"]',
|
|
|
|
type: 'volume',
|
|
|
|
attributes: {
|
|
|
|
plainId: 'volume-id',
|
|
|
|
name: 'volume-id',
|
|
|
|
externalId: 'external-uuid',
|
|
|
|
topologies: {},
|
|
|
|
accessMode: 'access-this-way',
|
|
|
|
attachmentMode: 'attach-this-way',
|
|
|
|
schedulable: true,
|
|
|
|
provider: 'abc.123',
|
|
|
|
version: '1.0.29',
|
|
|
|
controllerRequired: true,
|
|
|
|
controllersHealthy: 1,
|
|
|
|
controllersExpected: 1,
|
|
|
|
nodesHealthy: 1,
|
|
|
|
nodesExpected: 2,
|
|
|
|
createIndex: 1,
|
|
|
|
modifyIndex: 38,
|
|
|
|
},
|
|
|
|
relationships: {
|
|
|
|
plugin: {
|
|
|
|
data: {
|
|
|
|
id: 'csi/plugin-1',
|
|
|
|
type: 'plugin',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
namespace: {
|
|
|
|
data: {
|
|
|
|
id: 'namespace-2',
|
|
|
|
type: 'namespace',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
readAllocations: {
|
|
|
|
data: [],
|
|
|
|
},
|
|
|
|
writeAllocations: {
|
|
|
|
data: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
included: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2021-12-28 14:45:20 +00:00
|
|
|
name: 'Allocations are interpreted as embedded records and are properly normalized into included resources in a JSON API shape',
|
2020-03-25 12:51:26 +00:00
|
|
|
in: {
|
|
|
|
ID: 'volume-id',
|
|
|
|
Name: 'volume-id',
|
|
|
|
Namespace: 'namespace-2',
|
|
|
|
PluginID: 'plugin-1',
|
|
|
|
ExternalID: 'external-uuid',
|
|
|
|
Topologies: {},
|
|
|
|
AccessMode: 'access-this-way',
|
|
|
|
AttachmentMode: 'attach-this-way',
|
|
|
|
Schedulable: true,
|
|
|
|
Provider: 'abc.123',
|
|
|
|
Version: '1.0.29',
|
|
|
|
ControllerRequired: true,
|
|
|
|
ControllersHealthy: 1,
|
|
|
|
ControllersExpected: 1,
|
|
|
|
NodesHealthy: 1,
|
|
|
|
NodesExpected: 2,
|
|
|
|
CreateIndex: 1,
|
|
|
|
ModifyIndex: 38,
|
2020-11-25 21:44:06 +00:00
|
|
|
Allocations: [
|
|
|
|
{
|
|
|
|
ID: 'alloc-id-1',
|
2020-03-25 12:51:26 +00:00
|
|
|
TaskGroup: 'foobar',
|
|
|
|
CreateTime: +REF_DATE * 1000000,
|
|
|
|
ModifyTime: +REF_DATE * 1000000,
|
|
|
|
JobID: 'the-job',
|
|
|
|
Namespace: 'namespace-2',
|
|
|
|
},
|
2020-11-25 21:44:06 +00:00
|
|
|
{
|
|
|
|
ID: 'alloc-id-2',
|
2020-03-25 12:51:26 +00:00
|
|
|
TaskGroup: 'write-here',
|
|
|
|
CreateTime: +REF_DATE * 1000000,
|
|
|
|
ModifyTime: +REF_DATE * 1000000,
|
|
|
|
JobID: 'the-job',
|
|
|
|
Namespace: 'namespace-2',
|
|
|
|
},
|
2020-11-25 21:44:06 +00:00
|
|
|
{
|
|
|
|
ID: 'alloc-id-3',
|
2020-03-25 12:51:26 +00:00
|
|
|
TaskGroup: 'look-if-you-must',
|
|
|
|
CreateTime: +REF_DATE * 1000000,
|
|
|
|
ModifyTime: +REF_DATE * 1000000,
|
|
|
|
JobID: 'the-job',
|
|
|
|
Namespace: 'namespace-2',
|
|
|
|
},
|
2020-11-25 21:44:06 +00:00
|
|
|
],
|
|
|
|
WriteAllocs: {
|
|
|
|
'alloc-id-1': null,
|
|
|
|
'alloc-id-2': null,
|
|
|
|
},
|
|
|
|
ReadAllocs: {
|
|
|
|
'alloc-id-3': null,
|
2020-03-25 12:51:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
out: {
|
|
|
|
data: {
|
|
|
|
id: '["csi/volume-id","namespace-2"]',
|
|
|
|
type: 'volume',
|
|
|
|
attributes: {
|
|
|
|
plainId: 'volume-id',
|
|
|
|
name: 'volume-id',
|
|
|
|
externalId: 'external-uuid',
|
|
|
|
topologies: {},
|
|
|
|
accessMode: 'access-this-way',
|
|
|
|
attachmentMode: 'attach-this-way',
|
|
|
|
schedulable: true,
|
|
|
|
provider: 'abc.123',
|
|
|
|
version: '1.0.29',
|
|
|
|
controllerRequired: true,
|
|
|
|
controllersHealthy: 1,
|
|
|
|
controllersExpected: 1,
|
|
|
|
nodesHealthy: 1,
|
|
|
|
nodesExpected: 2,
|
|
|
|
createIndex: 1,
|
|
|
|
modifyIndex: 38,
|
|
|
|
},
|
|
|
|
relationships: {
|
|
|
|
plugin: {
|
|
|
|
data: {
|
|
|
|
id: 'csi/plugin-1',
|
|
|
|
type: 'plugin',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
namespace: {
|
|
|
|
data: {
|
|
|
|
id: 'namespace-2',
|
|
|
|
type: 'namespace',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
readAllocations: {
|
|
|
|
data: [{ type: 'allocation', id: 'alloc-id-3' }],
|
|
|
|
},
|
|
|
|
writeAllocations: {
|
|
|
|
data: [
|
|
|
|
{ type: 'allocation', id: 'alloc-id-1' },
|
|
|
|
{ type: 'allocation', id: 'alloc-id-2' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
included: [
|
|
|
|
{
|
|
|
|
id: 'alloc-id-1',
|
|
|
|
type: 'allocation',
|
|
|
|
attributes: {
|
|
|
|
createTime: REF_DATE,
|
|
|
|
modifyTime: REF_DATE,
|
2021-12-18 01:23:28 +00:00
|
|
|
namespace: 'namespace-2',
|
2020-03-25 12:51:26 +00:00
|
|
|
taskGroupName: 'foobar',
|
|
|
|
wasPreempted: false,
|
|
|
|
states: [],
|
2020-05-01 21:30:02 +00:00
|
|
|
allocationTaskGroup: null,
|
2020-03-25 12:51:26 +00:00
|
|
|
},
|
|
|
|
relationships: {
|
|
|
|
followUpEvaluation: {
|
|
|
|
data: null,
|
|
|
|
},
|
|
|
|
job: {
|
|
|
|
data: { type: 'job', id: '["the-job","namespace-2"]' },
|
|
|
|
},
|
|
|
|
nextAllocation: {
|
|
|
|
data: null,
|
|
|
|
},
|
|
|
|
previousAllocation: {
|
|
|
|
data: null,
|
|
|
|
},
|
|
|
|
preemptedAllocations: {
|
|
|
|
data: [],
|
|
|
|
},
|
|
|
|
preemptedByAllocation: {
|
|
|
|
data: null,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'alloc-id-2',
|
|
|
|
type: 'allocation',
|
|
|
|
attributes: {
|
|
|
|
createTime: REF_DATE,
|
|
|
|
modifyTime: REF_DATE,
|
2021-12-18 01:23:28 +00:00
|
|
|
namespace: 'namespace-2',
|
2020-03-25 12:51:26 +00:00
|
|
|
taskGroupName: 'write-here',
|
|
|
|
wasPreempted: false,
|
|
|
|
states: [],
|
2020-05-01 21:30:02 +00:00
|
|
|
allocationTaskGroup: null,
|
2020-03-25 12:51:26 +00:00
|
|
|
},
|
|
|
|
relationships: {
|
|
|
|
followUpEvaluation: {
|
|
|
|
data: null,
|
|
|
|
},
|
|
|
|
job: {
|
|
|
|
data: { type: 'job', id: '["the-job","namespace-2"]' },
|
|
|
|
},
|
|
|
|
nextAllocation: {
|
|
|
|
data: null,
|
|
|
|
},
|
|
|
|
previousAllocation: {
|
|
|
|
data: null,
|
|
|
|
},
|
|
|
|
preemptedAllocations: {
|
|
|
|
data: [],
|
|
|
|
},
|
|
|
|
preemptedByAllocation: {
|
|
|
|
data: null,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'alloc-id-3',
|
|
|
|
type: 'allocation',
|
|
|
|
attributes: {
|
|
|
|
createTime: REF_DATE,
|
|
|
|
modifyTime: REF_DATE,
|
2021-12-18 01:23:28 +00:00
|
|
|
namespace: 'namespace-2',
|
2020-03-25 12:51:26 +00:00
|
|
|
taskGroupName: 'look-if-you-must',
|
|
|
|
wasPreempted: false,
|
|
|
|
states: [],
|
2020-05-01 21:30:02 +00:00
|
|
|
allocationTaskGroup: null,
|
2020-03-25 12:51:26 +00:00
|
|
|
},
|
|
|
|
relationships: {
|
|
|
|
followUpEvaluation: {
|
|
|
|
data: null,
|
|
|
|
},
|
|
|
|
job: {
|
|
|
|
data: { type: 'job', id: '["the-job","namespace-2"]' },
|
|
|
|
},
|
|
|
|
nextAllocation: {
|
|
|
|
data: null,
|
|
|
|
},
|
|
|
|
previousAllocation: {
|
|
|
|
data: null,
|
|
|
|
},
|
|
|
|
preemptedAllocations: {
|
|
|
|
data: [],
|
|
|
|
},
|
|
|
|
preemptedByAllocation: {
|
|
|
|
data: null,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
normalizationTestCases.forEach((testCase) => {
|
|
|
|
test(`normalization: ${testCase.name}`, async function (assert) {
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
this.subject().normalize(VolumeModel, testCase.in),
|
|
|
|
testCase.out
|
|
|
|
);
|
2020-03-25 12:51:26 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|