yarn-container-log-test.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. import { moduleFor, test } from 'ember-qunit';
  19. import Constants from 'yarn-ui/constants';
  20. moduleFor('route:yarn-container-log', 'Unit | Route | ContainerLog', {
  21. });
  22. test('Basic creation test', function(assert) {
  23. let route = this.subject();
  24. assert.ok(route);
  25. assert.ok(route.model);
  26. });
  27. test('Test getting container log', function(assert) {
  28. var response = {
  29. logs: "This is syslog",
  30. containerID: "container_e32_1456000363780_0002_01_000001",
  31. logFileName: "syslog"};
  32. var store = {
  33. findRecord: function(type) {
  34. return new Ember.RSVP.Promise(function(resolve) {
  35. resolve(response);
  36. }
  37. )}
  38. };
  39. assert.expect(6);
  40. var route = this.subject();
  41. route.set('store', store);
  42. var model = route.model({node_id: "localhost:64318",
  43. node_addr: "localhost:8042",
  44. container_id: "container_e32_1456000363780_0002_01_000001",
  45. filename: "syslog"});
  46. model.then(function(value) {
  47. assert.ok(value);
  48. assert.ok(value.containerLog);
  49. assert.deepEqual(value.containerLog, response);
  50. assert.ok(value.nodeInfo);
  51. assert.equal(value.nodeInfo.addr, 'localhost:8042');
  52. assert.equal(value.nodeInfo.id, 'localhost:64318');
  53. });
  54. });
  55. /**
  56. * This can happen when an empty response is sent from server
  57. */
  58. test('Test non HTTP error while getting container log', function(assert) {
  59. var error = {};
  60. var response = {
  61. logs: "",
  62. containerID: "container_e32_1456000363780_0002_01_000001",
  63. logFileName: "syslog"};
  64. var store = {
  65. findRecord: function(type) {
  66. return new Ember.RSVP.Promise(function(resolve, reject) {
  67. reject(error);
  68. }
  69. )}
  70. };
  71. assert.expect(6);
  72. var route = this.subject();
  73. route.set('store', store);
  74. var model = route.model({node_id: "localhost:64318",
  75. node_addr: "localhost:8042",
  76. container_id: "container_e32_1456000363780_0002_01_000001",
  77. filename: "syslog"});
  78. model.then(function(value) {
  79. assert.ok(value);
  80. assert.ok(value.containerLog);
  81. assert.deepEqual(value.containerLog, response);
  82. assert.ok(value.nodeInfo);
  83. assert.equal(value.nodeInfo.addr, 'localhost:8042');
  84. assert.equal(value.nodeInfo.id, 'localhost:64318');
  85. });
  86. });
  87. test('Test HTTP error while getting container log', function(assert) {
  88. var error = {errors: [{status: 404, responseText: 'Not Found'}]};
  89. var response = {
  90. logs: "",
  91. containerID: "container_e32_1456000363780_0002_01_000001",
  92. logFileName: "syslog"};
  93. var store = {
  94. findRecord: function(type) {
  95. return new Ember.RSVP.Promise(function(resolve, reject) {
  96. reject(error);
  97. }
  98. )}
  99. };
  100. assert.expect(5);
  101. var route = this.subject();
  102. route.set('store', store);
  103. var model = route.model({node_id: "localhost:64318",
  104. node_addr: "localhost:8042",
  105. container_id: "container_e32_1456000363780_0002_01_000001",
  106. filename: "syslog"});
  107. model.then(function(value) {
  108. assert.ok(value);
  109. assert.ok(value.errors);
  110. assert.equal(value.errors.length, 1);
  111. assert.equal(value.errors[0].status, 404);
  112. assert.equal(value.errors[0].responseText, 'Not Found');
  113. });
  114. });