OLD | NEW |
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 (function() { | 3 (function() { |
4 | 4 |
| 5 describe('Go Juju environment utilities', function() { |
| 6 var environments, Y; |
| 7 |
| 8 before(function(done) { |
| 9 Y = YUI(GlobalConfig).use(['juju-env-go'], function(Y) { |
| 10 environments = Y.namespace('juju.environments'); |
| 11 done(); |
| 12 }); |
| 13 }); |
| 14 |
| 15 it('provides a way to lowercase the keys of an object', function() { |
| 16 var obj = {Key1: 'value1', key2: 'value2', MyThirdKey: 'value3'}, |
| 17 expected = {key1: 'value1', key2: 'value2', mythirdkey: 'value3'}, |
| 18 result = environments.lowerObjectKeys(obj); |
| 19 assert.deepEqual(expected, result); |
| 20 }); |
| 21 |
| 22 }); |
| 23 |
5 describe('Go Juju environment', function() { | 24 describe('Go Juju environment', function() { |
6 var conn, endpointA, endpointB, env, juju, msg, utils, Y; | 25 var conn, endpointA, endpointB, env, juju, msg, utils, Y; |
7 | 26 |
8 before(function(done) { | 27 before(function(done) { |
9 Y = YUI(GlobalConfig).use(['juju-env', 'juju-tests-utils'], function(Y) { | 28 Y = YUI(GlobalConfig).use(['juju-env', 'juju-tests-utils'], function(Y) { |
10 juju = Y.namespace('juju'); | 29 juju = Y.namespace('juju'); |
11 utils = Y.namespace('juju-tests.utils'); | 30 utils = Y.namespace('juju-tests.utils'); |
12 done(); | 31 done(); |
13 }); | 32 }); |
14 }); | 33 }); |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 msg = conn.last_message(); | 667 msg = conn.last_message(); |
649 conn.msg({ | 668 conn.msg({ |
650 RequestId: msg.RequestId, | 669 RequestId: msg.RequestId, |
651 Error: 'service "yoursql" not found' | 670 Error: 'service "yoursql" not found' |
652 }); | 671 }); |
653 assert.equal(endpoint_a, 'yoursql:database'); | 672 assert.equal(endpoint_a, 'yoursql:database'); |
654 assert.equal(endpoint_b, 'wordpress:website'); | 673 assert.equal(endpoint_b, 'wordpress:website'); |
655 assert.equal(err, 'service "yoursql" not found'); | 674 assert.equal(err, 'service "yoursql" not found'); |
656 }); | 675 }); |
657 | 676 |
| 677 it('sends the correct CharmInfo message', function() { |
| 678 env.get_charm('cs:precise/wordpress-10'); |
| 679 var last_message = conn.last_message(); |
| 680 var expected = { |
| 681 Type: 'Client', |
| 682 Request: 'CharmInfo', |
| 683 Params: {CharmURL: 'cs:precise/wordpress-10'}, |
| 684 RequestId: 1 |
| 685 }; |
| 686 assert.deepEqual(expected, last_message); |
| 687 }); |
| 688 |
| 689 it('successfully retrieves information about a charm', function(done) { |
| 690 // Define a response example. |
| 691 var response = { |
| 692 Config: { |
| 693 Options: { |
| 694 debug: { |
| 695 Default: 'no', |
| 696 Description: 'Setting this option to "yes" will ...', |
| 697 Title: '', |
| 698 Type: 'string' |
| 699 }, |
| 700 engine: { |
| 701 Default: 'nginx', |
| 702 Description: 'Two web server engines are supported...', |
| 703 Title: '', |
| 704 Type: 'string' |
| 705 } |
| 706 } |
| 707 }, |
| 708 Meta: { |
| 709 Categories: null, |
| 710 Description: 'This will install and setup WordPress...', |
| 711 Format: 1, |
| 712 Name: 'wordpress', |
| 713 OldRevision: 0, |
| 714 Peers: { |
| 715 loadbalancer: { |
| 716 Interface: 'reversenginx', |
| 717 Limit: 1, |
| 718 Optional: false, |
| 719 Scope: 'global' |
| 720 } |
| 721 }, |
| 722 Provides: { |
| 723 website: { |
| 724 Interface: 'http', |
| 725 Limit: 0, |
| 726 Optional: false, |
| 727 Scope: 'global' |
| 728 } |
| 729 }, |
| 730 Requires: { |
| 731 cache: { |
| 732 Interface: 'memcache', |
| 733 Limit: 1, |
| 734 Optional: false, |
| 735 Scope: 'global' |
| 736 }, |
| 737 db: { |
| 738 Interface: 'mysql', |
| 739 Limit: 1, |
| 740 Optional: false, |
| 741 Scope: 'global' |
| 742 } |
| 743 }, |
| 744 Subordinate: false, |
| 745 Summary: 'WordPress is a full featured web blogging tool...' |
| 746 }, |
| 747 Revision: 10, |
| 748 URL: 'cs:precise/wordpress-10' |
| 749 }; |
| 750 // Define expected options. |
| 751 var options = response.Config.Options; |
| 752 var expectedOptions = { |
| 753 debug: { |
| 754 'default': options.debug.Default, |
| 755 description: options.debug.Description, |
| 756 type: options.debug.Type, |
| 757 title: options.debug.Title |
| 758 }, |
| 759 engine: { |
| 760 'default': options.engine.Default, |
| 761 description: options.engine.Description, |
| 762 type: options.engine.Type, |
| 763 title: options.engine.Title |
| 764 } |
| 765 }; |
| 766 // Define expected peers. |
| 767 var meta = response.Meta; |
| 768 var peer = meta.Peers.loadbalancer; |
| 769 var expectedPeers = { |
| 770 loadbalancer: { |
| 771 'interface': peer.Interface, |
| 772 limit: peer.Limit, |
| 773 optional: peer.Optional, |
| 774 scope: peer.Scope |
| 775 } |
| 776 }; |
| 777 // Define expected provides. |
| 778 var provide = meta.Provides.website; |
| 779 var expectedProvides = { |
| 780 website: { |
| 781 'interface': provide.Interface, |
| 782 limit: provide.Limit, |
| 783 optional: provide.Optional, |
| 784 scope: provide.Scope |
| 785 } |
| 786 }; |
| 787 // Define expected requires. |
| 788 var require1 = meta.Requires.cache; |
| 789 var require2 = meta.Requires.db; |
| 790 var expectedRequires = { |
| 791 cache: { |
| 792 'interface': require1.Interface, |
| 793 limit: require1.Limit, |
| 794 optional: require1.Optional, |
| 795 scope: require1.Scope |
| 796 }, |
| 797 db: { |
| 798 'interface': require2.Interface, |
| 799 limit: require2.Limit, |
| 800 optional: require2.Optional, |
| 801 scope: require2.Scope |
| 802 } |
| 803 }; |
| 804 env.get_charm('cs:precise/wordpress-10', function(data) { |
| 805 var err = data.err, |
| 806 result = data.result; |
| 807 // Ensure the result is correctly generated. |
| 808 assert.isUndefined(err); |
| 809 assert.deepEqual({options: expectedOptions}, result.config); |
| 810 assert.deepEqual(expectedPeers, result.peers); |
| 811 assert.deepEqual(expectedProvides, result.provides); |
| 812 assert.deepEqual(expectedRequires, result.requires); |
| 813 assert.equal(response.URL, result.url); |
| 814 // The result is enriched with additional info returned by juju-core. |
| 815 assert.equal(response.Revision, result.revision); |
| 816 assert.equal(meta.Description, result.description); |
| 817 assert.equal(meta.Format, result.format); |
| 818 assert.equal(meta.Name, result.name); |
| 819 assert.equal(meta.Subordinate, result.subordinate); |
| 820 assert.equal(meta.Summary, result.summary); |
| 821 done(); |
| 822 }); |
| 823 // Mimic response, assuming CharmInfo to be the first request. |
| 824 conn.msg({ |
| 825 RequestId: 1, |
| 826 Response: response |
| 827 }); |
| 828 }); |
| 829 |
| 830 it('handles failed attempt to retrieve charm info', function(done) { |
| 831 env.get_charm('cs:precise/wordpress-10', function(data) { |
| 832 var err = data.err, |
| 833 result = data.result; |
| 834 assert.equal('charm not found', err); |
| 835 assert.isUndefined(result); |
| 836 done(); |
| 837 }); |
| 838 // Mimic response, assuming CharmInfo to be the first request. |
| 839 conn.msg({ |
| 840 RequestId: 1, |
| 841 Error: 'charm not found' |
| 842 }); |
| 843 }); |
| 844 |
658 it('provides for a missing Params', function() { | 845 it('provides for a missing Params', function() { |
659 // If no "Params" are provided in an RPC call an empty one is added. | 846 // If no "Params" are provided in an RPC call an empty one is added. |
660 var op = {}; | 847 var op = {}; |
661 env._send_rpc(op); | 848 env._send_rpc(op); |
662 assert.deepEqual(op.Params, {}); | 849 assert.deepEqual(op.Params, {}); |
663 }); | 850 }); |
664 | 851 |
665 it('can watch all changes', function() { | 852 it('can watch all changes', function() { |
666 env._watchAll(); | 853 env._watchAll(); |
667 msg = conn.last_message(); | 854 msg = conn.last_message(); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 | 1021 |
835 it('converts "InstanceId" to "instance_id"', function() { | 1022 it('converts "InstanceId" to "instance_id"', function() { |
836 var converted = converter({InstanceId: 'instance ID'}); | 1023 var converted = converter({InstanceId: 'instance ID'}); |
837 assert.isTrue('instance_id' in converted); | 1024 assert.isTrue('instance_id' in converted); |
838 assert.equal('instance ID', converted.instance_id); | 1025 assert.equal('instance ID', converted.instance_id); |
839 }); | 1026 }); |
840 | 1027 |
841 }); | 1028 }); |
842 | 1029 |
843 })(); | 1030 })(); |
OLD | NEW |