OLD | NEW |
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 (function() { | 3 (function() { |
4 | 4 |
5 describe('Go Juju environment utilities', function() { | 5 describe('Go Juju environment utilities', function() { |
6 var environments, Y; | 6 var environments, Y; |
7 | 7 |
8 before(function(done) { | 8 before(function(done) { |
9 Y = YUI(GlobalConfig).use(['juju-env-go'], function(Y) { | 9 Y = YUI(GlobalConfig).use(['juju-env-go'], function(Y) { |
10 environments = Y.namespace('juju.environments'); | 10 environments = Y.namespace('juju.environments'); |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 var expected = { | 658 var expected = { |
659 Request: 'ServiceGet', | 659 Request: 'ServiceGet', |
660 Type: 'Client', | 660 Type: 'Client', |
661 RequestId: 1, | 661 RequestId: 1, |
662 Params: {ServiceName: 'mysql'} | 662 Params: {ServiceName: 'mysql'} |
663 }; | 663 }; |
664 assert.deepEqual(expected, last_message); | 664 assert.deepEqual(expected, last_message); |
665 }); | 665 }); |
666 | 666 |
667 it('successfully gets service configuration', function() { | 667 it('successfully gets service configuration', function() { |
668 var service_name; | 668 var service_name, result; |
669 var result; | |
670 var expected = { | |
671 Service: 'mysql', | |
672 Charm: 'mysql', | |
673 Settings: { | |
674 'binlog-format': { | |
675 description: 'If binlogging is enabled, etc, etc","type":"string', | |
676 value: null | |
677 } | |
678 } | |
679 }; | |
680 env.get_service('mysql', function(data) { | 669 env.get_service('mysql', function(data) { |
681 service_name = data.service_name; | 670 service_name = data.service_name; |
682 result = data.result; | 671 result = data.result; |
683 }); | 672 }); |
684 // Mimic response. | 673 // Mimic response. |
685 conn.msg({ | 674 conn.msg({ |
686 RequestId: 1, | 675 RequestId: 1, |
687 Response: expected | 676 Response: { |
| 677 Service: 'mysql', |
| 678 Charm: 'mysql', |
| 679 Settings: { |
| 680 'binlog-format': { |
| 681 description: 'Yada, yada, yada.', |
| 682 type: 'string', |
| 683 value: null |
| 684 } |
| 685 } |
| 686 } |
688 }); | 687 }); |
689 expected.name = 'mysql'; | 688 assert.equal(service_name, 'mysql'); |
| 689 var expected = { |
| 690 config: { |
| 691 'binlog-format': { |
| 692 description: 'Yada, yada, yada.', |
| 693 type: 'string', |
| 694 value: null |
| 695 } |
| 696 }, |
| 697 constraints: undefined |
| 698 }; |
690 assert.strictEqual('mysql', service_name); | 699 assert.strictEqual('mysql', service_name); |
691 assert.deepEqual(expected, result); | 700 assert.deepEqual(expected, result); |
692 }); | 701 }); |
693 | 702 |
694 it('handles failed get service', function() { | 703 it('handles failed get service', function() { |
695 var service_name; | 704 var service_name; |
696 var err; | 705 var err; |
697 env.get_service('yoursql', function(data) { | 706 env.get_service('yoursql', function(data) { |
698 service_name = data.service_name; | 707 service_name = data.service_name; |
699 err = data.err; | 708 err = data.err; |
700 }); | 709 }); |
701 // Mimic response. | 710 // Mimic response. |
702 conn.msg({ | 711 conn.msg({ |
703 RequestId: 1, | 712 RequestId: 1, |
704 Error: 'service \"yoursql\" not found', | 713 Error: 'service \"yoursql\" not found', |
705 Response: { | 714 Response: { |
706 Service: 'yoursql' | 715 Service: 'yoursql' |
707 } | 716 } |
708 }); | 717 }); |
709 assert.equal(service_name, 'yoursql'); | 718 assert.equal(service_name, 'yoursql'); |
710 assert.equal(err, 'service "yoursql" not found'); | 719 assert.equal(err, 'service "yoursql" not found'); |
711 }); | 720 }); |
712 | 721 |
| 722 it('can set service constraints', function() { |
| 723 env.set_constraints('mysql', {'cpu-cores': '4'}); |
| 724 msg = conn.last_message(); |
| 725 var expected = { |
| 726 Type: 'Client', |
| 727 Request: 'SetServiceConstraints', |
| 728 Params: { |
| 729 ServiceName: 'mysql', |
| 730 Constraints: { |
| 731 'cpu-cores': 4 |
| 732 } |
| 733 }, |
| 734 RequestId: msg.RequestId |
| 735 }; |
| 736 assert.deepEqual(expected, msg); |
| 737 }); |
| 738 |
713 it('can set a service config', function() { | 739 it('can set a service config', function() { |
714 env.set_config('mysql', {'cfg-key': 'cfg-val'}); | 740 env.set_config('mysql', {'cfg-key': 'cfg-val'}); |
715 msg = conn.last_message(); | 741 msg = conn.last_message(); |
716 var expected = { | 742 var expected = { |
717 Type: 'Client', | 743 Type: 'Client', |
718 Params: { | 744 Params: { |
719 ServiceName: 'mysql', | 745 ServiceName: 'mysql', |
720 Config: { | 746 Config: { |
721 'cfg-key': 'cfg-val' | 747 'cfg-key': 'cfg-val' |
722 } | 748 } |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 // Calling this sets up the callback. | 1150 // Calling this sets up the callback. |
1125 env._next(); | 1151 env._next(); |
1126 env._txn_callbacks[env._counter].call(env, {}); | 1152 env._txn_callbacks[env._counter].call(env, {}); |
1127 // The only test assertion is that done (above) is called. | 1153 // The only test assertion is that done (above) is called. |
1128 }); | 1154 }); |
1129 | 1155 |
1130 it('fires "delta" when handling an RPC response', function(done) { | 1156 it('fires "delta" when handling an RPC response', function(done) { |
1131 env.detach('delta'); | 1157 env.detach('delta'); |
1132 var callbackData = {Response: {Deltas: [['service', 'deploy', {}]]}}; | 1158 var callbackData = {Response: {Deltas: [['service', 'deploy', {}]]}}; |
1133 env.on('delta', function(evt) { | 1159 env.on('delta', function(evt) { |
1134 console.log(evt.data.result); | |
1135 done(); | 1160 done(); |
1136 }); | 1161 }); |
1137 env._handleRpcResponse(callbackData); | 1162 env._handleRpcResponse(callbackData); |
1138 }); | 1163 }); |
1139 | 1164 |
1140 it('translates the type of each change in the delta', function(done) { | 1165 it('translates the type of each change in the delta', function(done) { |
1141 env.detach('delta'); | 1166 env.detach('delta'); |
1142 var callbackData = {Response: {Deltas: [['service', 'deploy', {}]]}}; | 1167 var callbackData = {Response: {Deltas: [['service', 'deploy', {}]]}}; |
1143 env.on('delta', function(evt) { | 1168 env.on('delta', function(evt) { |
1144 var change = evt.data.result[0]; | 1169 var change = evt.data.result[0]; |
1145 assert.deepEqual(['serviceInfo', 'deploy', {}], change); | 1170 assert.deepEqual(['serviceInfo', 'deploy', {}], change); |
1146 done(); | 1171 done(); |
1147 }); | 1172 }); |
1148 env._handleRpcResponse(callbackData); | 1173 env._handleRpcResponse(callbackData); |
1149 }); | 1174 }); |
1150 | 1175 |
1151 it('the _rpc_response subscription can not have args', function() { | 1176 it('the _rpc_response subscription can not have args', function() { |
1152 var subscribers = env.getEvent('_rpc_response')._subscribers; | 1177 var subscribers = env.getEvent('_rpc_response')._subscribers; |
1153 // This test assumes that there is only one subscriber. If we ever have | 1178 // This test assumes that there is only one subscriber. If we ever have |
1154 // any more we will need to update this test. | 1179 // any more we will need to update this test. |
1155 assert.equal(subscribers.length, 1); | 1180 assert.equal(subscribers.length, 1); |
1156 assert.equal(subscribers[0].args, null); | 1181 assert.equal(subscribers[0].args, null); |
1157 }); | 1182 }); |
1158 | 1183 |
1159 }); | 1184 }); |
1160 | 1185 |
1161 })(); | 1186 })(); |
OLD | NEW |