OLD | NEW |
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 (function() { | 3 (function() { |
4 | 4 |
5 describe('sandbox.ClientConnection', function() { | 5 describe('sandbox.ClientConnection', function() { |
6 var requires = ['juju-env-sandbox', 'json-stringify']; | 6 var requires = ['juju-env-sandbox', 'json-stringify']; |
7 var Y, sandboxModule, ClientConnection; | 7 var Y, sandboxModule, ClientConnection; |
8 | 8 |
9 before(function(done) { | 9 before(function(done) { |
10 Y = YUI(GlobalConfig).use(requires, function(Y) { | 10 Y = YUI(GlobalConfig).use(requires, function(Y) { |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 }; | 511 }; |
512 client.onmessage = function(received) { | 512 client.onmessage = function(received) { |
513 // First message is the provider type and default series. We can | 513 // First message is the provider type and default series. We can |
514 // close now. | 514 // close now. |
515 client.close(); | 515 client.close(); |
516 }; | 516 }; |
517 juju.set('deltaInterval', 4); | 517 juju.set('deltaInterval', 4); |
518 client.open(); | 518 client.open(); |
519 }); | 519 }); |
520 | 520 |
| 521 it('can add additional units', function(done) { |
| 522 state.deploy('cs:wordpress', function(service) { |
| 523 var data = { |
| 524 op: 'add_unit', |
| 525 service_name: 'wordpress', |
| 526 num_units: 2 |
| 527 }; |
| 528 //Clear out the delta stream |
| 529 state.nextChanges(); |
| 530 client.onmessage = function() { |
| 531 client.onmessage = function(received) { |
| 532 var units = state.db.units.get_units_for_service(service.service), |
| 533 data = Y.JSON.parse(received.data), |
| 534 mock = { |
| 535 num_units: 2, |
| 536 service_name: 'wordpress', |
| 537 op: 'add_unit', |
| 538 result: ['wordpress/2', 'wordpress/3'] |
| 539 }; |
| 540 // Do we have enough total units? |
| 541 assert.lengthOf(units, 3); |
| 542 // Does the response object contain the proper data |
| 543 assert.deepEqual(data, mock); |
| 544 // Error is undefined |
| 545 assert.isUndefined(data.err); |
| 546 done(); |
| 547 }; |
| 548 client.send(Y.JSON.stringify(data)); |
| 549 }; |
| 550 client.open(); |
| 551 }); |
| 552 }); |
| 553 |
| 554 it('throws an error when adding units to an invalid service', |
| 555 function(done) { |
| 556 state.deploy('cs:wordpress', function(service) { |
| 557 var data = { |
| 558 op: 'add_unit', |
| 559 service_name: 'noservice', |
| 560 num_units: 2 |
| 561 }; |
| 562 //Clear out the delta stream |
| 563 state.nextChanges(); |
| 564 client.onmessage = function() { |
| 565 client.onmessage = function(received) { |
| 566 var data = Y.JSON.parse(received.data); |
| 567 |
| 568 // If there is no error data.err will be undefined |
| 569 assert.equal(true, !!data.err); |
| 570 done(); |
| 571 }; |
| 572 client.send(Y.JSON.stringify(data)); |
| 573 }; |
| 574 client.open(); |
| 575 }); |
| 576 } |
| 577 ); |
| 578 |
| 579 it('can add additional units (integration)', function(done) { |
| 580 env.after('defaultSeriesChange', function() { |
| 581 var callback = function(result) { |
| 582 env.add_unit('kumquat', 2, function(data) { |
| 583 var service = state.db.services.getById('kumquat'); |
| 584 var units = state.db.units.get_units_for_service(service); |
| 585 assert.lengthOf(units, 3); |
| 586 done(); |
| 587 }); |
| 588 }; |
| 589 env.deploy( |
| 590 'cs:wordpress', 'kumquat', {llama: 'pajama'}, null, 1, callback); |
| 591 }); |
| 592 env.connect(); |
| 593 }); |
| 594 |
| 595 |
| 596 |
521 }); | 597 }); |
522 | 598 |
523 })(); | 599 })(); |
OLD | NEW |