github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/unit/controllers/allocations/allocation/index-test.js (about) 1 import { module, test } from 'qunit'; 2 import { setupTest } from 'ember-qunit'; 3 4 module('Unit | Controller | allocations/allocation/index', function (hooks) { 5 setupTest(hooks); 6 7 module('#serviceHealthStatuses', function () { 8 test('it groups health service data by service name', function (assert) { 9 let controller = this.owner.lookup( 10 'controller:allocations/allocation/index' 11 ); 12 controller.set('model', JSON.parse(JSON.stringify(Allocation))); 13 14 const groupFakePy = { 15 refID: 'fakepy-group-fake-py', 16 statuses: { 17 success: 1, 18 failure: 1, 19 pending: 0, 20 }, 21 }; 22 const taskFakePy = { 23 refID: 'http.server-task-fake-py', 24 statuses: { 25 success: 2, 26 failure: 2, 27 pending: 0, 28 }, 29 }; 30 const pender = { 31 refID: 'http.server-pender', 32 statuses: { 33 success: 0, 34 failure: 0, 35 pending: 1, 36 }, 37 }; 38 39 assert.equal( 40 controller.servicesWithHealthChecks 41 .findBy('refID', groupFakePy.refID) 42 .healthChecks.filter((check) => check.Status === 'success').length, 43 groupFakePy.statuses['success'] 44 ); 45 assert.equal( 46 controller.servicesWithHealthChecks 47 .findBy('refID', groupFakePy.refID) 48 .healthChecks.filter((check) => check.Status === 'failure').length, 49 groupFakePy.statuses['failure'] 50 ); 51 assert.equal( 52 controller.servicesWithHealthChecks 53 .findBy('refID', groupFakePy.refID) 54 .healthChecks.filter((check) => check.Status === 'pending').length, 55 groupFakePy.statuses['pending'] 56 ); 57 58 assert.equal( 59 controller.servicesWithHealthChecks 60 .findBy('refID', taskFakePy.refID) 61 .healthChecks.filter((check) => check.Status === 'success').length, 62 taskFakePy.statuses['success'] 63 ); 64 assert.equal( 65 controller.servicesWithHealthChecks 66 .findBy('refID', taskFakePy.refID) 67 .healthChecks.filter((check) => check.Status === 'failure').length, 68 taskFakePy.statuses['failure'] 69 ); 70 assert.equal( 71 controller.servicesWithHealthChecks 72 .findBy('refID', taskFakePy.refID) 73 .healthChecks.filter((check) => check.Status === 'pending').length, 74 taskFakePy.statuses['pending'] 75 ); 76 77 assert.equal( 78 controller.servicesWithHealthChecks 79 .findBy('refID', pender.refID) 80 .healthChecks.filter((check) => check.Status === 'success').length, 81 pender.statuses['success'] 82 ); 83 assert.equal( 84 controller.servicesWithHealthChecks 85 .findBy('refID', pender.refID) 86 .healthChecks.filter((check) => check.Status === 'failure').length, 87 pender.statuses['failure'] 88 ); 89 assert.equal( 90 controller.servicesWithHealthChecks 91 .findBy('refID', pender.refID) 92 .healthChecks.filter((check) => check.Status === 'pending').length, 93 pender.statuses['pending'] 94 ); 95 }); 96 97 test('it handles duplicate names', async function (assert) { 98 let controller = this.owner.lookup( 99 'controller:allocations/allocation/index' 100 ); 101 controller.set('model', JSON.parse(JSON.stringify(Allocation))); 102 103 const groupDupe = { 104 refID: 'fakepy-duper', 105 statuses: { 106 success: 1, 107 failure: 0, 108 pending: 0, 109 }, 110 }; 111 const taskDupe = { 112 refID: 'http.server-duper', 113 statuses: { 114 success: 0, 115 failure: 1, 116 pending: 0, 117 }, 118 }; 119 120 assert.equal( 121 controller.servicesWithHealthChecks 122 .findBy('refID', groupDupe.refID) 123 .healthChecks.filter((check) => check.Status === 'success').length, 124 groupDupe.statuses['success'] 125 ); 126 assert.equal( 127 controller.servicesWithHealthChecks 128 .findBy('refID', groupDupe.refID) 129 .healthChecks.filter((check) => check.Status === 'failure').length, 130 groupDupe.statuses['failure'] 131 ); 132 assert.equal( 133 controller.servicesWithHealthChecks 134 .findBy('refID', groupDupe.refID) 135 .healthChecks.filter((check) => check.Status === 'pending').length, 136 groupDupe.statuses['pending'] 137 ); 138 139 assert.equal( 140 controller.servicesWithHealthChecks 141 .findBy('refID', taskDupe.refID) 142 .healthChecks.filter((check) => check.Status === 'success').length, 143 taskDupe.statuses['success'] 144 ); 145 assert.equal( 146 controller.servicesWithHealthChecks 147 .findBy('refID', taskDupe.refID) 148 .healthChecks.filter((check) => check.Status === 'failure').length, 149 taskDupe.statuses['failure'] 150 ); 151 assert.equal( 152 controller.servicesWithHealthChecks 153 .findBy('refID', taskDupe.refID) 154 .healthChecks.filter((check) => check.Status === 'pending').length, 155 taskDupe.statuses['pending'] 156 ); 157 }); 158 }); 159 }); 160 161 // Using var to hoist this variable to the top of the module 162 var Allocation = { 163 namespace: 'default', 164 name: 'my-alloc', 165 taskGroup: { 166 name: 'fakepy', 167 count: 3, 168 services: [ 169 { 170 Name: 'group-fake-py', 171 refID: 'fakepy-group-fake-py', 172 PortLabel: 'http', 173 Tags: [], 174 OnUpdate: 'require_healthy', 175 Provider: 'nomad', 176 Connect: null, 177 GroupName: 'fakepy', 178 TaskName: '', 179 healthChecks: [], 180 }, 181 { 182 Name: 'duper', 183 refID: 'fakepy-duper', 184 PortLabel: 'http', 185 Tags: [], 186 OnUpdate: 'require_healthy', 187 Provider: 'nomad', 188 Connect: null, 189 GroupName: 'fakepy', 190 TaskName: '', 191 healthChecks: [], 192 }, 193 ], 194 }, 195 allocatedResources: { 196 Cpu: 100, 197 Memory: 300, 198 MemoryMax: null, 199 Disk: 0, 200 Iops: null, 201 Networks: [ 202 { 203 Device: '', 204 CIDR: '', 205 IP: '127.0.0.1', 206 Mode: 'host', 207 MBits: 0, 208 Ports: [ 209 { 210 name: 'http', 211 port: 22308, 212 to: 0, 213 isDynamic: true, 214 }, 215 ], 216 }, 217 ], 218 Ports: [ 219 { 220 HostIP: '127.0.0.1', 221 Label: 'http', 222 To: 0, 223 Value: 22308, 224 }, 225 ], 226 }, 227 healthChecks: { 228 c97fda942e772b43a5a537e5b0c8544c: { 229 Check: 'service: "task-fake-py" check', 230 Alloc: 'my-alloc', 231 Group: 'trying-multi-dupes.fakepy[1]', 232 ID: 'c97fda942e772b43a5a537e5b0c8544c', 233 Mode: 'healthiness', 234 Output: 'nomad: http ok', 235 Service: 'task-fake-py', 236 Status: 'success', 237 StatusCode: 200, 238 Task: 'http.server', 239 Timestamp: 1662131947, 240 }, 241 '2e1bfc8ecc485ee86b972ae08e890152': { 242 Check: 'task-happy', 243 Alloc: 'my-alloc', 244 Group: 'trying-multi-dupes.fakepy[1]', 245 ID: '2e1bfc8ecc485ee86b972ae08e890152', 246 Mode: 'healthiness', 247 Output: 'nomad: http ok', 248 Service: 'task-fake-py', 249 Status: 'success', 250 StatusCode: 200, 251 Task: 'http.server', 252 Timestamp: 1662131949, 253 }, 254 '6162723ab20b268c25eda69b400dc9c6': { 255 Check: 'task-sad', 256 Alloc: 'my-alloc', 257 Group: 'trying-multi-dupes.fakepy[1]', 258 ID: '6162723ab20b268c25eda69b400dc9c6', 259 Mode: 'healthiness', 260 Output: 261 '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"\n "http://www.w3.org/TR/html4/strict.dtd">\n<html>\n <head>\n <meta http-equiv="Content-Type" content="text/html;charset=utf-8">\n <title>Error response</title>\n </head>\n <body>\n <h1>Error response</h1>\n <p>Error code: 404</p>\n <p>Message: File not found.</p>\n <p>Error code explanation: HTTPStatus.NOT_FOUND - Nothing matches the given URI.</p>\n </body>\n</html>\n', 262 Service: 'task-fake-py', 263 Status: 'failure', 264 StatusCode: 404, 265 Task: 'http.server', 266 Timestamp: 1662131936, 267 }, 268 a4a7050175a2b236edcf613cb3563753: { 269 Check: 'task-sad2', 270 Alloc: 'my-alloc', 271 Group: 'trying-multi-dupes.fakepy[1]', 272 ID: 'a4a7050175a2b236edcf613cb3563753', 273 Mode: 'healthiness', 274 Output: 275 '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"\n "http://www.w3.org/TR/html4/strict.dtd">\n<html>\n <head>\n <meta http-equiv="Content-Type" content="text/html;charset=utf-8">\n <title>Error response</title>\n </head>\n <body>\n <h1>Error response</h1>\n <p>Error code: 404</p>\n <p>Message: File not found.</p>\n <p>Error code explanation: HTTPStatus.NOT_FOUND - Nothing matches the given URI.</p>\n </body>\n</html>\n', 276 Service: 'task-fake-py', 277 Status: 'failure', 278 StatusCode: 404, 279 Task: 'http.server', 280 Timestamp: 1662131936, 281 }, 282 '2dfe58eb841bdfa704f0ae9ef5b5af5e': { 283 Check: 'tcp_probe', 284 Alloc: 'my-alloc', 285 Group: 'trying-multi-dupes.fakepy[1]', 286 ID: '2dfe58eb841bdfa704f0ae9ef5b5af5e', 287 Mode: 'readiness', 288 Output: 'nomad: tcp ok', 289 Service: 'web', 290 Status: 'success', 291 Task: 'http.server', 292 Timestamp: 1662131949, 293 }, 294 '69021054964f4c461b3c4c4f456e16a8': { 295 Check: 'happy', 296 Alloc: 'my-alloc', 297 Group: 'trying-multi-dupes.fakepy[1]', 298 ID: '69021054964f4c461b3c4c4f456e16a8', 299 Mode: 'healthiness', 300 Output: 'nomad: http ok', 301 Service: 'group-fake-py', 302 Status: 'success', 303 StatusCode: 200, 304 Timestamp: 1662131949, 305 }, 306 '913f5b725ceecdd5ff48a9a51ddf8513': { 307 Check: 'sad', 308 Alloc: 'my-alloc', 309 Group: 'trying-multi-dupes.fakepy[1]', 310 ID: '913f5b725ceecdd5ff48a9a51ddf8513', 311 Mode: 'healthiness', 312 Output: 313 '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"\n "http://www.w3.org/TR/html4/strict.dtd">\n<html>\n <head>\n <meta http-equiv="Content-Type" content="text/html;charset=utf-8">\n <title>Error response</title>\n </head>\n <body>\n <h1>Error response</h1>\n <p>Error code: 404</p>\n <p>Message: File not found.</p>\n <p>Error code explanation: HTTPStatus.NOT_FOUND - Nothing matches the given URI.</p>\n </body>\n</html>\n', 314 Service: 'group-fake-py', 315 Status: 'failure', 316 StatusCode: 404, 317 Timestamp: 1662131936, 318 }, 319 bloop: { 320 Check: 'is-alive', 321 Alloc: 'my-alloc', 322 Group: 'trying-multi-dupes.fakepy[1]', 323 ID: 'bloop', 324 Mode: 'healthiness', 325 Service: 'pender', 326 Status: 'pending', 327 Task: 'http.server', 328 Timestamp: 1662131947, 329 }, 330 'group-dupe': { 331 Check: 'is-alive', 332 Alloc: 'my-alloc', 333 Group: 'trying-multi-dupes.fakepy[1]', 334 ID: 'group-dupe', 335 Mode: 'healthiness', 336 Service: 'duper', 337 Status: 'success', 338 Task: '', 339 Timestamp: 1662131947, 340 }, 341 'task-dupe': { 342 Check: 'is-alive', 343 Alloc: 'my-alloc', 344 Group: 'trying-multi-dupes.fakepy[1]', 345 ID: 'task-dupe', 346 Mode: 'healthiness', 347 Service: 'duper', 348 Status: 'failure', 349 Task: 'http.server', 350 Timestamp: 1662131947, 351 }, 352 }, 353 id: 'my-alloc', 354 states: [ 355 { 356 Name: 'http.server', 357 task: { 358 name: 'http.server', 359 driver: 'raw_exec', 360 kind: '', 361 meta: null, 362 lifecycle: null, 363 reservedMemory: 300, 364 reservedMemoryMax: 0, 365 reservedCPU: 100, 366 reservedDisk: 0, 367 reservedEphemeralDisk: 300, 368 services: [ 369 { 370 Name: 'task-fake-py', 371 PortLabel: 'http', 372 refID: 'http.server-task-fake-py', 373 Tags: [ 374 'long', 375 'and', 376 'arbitrary', 377 'list', 378 'of', 379 'tags', 380 'arbitrary', 381 ], 382 OnUpdate: 'require_healthy', 383 Provider: 'nomad', 384 Connect: null, 385 TaskName: 'http.server', 386 healthChecks: [], 387 }, 388 { 389 Name: 'pender', 390 refID: 'http.server-pender', 391 PortLabel: 'http', 392 Tags: ['lol', 'lmao'], 393 OnUpdate: 'require_healthy', 394 Provider: 'nomad', 395 Connect: null, 396 TaskName: 'http.server', 397 healthChecks: [], 398 }, 399 { 400 Name: 'web', 401 refID: 'http.server-web', 402 PortLabel: 'http', 403 Tags: ['lol', 'lmao'], 404 OnUpdate: 'require_healthy', 405 Provider: 'nomad', 406 Connect: null, 407 TaskName: 'http.server', 408 healthChecks: [], 409 }, 410 { 411 Name: 'duper', 412 refID: 'http.server-duper', 413 PortLabel: 'http', 414 Tags: ['lol', 'lmao'], 415 OnUpdate: 'require_healthy', 416 Provider: 'nomad', 417 Connect: null, 418 TaskName: 'http.server', 419 healthChecks: [], 420 }, 421 ], 422 volumeMounts: null, 423 }, 424 }, 425 ], 426 rescheduleEvents: [], 427 job: '["trying-multi-dupes","default"]', 428 node: '5d33384d-8d0f-6a65-743c-2fcc1871b13e', 429 previousAllocation: null, 430 nextAllocation: null, 431 preemptedByAllocation: null, 432 followUpEvaluation: null, 433 };