github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/ui/tests/acceptance/task-logs-test.js (about)

     1  import { currentURL } from '@ember/test-helpers';
     2  import { run } from '@ember/runloop';
     3  import { module, test } from 'qunit';
     4  import { setupApplicationTest } from 'ember-qunit';
     5  import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
     6  import TaskLogs from 'nomad-ui/tests/pages/allocations/task/logs';
     7  
     8  let allocation;
     9  let task;
    10  
    11  module('Acceptance | task logs', function(hooks) {
    12    setupApplicationTest(hooks);
    13    setupMirage(hooks);
    14  
    15    hooks.beforeEach(async function() {
    16      server.create('agent');
    17      server.create('node', 'forceIPv4');
    18      const job = server.create('job', { createAllocations: false });
    19  
    20      allocation = server.create('allocation', { jobId: job.id, clientStatus: 'running' });
    21      task = server.db.taskStates.where({ allocationId: allocation.id })[0];
    22  
    23      run.later(run, run.cancelTimers, 1000);
    24      await TaskLogs.visit({ id: allocation.id, name: task.name });
    25    });
    26  
    27    test('/allocation/:id/:task_name/logs should have a log component', async function(assert) {
    28      assert.equal(currentURL(), `/allocations/${allocation.id}/${task.name}/logs`, 'No redirect');
    29      assert.ok(TaskLogs.hasTaskLog, 'Task log component found');
    30    });
    31  
    32    test('the stdout log immediately starts streaming', async function(assert) {
    33      const node = server.db.nodes.find(allocation.nodeId);
    34      const logUrlRegex = new RegExp(`${node.httpAddr}/v1/client/fs/logs/${allocation.id}`);
    35      assert.ok(
    36        server.pretender.handledRequests.filter(req => logUrlRegex.test(req.url)).length,
    37        'Log requests were made'
    38      );
    39    });
    40  });