OLD | NEW |
1 /* | 1 /* |
2 This file is part of the Juju GUI, which lets users view and manage Juju | 2 This file is part of the Juju GUI, which lets users view and manage Juju |
3 environments within a graphical interface (https://launchpad.net/juju-gui). | 3 environments within a graphical interface (https://launchpad.net/juju-gui). |
4 Copyright (C) 2012-2013 Canonical Ltd. | 4 Copyright (C) 2012-2013 Canonical Ltd. |
5 | 5 |
6 This program is free software: you can redistribute it and/or modify it under | 6 This program is free software: you can redistribute it and/or modify it under |
7 the terms of the GNU Affero General Public License version 3, as published by | 7 the terms of the GNU Affero General Public License version 3, as published by |
8 the Free Software Foundation. | 8 the Free Software Foundation. |
9 | 9 |
10 This program is distributed in the hope that it will be useful, but WITHOUT | 10 This program is distributed in the hope that it will be useful, but WITHOUT |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 before(function(done) { | 50 before(function(done) { |
51 Y = YUI(GlobalConfig).use(requires, function(Y) { | 51 Y = YUI(GlobalConfig).use(requires, function(Y) { |
52 Simulator = Y.namespace('juju.environments').Simulator; | 52 Simulator = Y.namespace('juju.environments').Simulator; |
53 utils = Y.namespace('juju-tests.utils'); | 53 utils = Y.namespace('juju-tests.utils'); |
54 done(); | 54 done(); |
55 }); | 55 }); |
56 }); | 56 }); |
57 | 57 |
58 beforeEach(function(done) { | 58 beforeEach(function(done) { |
59 state = utils.makeFakeBackend(); | 59 utils.promiseImport('data/wp-deployer.yaml', 'wordpress-prod') |
60 var fixture = utils.loadFixture('data/sample-improv.json', false); | 60 .then(function(resolve) { |
61 state.importEnvironment(fixture, function(result) { | 61 state = resolve.backend; |
62 done(); | 62 done(); |
63 }); | 63 }); |
64 }); | 64 }); |
65 | 65 |
66 afterEach(function() { | 66 afterEach(function() { |
67 simulator.destroy(); | 67 simulator.destroy(); |
68 state.destroy(); | 68 state.destroy(); |
69 }); | 69 }); |
70 | 70 |
71 /** | 71 /** |
72 * `it` wrapper/generator that lets us write tests | 72 * `it` wrapper/generator that lets us write tests |
73 * that run after a single agent run cycle. | 73 * that run after a single agent run cycle. |
(...skipping 27 matching lines...) Expand all Loading... |
101 assert.equal(this.get('state'), state); | 101 assert.equal(this.get('state'), state); |
102 }); | 102 }); |
103 | 103 |
104 agentShould('should be able to run declared agents', function() { | 104 agentShould('should be able to run declared agents', function() { |
105 // Verify that our sample agent | 105 // Verify that our sample agent |
106 // added units. | 106 // added units. |
107 var db = state.db, | 107 var db = state.db, |
108 service = db.services.getById('wordpress'), | 108 service = db.services.getById('wordpress'), |
109 units = db.units.get_units_for_service(service); | 109 units = db.units.get_units_for_service(service); |
110 units = state.db.units.get_units_for_service(service); | 110 units = state.db.units.get_units_for_service(service); |
111 assert.equal(units.length, 11); | 111 assert.equal(units.length, 12); |
112 }); | 112 }); |
113 | 113 |
114 agentShould('honor threshold 0.0', function() { | 114 agentShould('honor threshold 0.0', function() { |
115 assert.isUndefined(this.get('hasRun')); | 115 assert.isUndefined(this.get('hasRun')); |
116 }, { | 116 }, { |
117 threshold: 0.0, | 117 threshold: 0.0, |
118 run: function(context) { | 118 run: function(context) { |
119 this.set('hasRun', true); | 119 this.set('hasRun', true); |
120 }}); | 120 }}); |
121 | 121 |
(...skipping 15 matching lines...) Expand all Loading... |
137 | 137 |
138 agentShould('be able to use random (0) for list for selection', function() { | 138 agentShould('be able to use random (0) for list for selection', function() { |
139 // A random selection of 0% results in no items. | 139 // A random selection of 0% results in no items. |
140 assert.equal(this.get('selection').size(), 0); | 140 assert.equal(this.get('selection').size(), 0); |
141 }, { | 141 }, { |
142 select: {list: 'services', random: 0.0} | 142 select: {list: 'services', random: 0.0} |
143 }); | 143 }); |
144 | 144 |
145 agentShould('be able to use random (1) for list for selection', function() { | 145 agentShould('be able to use random (1) for list for selection', function() { |
146 // A random selection of 0% results in no items. | 146 // A random selection of 0% results in no items. |
147 assert.equal(this.get('selection').size(), 5); | 147 assert.equal(this.get('selection').size(), 2); |
148 }, { | 148 }, { |
149 select: {list: 'services', random: 1.0} | 149 select: {list: 'services', random: 1.0} |
150 }); | 150 }); |
151 | 151 |
152 it('should not start or run callbacks when not logged in', function(done) { | 152 it('should not start or run callbacks when not logged in', function(done) { |
153 simulator = new Simulator({ | 153 simulator = new Simulator({ |
154 state: state, | 154 state: state, |
155 useDefaultAgents: false, | 155 useDefaultAgents: false, |
156 agents: { | 156 agents: { |
157 test: { | 157 test: { |
158 run: function() { this.set('running', true);} | 158 run: function() { this.set('running', true);} |
159 } | 159 } |
160 } | 160 } |
161 }); | 161 }); |
162 var agent = simulator._agents.test; | 162 var agent = simulator._agents.test; |
163 | 163 |
164 simulator.on('tick', function() { | 164 simulator.on('tick', function() { |
165 assert.isFalse(agent.get('started')); | 165 assert.isFalse(agent.get('started')); |
166 assert.isUndefined(agent.get('running')); | 166 assert.isUndefined(agent.get('running')); |
167 done(); | 167 done(); |
168 }); | 168 }); |
169 | 169 |
170 state.logout(); | 170 state.logout(); |
171 simulator.start(); | 171 simulator.start(); |
172 }); | 172 }); |
173 | 173 |
174 }); | 174 }); |
175 | 175 |
176 })(); | 176 })(); |
OLD | NEW |