mirror of
https://github.com/kemko/nomad.git
synced 2026-01-08 11:25:41 +03:00
Don't use Ember.get in conjunction with dynamic strings in the deployment serializer
This commit is contained in:
@@ -9,8 +9,9 @@ export default ApplicationSerializer.extend({
|
||||
|
||||
normalize(typeHash, hash) {
|
||||
if (hash) {
|
||||
hash.TaskGroupSummaries = Object.keys(get(hash, 'TaskGroups') || {}).map(key => {
|
||||
const deploymentStats = get(hash, `TaskGroups.${key}`);
|
||||
const taskGroups = hash.TaskGroups || {};
|
||||
hash.TaskGroupSummaries = Object.keys(taskGroups).map(key => {
|
||||
const deploymentStats = taskGroups[key];
|
||||
return assign({ Name: key }, deploymentStats);
|
||||
});
|
||||
|
||||
|
||||
129
ui/tests/unit/serializers/deployment-test.js
Normal file
129
ui/tests/unit/serializers/deployment-test.js
Normal file
@@ -0,0 +1,129 @@
|
||||
import { test } 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',
|
||||
],
|
||||
});
|
||||
|
||||
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',
|
||||
},
|
||||
},
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
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',
|
||||
},
|
||||
},
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user