github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/ui/tests/unit/serializers/allocation-test.js (about)

     1  import { module, test } from 'qunit';
     2  import { setupTest } from 'ember-qunit';
     3  import AllocationModel from 'nomad-ui/models/allocation';
     4  
     5  module('Unit | Serializer | Allocation', function(hooks) {
     6    setupTest(hooks);
     7    hooks.beforeEach(function() {
     8      this.store = this.owner.lookup('service:store');
     9      this.subject = () => this.store.serializerFor('allocation');
    10    });
    11  
    12    const sampleDate = new Date('2018-12-12T00:00:00');
    13    const normalizationTestCases = [
    14      {
    15        name: 'Normal',
    16        in: {
    17          ID: 'test-allocation',
    18          JobID: 'test-summary',
    19          Name: 'test-summary[1]',
    20          Namespace: 'test-namespace',
    21          TaskGroup: 'test-group',
    22          CreateTime: +sampleDate * 1000000,
    23          ModifyTime: +sampleDate * 1000000,
    24          TaskStates: {
    25            testTask: {
    26              State: 'running',
    27              Failed: false,
    28            },
    29          },
    30        },
    31        out: {
    32          data: {
    33            id: 'test-allocation',
    34            type: 'allocation',
    35            attributes: {
    36              taskGroupName: 'test-group',
    37              name: 'test-summary[1]',
    38              modifyTime: sampleDate,
    39              createTime: sampleDate,
    40              states: [
    41                {
    42                  name: 'testTask',
    43                  state: 'running',
    44                  failed: false,
    45                },
    46              ],
    47              wasPreempted: false,
    48            },
    49            relationships: {
    50              followUpEvaluation: {
    51                data: null,
    52              },
    53              nextAllocation: {
    54                data: null,
    55              },
    56              previousAllocation: {
    57                data: null,
    58              },
    59              preemptedAllocations: {
    60                data: [],
    61              },
    62              preemptedByAllocation: {
    63                data: null,
    64              },
    65              job: {
    66                data: {
    67                  id: '["test-summary","test-namespace"]',
    68                  type: 'job',
    69                },
    70              },
    71            },
    72          },
    73        },
    74      },
    75  
    76      {
    77        name: 'Dots in task names',
    78        in: {
    79          ID: 'test-allocation',
    80          JobID: 'test-summary',
    81          Name: 'test-summary[1]',
    82          Namespace: 'test-namespace',
    83          TaskGroup: 'test-group',
    84          CreateTime: +sampleDate * 1000000,
    85          ModifyTime: +sampleDate * 1000000,
    86          TaskStates: {
    87            'one.two': {
    88              State: 'running',
    89              Failed: false,
    90            },
    91            'three.four': {
    92              State: 'pending',
    93              Failed: true,
    94            },
    95          },
    96        },
    97        out: {
    98          data: {
    99            id: 'test-allocation',
   100            type: 'allocation',
   101            attributes: {
   102              taskGroupName: 'test-group',
   103              name: 'test-summary[1]',
   104              modifyTime: sampleDate,
   105              createTime: sampleDate,
   106              states: [
   107                {
   108                  name: 'one.two',
   109                  state: 'running',
   110                  failed: false,
   111                },
   112                {
   113                  name: 'three.four',
   114                  state: 'pending',
   115                  failed: true,
   116                },
   117              ],
   118              wasPreempted: false,
   119            },
   120            relationships: {
   121              followUpEvaluation: {
   122                data: null,
   123              },
   124              nextAllocation: {
   125                data: null,
   126              },
   127              previousAllocation: {
   128                data: null,
   129              },
   130              preemptedAllocations: {
   131                data: [],
   132              },
   133              preemptedByAllocation: {
   134                data: null,
   135              },
   136              job: {
   137                data: {
   138                  id: '["test-summary","test-namespace"]',
   139                  type: 'job',
   140                },
   141              },
   142            },
   143          },
   144        },
   145      },
   146  
   147      {
   148        name: 'With preemptions',
   149        in: {
   150          ID: 'test-allocation',
   151          JobID: 'test-summary',
   152          Name: 'test-summary[1]',
   153          Namespace: 'test-namespace',
   154          TaskGroup: 'test-group',
   155          CreateTime: +sampleDate * 1000000,
   156          ModifyTime: +sampleDate * 1000000,
   157          TaskStates: {
   158            task: {
   159              State: 'running',
   160              Failed: false,
   161            },
   162          },
   163          PreemptedByAllocation: 'preempter-allocation',
   164          PreemptedAllocations: ['preempted-one-allocation', 'preempted-two-allocation'],
   165        },
   166        out: {
   167          data: {
   168            id: 'test-allocation',
   169            type: 'allocation',
   170            attributes: {
   171              taskGroupName: 'test-group',
   172              name: 'test-summary[1]',
   173              modifyTime: sampleDate,
   174              createTime: sampleDate,
   175              states: [
   176                {
   177                  name: 'task',
   178                  state: 'running',
   179                  failed: false,
   180                },
   181              ],
   182              wasPreempted: true,
   183            },
   184            relationships: {
   185              followUpEvaluation: {
   186                data: null,
   187              },
   188              nextAllocation: {
   189                data: null,
   190              },
   191              previousAllocation: {
   192                data: null,
   193              },
   194              preemptedAllocations: {
   195                data: [
   196                  { id: 'preempted-one-allocation', type: 'allocation' },
   197                  { id: 'preempted-two-allocation', type: 'allocation' },
   198                ],
   199              },
   200              preemptedByAllocation: {
   201                data: {
   202                  id: 'preempter-allocation',
   203                  type: 'allocation',
   204                },
   205              },
   206              job: {
   207                data: {
   208                  id: '["test-summary","test-namespace"]',
   209                  type: 'job',
   210                },
   211              },
   212            },
   213          },
   214        },
   215      },
   216    ];
   217  
   218    normalizationTestCases.forEach(testCase => {
   219      test(`normalization: ${testCase.name}`, async function(assert) {
   220        assert.deepEqual(this.subject().normalize(AllocationModel, testCase.in), testCase.out);
   221      });
   222    });
   223  });