mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 09:25:46 +03:00
Update serializer unit tests to use module instead of custom code
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
import { module } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer';
|
||||
|
||||
export default function(modelName, description, options = { needs: [] }) {
|
||||
// moduleForModel correctly wires up #Serializer.store,
|
||||
// but module does not.
|
||||
module(description, function(hooks) {
|
||||
setupTest(hooks);
|
||||
this.store = this.owner.lookup('service:store');
|
||||
|
||||
// Initializers don't run automatically in unit tests
|
||||
fragmentSerializerInitializer(this.owner);
|
||||
|
||||
// Reassign the subject to provide the serializer
|
||||
this.subject = () => this.store.serializerFor(modelName);
|
||||
|
||||
if (options.beforeEach) {
|
||||
options.beforeEach.apply(this, arguments);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,149 +1,139 @@
|
||||
import { test } from 'qunit';
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import AllocationModel from 'nomad-ui/models/allocation';
|
||||
import moduleForSerializer from '../../helpers/module-for-serializer';
|
||||
|
||||
moduleForSerializer('allocation', 'Unit | Serializer | Allocation', {
|
||||
needs: [
|
||||
'service:token',
|
||||
'service:system',
|
||||
'serializer:allocation',
|
||||
'transform:fragment',
|
||||
'transform:fragment-array',
|
||||
'model:job',
|
||||
'model:node',
|
||||
'model:namespace',
|
||||
'model:evaluation',
|
||||
'model:allocation',
|
||||
'model:resources',
|
||||
'model:task-state',
|
||||
'model:reschedule-event',
|
||||
],
|
||||
});
|
||||
module('Unit | Serializer | Allocation', function(hooks) {
|
||||
setupTest(hooks);
|
||||
hooks.beforeEach(function() {
|
||||
this.store = this.owner.lookup('service:store');
|
||||
this.subject = () => this.store.serializerFor('allocation');
|
||||
});
|
||||
|
||||
const sampleDate = new Date('2018-12-12T00:00:00');
|
||||
const normalizationTestCases = [
|
||||
{
|
||||
name: 'Normal',
|
||||
in: {
|
||||
ID: 'test-allocation',
|
||||
JobID: 'test-summary',
|
||||
Name: 'test-summary[1]',
|
||||
Namespace: 'test-namespace',
|
||||
TaskGroup: 'test-group',
|
||||
CreateTime: +sampleDate * 1000000,
|
||||
ModifyTime: +sampleDate * 1000000,
|
||||
TaskStates: {
|
||||
testTask: {
|
||||
State: 'running',
|
||||
Failed: false,
|
||||
const sampleDate = new Date('2018-12-12T00:00:00');
|
||||
const normalizationTestCases = [
|
||||
{
|
||||
name: 'Normal',
|
||||
in: {
|
||||
ID: 'test-allocation',
|
||||
JobID: 'test-summary',
|
||||
Name: 'test-summary[1]',
|
||||
Namespace: 'test-namespace',
|
||||
TaskGroup: 'test-group',
|
||||
CreateTime: +sampleDate * 1000000,
|
||||
ModifyTime: +sampleDate * 1000000,
|
||||
TaskStates: {
|
||||
testTask: {
|
||||
State: 'running',
|
||||
Failed: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-allocation',
|
||||
type: 'allocation',
|
||||
attributes: {
|
||||
taskGroupName: 'test-group',
|
||||
name: 'test-summary[1]',
|
||||
modifyTime: sampleDate,
|
||||
createTime: sampleDate,
|
||||
states: [
|
||||
{
|
||||
name: 'testTask',
|
||||
state: 'running',
|
||||
failed: false,
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-allocation',
|
||||
type: 'allocation',
|
||||
attributes: {
|
||||
taskGroupName: 'test-group',
|
||||
name: 'test-summary[1]',
|
||||
modifyTime: sampleDate,
|
||||
createTime: sampleDate,
|
||||
states: [
|
||||
{
|
||||
name: 'testTask',
|
||||
state: 'running',
|
||||
failed: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
followUpEvaluation: {
|
||||
data: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
followUpEvaluation: {
|
||||
data: null,
|
||||
},
|
||||
nextAllocation: {
|
||||
data: null,
|
||||
},
|
||||
previousAllocation: {
|
||||
data: null,
|
||||
},
|
||||
job: {
|
||||
data: {
|
||||
id: '["test-summary","test-namespace"]',
|
||||
type: 'job',
|
||||
nextAllocation: {
|
||||
data: null,
|
||||
},
|
||||
previousAllocation: {
|
||||
data: null,
|
||||
},
|
||||
job: {
|
||||
data: {
|
||||
id: '["test-summary","test-namespace"]',
|
||||
type: 'job',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: 'Dots in task names',
|
||||
in: {
|
||||
ID: 'test-allocation',
|
||||
JobID: 'test-summary',
|
||||
Name: 'test-summary[1]',
|
||||
Namespace: 'test-namespace',
|
||||
TaskGroup: 'test-group',
|
||||
CreateTime: +sampleDate * 1000000,
|
||||
ModifyTime: +sampleDate * 1000000,
|
||||
TaskStates: {
|
||||
'one.two': {
|
||||
State: 'running',
|
||||
Failed: false,
|
||||
},
|
||||
'three.four': {
|
||||
State: 'pending',
|
||||
Failed: true,
|
||||
{
|
||||
name: 'Dots in task names',
|
||||
in: {
|
||||
ID: 'test-allocation',
|
||||
JobID: 'test-summary',
|
||||
Name: 'test-summary[1]',
|
||||
Namespace: 'test-namespace',
|
||||
TaskGroup: 'test-group',
|
||||
CreateTime: +sampleDate * 1000000,
|
||||
ModifyTime: +sampleDate * 1000000,
|
||||
TaskStates: {
|
||||
'one.two': {
|
||||
State: 'running',
|
||||
Failed: false,
|
||||
},
|
||||
'three.four': {
|
||||
State: 'pending',
|
||||
Failed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-allocation',
|
||||
type: 'allocation',
|
||||
attributes: {
|
||||
taskGroupName: 'test-group',
|
||||
name: 'test-summary[1]',
|
||||
modifyTime: sampleDate,
|
||||
createTime: sampleDate,
|
||||
states: [
|
||||
{
|
||||
name: 'one.two',
|
||||
state: 'running',
|
||||
failed: false,
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-allocation',
|
||||
type: 'allocation',
|
||||
attributes: {
|
||||
taskGroupName: 'test-group',
|
||||
name: 'test-summary[1]',
|
||||
modifyTime: sampleDate,
|
||||
createTime: sampleDate,
|
||||
states: [
|
||||
{
|
||||
name: 'one.two',
|
||||
state: 'running',
|
||||
failed: false,
|
||||
},
|
||||
{
|
||||
name: 'three.four',
|
||||
state: 'pending',
|
||||
failed: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
followUpEvaluation: {
|
||||
data: null,
|
||||
},
|
||||
{
|
||||
name: 'three.four',
|
||||
state: 'pending',
|
||||
failed: true,
|
||||
nextAllocation: {
|
||||
data: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
followUpEvaluation: {
|
||||
data: null,
|
||||
},
|
||||
nextAllocation: {
|
||||
data: null,
|
||||
},
|
||||
previousAllocation: {
|
||||
data: null,
|
||||
},
|
||||
job: {
|
||||
data: {
|
||||
id: '["test-summary","test-namespace"]',
|
||||
type: 'job',
|
||||
previousAllocation: {
|
||||
data: null,
|
||||
},
|
||||
job: {
|
||||
data: {
|
||||
id: '["test-summary","test-namespace"]',
|
||||
type: 'job',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
];
|
||||
|
||||
normalizationTestCases.forEach(testCase => {
|
||||
test(`normalization: ${testCase.name}`, function(assert) {
|
||||
assert.deepEqual(this.subject().normalize(AllocationModel, testCase.in), testCase.out);
|
||||
normalizationTestCases.forEach(testCase => {
|
||||
test(`normalization: ${testCase.name}`, function(assert) {
|
||||
assert.deepEqual(this.subject().normalize(AllocationModel, testCase.in), testCase.out);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,129 +1,127 @@
|
||||
import { test } from 'qunit';
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import DeploymentModel from 'nomad-ui/models/deployment';
|
||||
import moduleForSerializer from '../../helpers/module-for-serializer';
|
||||
|
||||
moduleForSerializer('deployment', 'Unit | Serializer | Deployment', {
|
||||
needs: [
|
||||
'adapter:application',
|
||||
'serializer:deployment',
|
||||
'service:system',
|
||||
'service:token',
|
||||
'transform:fragment-array',
|
||||
'model:allocation',
|
||||
'model:job',
|
||||
'model:task-group-deployment-summary',
|
||||
],
|
||||
});
|
||||
module('Unit | Serializer | Deployment', function(hooks) {
|
||||
setupTest(hooks);
|
||||
hooks.beforeEach(function() {
|
||||
this.store = this.owner.lookup('service:store');
|
||||
this.subject = () => this.store.serializerFor('deployment');
|
||||
});
|
||||
|
||||
const normalizationTestCases = [
|
||||
{
|
||||
name: 'Normal',
|
||||
in: {
|
||||
ID: 'test-deployment',
|
||||
JobID: 'test-job',
|
||||
Namespace: 'test-namespace',
|
||||
Status: 'canceled',
|
||||
TaskGroups: {
|
||||
taskGroup: {
|
||||
DesiredCanaries: 2,
|
||||
const normalizationTestCases = [
|
||||
{
|
||||
name: 'Normal',
|
||||
in: {
|
||||
ID: 'test-deployment',
|
||||
JobID: 'test-job',
|
||||
Namespace: 'test-namespace',
|
||||
Status: 'canceled',
|
||||
TaskGroups: {
|
||||
taskGroup: {
|
||||
DesiredCanaries: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-deployment',
|
||||
type: 'deployment',
|
||||
attributes: {
|
||||
status: 'canceled',
|
||||
taskGroupSummaries: [
|
||||
{
|
||||
name: 'taskGroup',
|
||||
desiredCanaries: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
allocations: {
|
||||
links: {
|
||||
related: '/v1/deployment/allocations/test-deployment',
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-deployment',
|
||||
type: 'deployment',
|
||||
attributes: {
|
||||
status: 'canceled',
|
||||
taskGroupSummaries: [
|
||||
{
|
||||
name: 'taskGroup',
|
||||
desiredCanaries: 2,
|
||||
placedCanaryAllocations: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
job: {
|
||||
data: {
|
||||
id: '["test-job","test-namespace"]',
|
||||
type: 'job',
|
||||
relationships: {
|
||||
allocations: {
|
||||
links: {
|
||||
related: '/v1/deployment/allocations/test-deployment',
|
||||
},
|
||||
},
|
||||
},
|
||||
jobForLatest: {
|
||||
data: {
|
||||
id: '["test-job","test-namespace"]',
|
||||
type: 'job',
|
||||
job: {
|
||||
data: {
|
||||
id: '["test-job","test-namespace"]',
|
||||
type: 'job',
|
||||
},
|
||||
},
|
||||
jobForLatest: {
|
||||
data: {
|
||||
id: '["test-job","test-namespace"]',
|
||||
type: 'job',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: 'Dots in task group names',
|
||||
in: {
|
||||
ID: 'test-deployment',
|
||||
JobID: 'test-job',
|
||||
Namespace: 'test-namespace',
|
||||
Status: 'canceled',
|
||||
TaskGroups: {
|
||||
'one.two': {
|
||||
DesiredCanaries: 2,
|
||||
},
|
||||
'three.four': {
|
||||
DesiredCanaries: 3,
|
||||
{
|
||||
name: 'Dots in task group names',
|
||||
in: {
|
||||
ID: 'test-deployment',
|
||||
JobID: 'test-job',
|
||||
Namespace: 'test-namespace',
|
||||
Status: 'canceled',
|
||||
TaskGroups: {
|
||||
'one.two': {
|
||||
DesiredCanaries: 2,
|
||||
},
|
||||
'three.four': {
|
||||
DesiredCanaries: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-deployment',
|
||||
type: 'deployment',
|
||||
attributes: {
|
||||
status: 'canceled',
|
||||
taskGroupSummaries: [
|
||||
{
|
||||
name: 'one.two',
|
||||
desiredCanaries: 2,
|
||||
},
|
||||
{
|
||||
name: 'three.four',
|
||||
desiredCanaries: 3,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
allocations: {
|
||||
links: {
|
||||
related: '/v1/deployment/allocations/test-deployment',
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-deployment',
|
||||
type: 'deployment',
|
||||
attributes: {
|
||||
status: 'canceled',
|
||||
taskGroupSummaries: [
|
||||
{
|
||||
name: 'one.two',
|
||||
desiredCanaries: 2,
|
||||
placedCanaryAllocations: [],
|
||||
},
|
||||
{
|
||||
name: 'three.four',
|
||||
desiredCanaries: 3,
|
||||
placedCanaryAllocations: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
job: {
|
||||
data: {
|
||||
id: '["test-job","test-namespace"]',
|
||||
type: 'job',
|
||||
relationships: {
|
||||
allocations: {
|
||||
links: {
|
||||
related: '/v1/deployment/allocations/test-deployment',
|
||||
},
|
||||
},
|
||||
},
|
||||
jobForLatest: {
|
||||
data: {
|
||||
id: '["test-job","test-namespace"]',
|
||||
type: 'job',
|
||||
job: {
|
||||
data: {
|
||||
id: '["test-job","test-namespace"]',
|
||||
type: 'job',
|
||||
},
|
||||
},
|
||||
jobForLatest: {
|
||||
data: {
|
||||
id: '["test-job","test-namespace"]',
|
||||
type: 'job',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
];
|
||||
|
||||
normalizationTestCases.forEach(testCase => {
|
||||
test(`normalization: ${testCase.name}`, function(assert) {
|
||||
assert.deepEqual(this.subject().normalize(DeploymentModel, testCase.in), testCase.out);
|
||||
normalizationTestCases.forEach(testCase => {
|
||||
test(`normalization: ${testCase.name}`, function(assert) {
|
||||
assert.deepEqual(this.subject().normalize(DeploymentModel, testCase.in), testCase.out);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,104 +1,102 @@
|
||||
import { test } from 'qunit';
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import EvaluationModel from 'nomad-ui/models/evaluation';
|
||||
import moduleForSerializer from '../../helpers/module-for-serializer';
|
||||
|
||||
moduleForSerializer('evaluation', 'Unit | Serializer | Evaluation', {
|
||||
needs: [
|
||||
'serializer:evaluation',
|
||||
'service:system',
|
||||
'transform:fragment-array',
|
||||
'model:job',
|
||||
'model:placement-failure',
|
||||
],
|
||||
});
|
||||
module('Unit | Serializer | Evaluation', function(hooks) {
|
||||
setupTest(hooks);
|
||||
hooks.beforeEach(function() {
|
||||
this.store = this.owner.lookup('service:store');
|
||||
this.subject = () => this.store.serializerFor('evaluation');
|
||||
});
|
||||
|
||||
const normalizationTestCases = [
|
||||
{
|
||||
name: 'Normal',
|
||||
in: {
|
||||
ID: 'test-eval',
|
||||
FailedTGAllocs: {
|
||||
taskGroup: {
|
||||
NodesAvailable: 10,
|
||||
const normalizationTestCases = [
|
||||
{
|
||||
name: 'Normal',
|
||||
in: {
|
||||
ID: 'test-eval',
|
||||
FailedTGAllocs: {
|
||||
taskGroup: {
|
||||
NodesAvailable: 10,
|
||||
},
|
||||
},
|
||||
JobID: 'some-job-id',
|
||||
Job: {
|
||||
Namespace: 'test-namespace',
|
||||
},
|
||||
},
|
||||
JobID: 'some-job-id',
|
||||
Job: {
|
||||
Namespace: 'test-namespace',
|
||||
},
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-eval',
|
||||
type: 'evaluation',
|
||||
attributes: {
|
||||
failedTGAllocs: [
|
||||
{
|
||||
name: 'taskGroup',
|
||||
nodesAvailable: 10,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
job: {
|
||||
data: {
|
||||
id: '["some-job-id","test-namespace"]',
|
||||
type: 'job',
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-eval',
|
||||
type: 'evaluation',
|
||||
attributes: {
|
||||
failedTGAllocs: [
|
||||
{
|
||||
name: 'taskGroup',
|
||||
nodesAvailable: 10,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
job: {
|
||||
data: {
|
||||
id: '["some-job-id","test-namespace"]',
|
||||
type: 'job',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: 'Dots in task group names',
|
||||
in: {
|
||||
ID: 'test-eval',
|
||||
FailedTGAllocs: {
|
||||
'one.two': {
|
||||
NodesAvailable: 10,
|
||||
{
|
||||
name: 'Dots in task group names',
|
||||
in: {
|
||||
ID: 'test-eval',
|
||||
FailedTGAllocs: {
|
||||
'one.two': {
|
||||
NodesAvailable: 10,
|
||||
},
|
||||
'three.four': {
|
||||
NodesAvailable: 25,
|
||||
},
|
||||
},
|
||||
'three.four': {
|
||||
NodesAvailable: 25,
|
||||
JobID: 'some-job-id',
|
||||
Job: {
|
||||
Namespace: 'test-namespace',
|
||||
},
|
||||
},
|
||||
JobID: 'some-job-id',
|
||||
Job: {
|
||||
Namespace: 'test-namespace',
|
||||
},
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-eval',
|
||||
type: 'evaluation',
|
||||
attributes: {
|
||||
failedTGAllocs: [
|
||||
{
|
||||
name: 'one.two',
|
||||
nodesAvailable: 10,
|
||||
},
|
||||
{
|
||||
name: 'three.four',
|
||||
nodesAvailable: 25,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
job: {
|
||||
data: {
|
||||
id: '["some-job-id","test-namespace"]',
|
||||
type: 'job',
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-eval',
|
||||
type: 'evaluation',
|
||||
attributes: {
|
||||
failedTGAllocs: [
|
||||
{
|
||||
name: 'one.two',
|
||||
nodesAvailable: 10,
|
||||
},
|
||||
{
|
||||
name: 'three.four',
|
||||
nodesAvailable: 25,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
job: {
|
||||
data: {
|
||||
id: '["some-job-id","test-namespace"]',
|
||||
type: 'job',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
];
|
||||
|
||||
normalizationTestCases.forEach(testCase => {
|
||||
test(`normalization: ${testCase.name}`, function(assert) {
|
||||
assert.deepEqual(this.subject().normalize(EvaluationModel, testCase.in), testCase.out);
|
||||
normalizationTestCases.forEach(testCase => {
|
||||
test(`normalization: ${testCase.name}`, function(assert) {
|
||||
assert.deepEqual(this.subject().normalize(EvaluationModel, testCase.in), testCase.out);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,94 +1,92 @@
|
||||
import { test } from 'qunit';
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import JobPlanModel from 'nomad-ui/models/job-plan';
|
||||
import moduleForSerializer from '../../helpers/module-for-serializer';
|
||||
|
||||
moduleForSerializer('job-plan', 'Unit | Serializer | JobPlan', {
|
||||
needs: [
|
||||
'service:token',
|
||||
'service:system',
|
||||
'serializer:job-plan',
|
||||
'transform:fragment-array',
|
||||
'model:placement-failure',
|
||||
],
|
||||
});
|
||||
module('Unit | Serializer | JobPlan', function(hooks) {
|
||||
setupTest(hooks);
|
||||
hooks.beforeEach(function() {
|
||||
this.store = this.owner.lookup('service:store');
|
||||
this.subject = () => this.store.serializerFor('job-plan');
|
||||
});
|
||||
|
||||
const normalizationTestCases = [
|
||||
{
|
||||
name: 'Normal',
|
||||
in: {
|
||||
ID: 'test-plan',
|
||||
Diff: {
|
||||
Arbitrary: 'Value',
|
||||
},
|
||||
FailedTGAllocs: {
|
||||
taskGroup: {
|
||||
NodesAvailable: 10,
|
||||
const normalizationTestCases = [
|
||||
{
|
||||
name: 'Normal',
|
||||
in: {
|
||||
ID: 'test-plan',
|
||||
Diff: {
|
||||
Arbitrary: 'Value',
|
||||
},
|
||||
},
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-plan',
|
||||
type: 'job-plan',
|
||||
attributes: {
|
||||
diff: {
|
||||
Arbitrary: 'Value',
|
||||
FailedTGAllocs: {
|
||||
taskGroup: {
|
||||
NodesAvailable: 10,
|
||||
},
|
||||
failedTGAllocs: [
|
||||
{
|
||||
name: 'taskGroup',
|
||||
nodesAvailable: 10,
|
||||
},
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-plan',
|
||||
type: 'job-plan',
|
||||
attributes: {
|
||||
diff: {
|
||||
Arbitrary: 'Value',
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: 'Dots in task names',
|
||||
in: {
|
||||
ID: 'test-plan',
|
||||
Diff: {
|
||||
Arbitrary: 'Value',
|
||||
},
|
||||
FailedTGAllocs: {
|
||||
'one.two': {
|
||||
NodesAvailable: 10,
|
||||
},
|
||||
'three.four': {
|
||||
NodesAvailable: 25,
|
||||
},
|
||||
},
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-plan',
|
||||
type: 'job-plan',
|
||||
attributes: {
|
||||
diff: {
|
||||
Arbitrary: 'Value',
|
||||
failedTGAllocs: [
|
||||
{
|
||||
name: 'taskGroup',
|
||||
nodesAvailable: 10,
|
||||
},
|
||||
],
|
||||
},
|
||||
failedTGAllocs: [
|
||||
{
|
||||
name: 'one.two',
|
||||
nodesAvailable: 10,
|
||||
},
|
||||
{
|
||||
name: 'three.four',
|
||||
nodesAvailable: 25,
|
||||
},
|
||||
],
|
||||
relationships: {},
|
||||
},
|
||||
relationships: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
normalizationTestCases.forEach(testCase => {
|
||||
test(`normalization: ${testCase.name}`, function(assert) {
|
||||
assert.deepEqual(this.subject().normalize(JobPlanModel, testCase.in), testCase.out);
|
||||
{
|
||||
name: 'Dots in task names',
|
||||
in: {
|
||||
ID: 'test-plan',
|
||||
Diff: {
|
||||
Arbitrary: 'Value',
|
||||
},
|
||||
FailedTGAllocs: {
|
||||
'one.two': {
|
||||
NodesAvailable: 10,
|
||||
},
|
||||
'three.four': {
|
||||
NodesAvailable: 25,
|
||||
},
|
||||
},
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-plan',
|
||||
type: 'job-plan',
|
||||
attributes: {
|
||||
diff: {
|
||||
Arbitrary: 'Value',
|
||||
},
|
||||
failedTGAllocs: [
|
||||
{
|
||||
name: 'one.two',
|
||||
nodesAvailable: 10,
|
||||
},
|
||||
{
|
||||
name: 'three.four',
|
||||
nodesAvailable: 25,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
normalizationTestCases.forEach(testCase => {
|
||||
test(`normalization: ${testCase.name}`, function(assert) {
|
||||
assert.deepEqual(this.subject().normalize(JobPlanModel, testCase.in), testCase.out);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,103 +1,102 @@
|
||||
import { test } from 'qunit';
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import JobSummaryModel from 'nomad-ui/models/job-summary';
|
||||
import moduleForSerializer from '../../helpers/module-for-serializer';
|
||||
|
||||
moduleForSerializer('job-summary', 'Unit | Serializer | JobSummary', {
|
||||
needs: [
|
||||
'serializer:job-summary',
|
||||
'transform:fragment-array',
|
||||
'model:job',
|
||||
'model:task-group-summary',
|
||||
],
|
||||
});
|
||||
module('Unit | Serializer | JobSummary', function(hooks) {
|
||||
setupTest(hooks);
|
||||
hooks.beforeEach(function() {
|
||||
this.store = this.owner.lookup('service:store');
|
||||
this.subject = () => this.store.serializerFor('job-summary');
|
||||
});
|
||||
|
||||
const normalizationTestCases = [
|
||||
{
|
||||
name: 'Normal',
|
||||
in: {
|
||||
JobID: 'test-summary',
|
||||
Namespace: 'test-namespace',
|
||||
Summary: {
|
||||
taskGroup: {
|
||||
Complete: 0,
|
||||
Running: 1,
|
||||
const normalizationTestCases = [
|
||||
{
|
||||
name: 'Normal',
|
||||
in: {
|
||||
JobID: 'test-summary',
|
||||
Namespace: 'test-namespace',
|
||||
Summary: {
|
||||
taskGroup: {
|
||||
Complete: 0,
|
||||
Running: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: '["test-summary","test-namespace"]',
|
||||
type: 'job-summary',
|
||||
attributes: {
|
||||
taskGroupSummaries: [
|
||||
{
|
||||
name: 'taskGroup',
|
||||
completeAllocs: 0,
|
||||
runningAllocs: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
job: {
|
||||
data: {
|
||||
id: '["test-summary","test-namespace"]',
|
||||
type: 'job',
|
||||
out: {
|
||||
data: {
|
||||
id: '["test-summary","test-namespace"]',
|
||||
type: 'job-summary',
|
||||
attributes: {
|
||||
taskGroupSummaries: [
|
||||
{
|
||||
name: 'taskGroup',
|
||||
completeAllocs: 0,
|
||||
runningAllocs: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
job: {
|
||||
data: {
|
||||
id: '["test-summary","test-namespace"]',
|
||||
type: 'job',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: 'Dots in task group names',
|
||||
in: {
|
||||
JobID: 'test-summary',
|
||||
Namespace: 'test-namespace',
|
||||
Summary: {
|
||||
'one.two': {
|
||||
Complete: 0,
|
||||
Running: 1,
|
||||
},
|
||||
'three.four': {
|
||||
Failed: 2,
|
||||
Lost: 3,
|
||||
{
|
||||
name: 'Dots in task group names',
|
||||
in: {
|
||||
JobID: 'test-summary',
|
||||
Namespace: 'test-namespace',
|
||||
Summary: {
|
||||
'one.two': {
|
||||
Complete: 0,
|
||||
Running: 1,
|
||||
},
|
||||
'three.four': {
|
||||
Failed: 2,
|
||||
Lost: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: '["test-summary","test-namespace"]',
|
||||
type: 'job-summary',
|
||||
attributes: {
|
||||
taskGroupSummaries: [
|
||||
{
|
||||
name: 'one.two',
|
||||
completeAllocs: 0,
|
||||
runningAllocs: 1,
|
||||
},
|
||||
{
|
||||
name: 'three.four',
|
||||
failedAllocs: 2,
|
||||
lostAllocs: 3,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
job: {
|
||||
data: {
|
||||
id: '["test-summary","test-namespace"]',
|
||||
type: 'job',
|
||||
out: {
|
||||
data: {
|
||||
id: '["test-summary","test-namespace"]',
|
||||
type: 'job-summary',
|
||||
attributes: {
|
||||
taskGroupSummaries: [
|
||||
{
|
||||
name: 'one.two',
|
||||
completeAllocs: 0,
|
||||
runningAllocs: 1,
|
||||
},
|
||||
{
|
||||
name: 'three.four',
|
||||
failedAllocs: 2,
|
||||
lostAllocs: 3,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
job: {
|
||||
data: {
|
||||
id: '["test-summary","test-namespace"]',
|
||||
type: 'job',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
];
|
||||
|
||||
normalizationTestCases.forEach(testCase => {
|
||||
test(`normalization: ${testCase.name}`, function(assert) {
|
||||
assert.deepEqual(this.subject().normalize(JobSummaryModel, testCase.in), testCase.out);
|
||||
normalizationTestCases.forEach(testCase => {
|
||||
test(`normalization: ${testCase.name}`, function(assert) {
|
||||
assert.deepEqual(this.subject().normalize(JobSummaryModel, testCase.in), testCase.out);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,36 +1,35 @@
|
||||
import { test } from 'qunit';
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import JobModel from 'nomad-ui/models/job';
|
||||
import moduleForSerializer from '../../helpers/module-for-serializer';
|
||||
|
||||
moduleForSerializer('job', 'Unit | Serializer | Job', {
|
||||
needs: [
|
||||
'serializer:job',
|
||||
'model:task-group-summary',
|
||||
'model:task-group',
|
||||
'transform:fragment-array',
|
||||
],
|
||||
});
|
||||
|
||||
test('`default` is used as the namespace in the job ID when there is no namespace in the payload', function(assert) {
|
||||
const original = {
|
||||
ID: 'example',
|
||||
Name: 'example',
|
||||
};
|
||||
|
||||
const { data } = this.subject().normalize(JobModel, original);
|
||||
assert.equal(data.id, JSON.stringify([data.attributes.name, 'default']));
|
||||
});
|
||||
|
||||
test('The ID of the record is a composite of both the name and the namespace', function(assert) {
|
||||
const original = {
|
||||
ID: 'example',
|
||||
Name: 'example',
|
||||
Namespace: 'special-namespace',
|
||||
};
|
||||
|
||||
const { data } = this.subject().normalize(JobModel, original);
|
||||
assert.equal(
|
||||
data.id,
|
||||
JSON.stringify([data.attributes.name, data.relationships.namespace.data.id])
|
||||
);
|
||||
module('Unit | Serializer | Job', function(hooks) {
|
||||
setupTest(hooks);
|
||||
hooks.beforeEach(function() {
|
||||
this.store = this.owner.lookup('service:store');
|
||||
this.subject = () => this.store.serializerFor('job');
|
||||
});
|
||||
|
||||
test('`default` is used as the namespace in the job ID when there is no namespace in the payload', function(assert) {
|
||||
const original = {
|
||||
ID: 'example',
|
||||
Name: 'example',
|
||||
};
|
||||
|
||||
const { data } = this.subject().normalize(JobModel, original);
|
||||
assert.equal(data.id, JSON.stringify([data.attributes.name, 'default']));
|
||||
});
|
||||
|
||||
test('The ID of the record is a composite of both the name and the namespace', function(assert) {
|
||||
const original = {
|
||||
ID: 'example',
|
||||
Name: 'example',
|
||||
Namespace: 'special-namespace',
|
||||
};
|
||||
|
||||
const { data } = this.subject().normalize(JobModel, original);
|
||||
assert.equal(
|
||||
data.id,
|
||||
JSON.stringify([data.attributes.name, data.relationships.namespace.data.id])
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,71 +1,31 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import { run } from '@ember/runloop';
|
||||
import { test } from 'qunit';
|
||||
import NodeModel from 'nomad-ui/models/node';
|
||||
import moduleForSerializer from '../../helpers/module-for-serializer';
|
||||
import pushPayloadToStore from '../../utils/push-payload-to-store';
|
||||
import { settled } from '@ember/test-helpers';
|
||||
|
||||
moduleForSerializer('node', 'Unit | Serializer | Node', {
|
||||
needs: [
|
||||
'adapter:application',
|
||||
'service:config',
|
||||
'serializer:node',
|
||||
'service:system',
|
||||
'service:token',
|
||||
'transform:fragment',
|
||||
'transform:fragment-array',
|
||||
'model:node-attributes',
|
||||
'model:resources',
|
||||
'model:drain-strategy',
|
||||
'model:node-driver',
|
||||
'model:node-event',
|
||||
'model:allocation',
|
||||
'model:job',
|
||||
],
|
||||
});
|
||||
|
||||
test('local store is culled to reflect the state of findAll requests', function(assert) {
|
||||
const findAllResponse = [
|
||||
makeNode('1', 'One', '127.0.0.1:4646'),
|
||||
makeNode('2', 'Two', '127.0.0.2:4646'),
|
||||
makeNode('3', 'Three', '127.0.0.3:4646'),
|
||||
];
|
||||
|
||||
const payload = this.subject().normalizeFindAllResponse(this.store, NodeModel, findAllResponse);
|
||||
pushPayloadToStore(this.store, payload, NodeModel.modelName);
|
||||
|
||||
assert.equal(
|
||||
payload.data.length,
|
||||
findAllResponse.length,
|
||||
'Each original record is returned in the response'
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
this.store
|
||||
.peekAll('node')
|
||||
.filterBy('id')
|
||||
.get('length'),
|
||||
findAllResponse.length,
|
||||
'Each original record is now in the store'
|
||||
);
|
||||
|
||||
const newFindAllResponse = [
|
||||
makeNode('2', 'Two', '127.0.0.2:4646'),
|
||||
makeNode('3', 'Three', '127.0.0.3:4646'),
|
||||
makeNode('4', 'Four', '127.0.0.4:4646'),
|
||||
];
|
||||
|
||||
let newPayload;
|
||||
run(() => {
|
||||
newPayload = this.subject().normalizeFindAllResponse(this.store, NodeModel, newFindAllResponse);
|
||||
module('Unit | Serializer | Node', function(hooks) {
|
||||
setupTest(hooks);
|
||||
hooks.beforeEach(function() {
|
||||
this.store = this.owner.lookup('service:store');
|
||||
this.subject = () => this.store.serializerFor('node');
|
||||
});
|
||||
pushPayloadToStore(this.store, newPayload, NodeModel.modelName);
|
||||
|
||||
return settled().then(() => {
|
||||
test('local store is culled to reflect the state of findAll requests', function(assert) {
|
||||
const findAllResponse = [
|
||||
makeNode('1', 'One', '127.0.0.1:4646'),
|
||||
makeNode('2', 'Two', '127.0.0.2:4646'),
|
||||
makeNode('3', 'Three', '127.0.0.3:4646'),
|
||||
];
|
||||
|
||||
const payload = this.subject().normalizeFindAllResponse(this.store, NodeModel, findAllResponse);
|
||||
pushPayloadToStore(this.store, payload, NodeModel.modelName);
|
||||
|
||||
assert.equal(
|
||||
newPayload.data.length,
|
||||
newFindAllResponse.length,
|
||||
'Each new record is returned in the response'
|
||||
payload.data.length,
|
||||
findAllResponse.length,
|
||||
'Each original record is returned in the response'
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
@@ -73,109 +33,142 @@ test('local store is culled to reflect the state of findAll requests', function(
|
||||
.peekAll('node')
|
||||
.filterBy('id')
|
||||
.get('length'),
|
||||
newFindAllResponse.length,
|
||||
'The node length in the store reflects the new response'
|
||||
findAllResponse.length,
|
||||
'Each original record is now in the store'
|
||||
);
|
||||
|
||||
assert.notOk(this.store.peekAll('node').findBy('id', '1'), 'Record One is no longer found');
|
||||
const newFindAllResponse = [
|
||||
makeNode('2', 'Two', '127.0.0.2:4646'),
|
||||
makeNode('3', 'Three', '127.0.0.3:4646'),
|
||||
makeNode('4', 'Four', '127.0.0.4:4646'),
|
||||
];
|
||||
|
||||
let newPayload;
|
||||
run(() => {
|
||||
newPayload = this.subject().normalizeFindAllResponse(
|
||||
this.store,
|
||||
NodeModel,
|
||||
newFindAllResponse
|
||||
);
|
||||
});
|
||||
pushPayloadToStore(this.store, newPayload, NodeModel.modelName);
|
||||
|
||||
return settled().then(() => {
|
||||
assert.equal(
|
||||
newPayload.data.length,
|
||||
newFindAllResponse.length,
|
||||
'Each new record is returned in the response'
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
this.store
|
||||
.peekAll('node')
|
||||
.filterBy('id')
|
||||
.get('length'),
|
||||
newFindAllResponse.length,
|
||||
'The node length in the store reflects the new response'
|
||||
);
|
||||
|
||||
assert.notOk(this.store.peekAll('node').findBy('id', '1'), 'Record One is no longer found');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function makeNode(id, name, ip) {
|
||||
return { ID: id, Name: name, HTTPAddr: ip };
|
||||
}
|
||||
function makeNode(id, name, ip) {
|
||||
return { ID: id, Name: name, HTTPAddr: ip };
|
||||
}
|
||||
|
||||
const normalizationTestCases = [
|
||||
{
|
||||
name: 'Normal',
|
||||
in: {
|
||||
ID: 'test-node',
|
||||
HTTPAddr: '867.53.0.9:4646',
|
||||
Drain: false,
|
||||
Drivers: {
|
||||
docker: {
|
||||
Detected: true,
|
||||
Healthy: false,
|
||||
const normalizationTestCases = [
|
||||
{
|
||||
name: 'Normal',
|
||||
in: {
|
||||
ID: 'test-node',
|
||||
HTTPAddr: '867.53.0.9:4646',
|
||||
Drain: false,
|
||||
Drivers: {
|
||||
docker: {
|
||||
Detected: true,
|
||||
Healthy: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-node',
|
||||
type: 'node',
|
||||
attributes: {
|
||||
isDraining: false,
|
||||
httpAddr: '867.53.0.9:4646',
|
||||
drivers: [
|
||||
{
|
||||
name: 'docker',
|
||||
detected: true,
|
||||
healthy: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
allocations: {
|
||||
links: {
|
||||
related: '/v1/node/test-node/allocations',
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-node',
|
||||
type: 'node',
|
||||
attributes: {
|
||||
isDraining: false,
|
||||
httpAddr: '867.53.0.9:4646',
|
||||
drivers: [
|
||||
{
|
||||
name: 'docker',
|
||||
detected: true,
|
||||
healthy: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
allocations: {
|
||||
links: {
|
||||
related: '/v1/node/test-node/allocations',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: 'Dots in driver names',
|
||||
in: {
|
||||
ID: 'test-node',
|
||||
HTTPAddr: '867.53.0.9:4646',
|
||||
Drain: false,
|
||||
Drivers: {
|
||||
'my.driver': {
|
||||
Detected: true,
|
||||
Healthy: false,
|
||||
},
|
||||
'my.other.driver': {
|
||||
Detected: false,
|
||||
Healthy: false,
|
||||
{
|
||||
name: 'Dots in driver names',
|
||||
in: {
|
||||
ID: 'test-node',
|
||||
HTTPAddr: '867.53.0.9:4646',
|
||||
Drain: false,
|
||||
Drivers: {
|
||||
'my.driver': {
|
||||
Detected: true,
|
||||
Healthy: false,
|
||||
},
|
||||
'my.other.driver': {
|
||||
Detected: false,
|
||||
Healthy: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-node',
|
||||
type: 'node',
|
||||
attributes: {
|
||||
isDraining: false,
|
||||
httpAddr: '867.53.0.9:4646',
|
||||
drivers: [
|
||||
{
|
||||
name: 'my.driver',
|
||||
detected: true,
|
||||
healthy: false,
|
||||
},
|
||||
{
|
||||
name: 'my.other.driver',
|
||||
detected: false,
|
||||
healthy: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
allocations: {
|
||||
links: {
|
||||
related: '/v1/node/test-node/allocations',
|
||||
out: {
|
||||
data: {
|
||||
id: 'test-node',
|
||||
type: 'node',
|
||||
attributes: {
|
||||
isDraining: false,
|
||||
httpAddr: '867.53.0.9:4646',
|
||||
drivers: [
|
||||
{
|
||||
name: 'my.driver',
|
||||
detected: true,
|
||||
healthy: false,
|
||||
},
|
||||
{
|
||||
name: 'my.other.driver',
|
||||
detected: false,
|
||||
healthy: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
relationships: {
|
||||
allocations: {
|
||||
links: {
|
||||
related: '/v1/node/test-node/allocations',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
];
|
||||
|
||||
normalizationTestCases.forEach(testCase => {
|
||||
test(`normalization: ${testCase.name}`, function(assert) {
|
||||
assert.deepEqual(this.subject().normalize(NodeModel, testCase.in), testCase.out);
|
||||
normalizationTestCases.forEach(testCase => {
|
||||
test(`normalization: ${testCase.name}`, function(assert) {
|
||||
assert.deepEqual(this.subject().normalize(NodeModel, testCase.in), testCase.out);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user