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 done(); |
| 545 }; |
| 546 client.send(Y.JSON.stringify(data)); |
| 547 }; |
| 548 client.open(); |
| 549 }); |
| 550 }); |
| 551 |
| 552 it('throws an error when adding units to an invalid service', |
| 553 function(done) { |
| 554 state.deploy('cs:wordpress', function(service) { |
| 555 var data = { |
| 556 op: 'add_unit', |
| 557 service_name: 'noservice', |
| 558 num_units: 2 |
| 559 }; |
| 560 //Clear out the delta stream |
| 561 state.nextChanges(); |
| 562 client.onmessage = function() { |
| 563 client.onmessage = function(received) { |
| 564 var data = Y.JSON.parse(received.data); |
| 565 |
| 566 // If there is no error data.err will be undefined |
| 567 assert.equal(true, !!data.err); |
| 568 done(); |
| 569 }; |
| 570 client.send(Y.JSON.stringify(data)); |
| 571 }; |
| 572 client.open(); |
| 573 }); |
| 574 } |
| 575 ); |
| 576 |
| 577 it('can add additional units (integration)', function(done) { |
| 578 env.after('defaultSeriesChange', function() { |
| 579 var callback = function(result) { |
| 580 env.add_unit('kumquat', 2, function(data) { |
| 581 var service = state.db.services.getById('kumquat'); |
| 582 var units = state.db.units.get_units_for_service(service); |
| 583 assert.lengthOf(units, 3); |
| 584 done(); |
| 585 }); |
| 586 }; |
| 587 env.deploy( |
| 588 'cs:wordpress', 'kumquat', {llama: 'pajama'}, null, 1, callback); |
| 589 }); |
| 590 env.connect(); |
| 591 }); |
| 592 |
| 593 |
| 594 |
521 }); | 595 }); |
522 | 596 |
523 })(); | 597 })(); |
OLD | NEW |