github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/ui/tests/unit/models/job-test.js (about)

     1  import { moduleForModel, test } from 'ember-qunit';
     2  
     3  moduleForModel('job', 'Unit | Model | job', {
     4    needs: ['model:task-group', 'model:task', 'model:task-group-summary'],
     5  });
     6  
     7  test('should expose aggregate allocations derived from task groups', function(assert) {
     8    const job = this.subject({
     9      name: 'example',
    10      taskGroups: [
    11        {
    12          name: 'one',
    13          count: 0,
    14          tasks: [],
    15        },
    16        {
    17          name: 'two',
    18          count: 0,
    19          tasks: [],
    20        },
    21        {
    22          name: 'three',
    23          count: 0,
    24          tasks: [],
    25        },
    26      ],
    27      taskGroupSummaries: [
    28        {
    29          name: 'one',
    30          queuedAllocs: 1,
    31          startingAllocs: 2,
    32          runningAllocs: 3,
    33          completeAllocs: 4,
    34          failedAllocs: 5,
    35          lostAllocs: 6,
    36        },
    37        {
    38          name: 'two',
    39          queuedAllocs: 2,
    40          startingAllocs: 4,
    41          runningAllocs: 6,
    42          completeAllocs: 8,
    43          failedAllocs: 10,
    44          lostAllocs: 12,
    45        },
    46        {
    47          name: 'three',
    48          queuedAllocs: 3,
    49          startingAllocs: 6,
    50          runningAllocs: 9,
    51          completeAllocs: 12,
    52          failedAllocs: 15,
    53          lostAllocs: 18,
    54        },
    55      ],
    56    });
    57  
    58    assert.equal(
    59      job.get('totalAllocs'),
    60      job.get('taskGroups').mapBy('summary.totalAllocs').reduce((sum, allocs) => sum + allocs, 0),
    61      'totalAllocs is the sum of all group totalAllocs'
    62    );
    63  
    64    assert.equal(
    65      job.get('queuedAllocs'),
    66      job.get('taskGroups').mapBy('summary.queuedAllocs').reduce((sum, allocs) => sum + allocs, 0),
    67      'queuedAllocs is the sum of all group queuedAllocs'
    68    );
    69  
    70    assert.equal(
    71      job.get('startingAllocs'),
    72      job.get('taskGroups').mapBy('summary.startingAllocs').reduce((sum, allocs) => sum + allocs, 0),
    73      'startingAllocs is the sum of all group startingAllocs'
    74    );
    75  
    76    assert.equal(
    77      job.get('runningAllocs'),
    78      job.get('taskGroups').mapBy('summary.runningAllocs').reduce((sum, allocs) => sum + allocs, 0),
    79      'runningAllocs is the sum of all group runningAllocs'
    80    );
    81  
    82    assert.equal(
    83      job.get('completeAllocs'),
    84      job.get('taskGroups').mapBy('summary.completeAllocs').reduce((sum, allocs) => sum + allocs, 0),
    85      'completeAllocs is the sum of all group completeAllocs'
    86    );
    87  
    88    assert.equal(
    89      job.get('failedAllocs'),
    90      job.get('taskGroups').mapBy('summary.failedAllocs').reduce((sum, allocs) => sum + allocs, 0),
    91      'failedAllocs is the sum of all group failedAllocs'
    92    );
    93  
    94    assert.equal(
    95      job.get('lostAllocs'),
    96      job.get('taskGroups').mapBy('summary.lostAllocs').reduce((sum, allocs) => sum + allocs, 0),
    97      'lostAllocs is the sum of all group lostAllocs'
    98    );
    99  });