Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1093)

Side by Side Diff: test/test_model_handlers.js

Issue 13997043: Remove DB.units list
Patch Set: Remove DB.units list Created 11 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/test_model.js ('k') | test/test_notifications.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 27 matching lines...) Expand all
38 38
39 39
40 describe('pyDelta handler', function() { 40 describe('pyDelta handler', function() {
41 var pyDelta; 41 var pyDelta;
42 42
43 before(function() { 43 before(function() {
44 pyDelta = handlers.pyDelta; 44 pyDelta = handlers.pyDelta;
45 }); 45 });
46 46
47 it('replaces the attribute names when required', function() { 47 it('replaces the attribute names when required', function() {
48 var django = db.services.add({id: 'django'});
48 var change = { 49 var change = {
49 id: 'django/1', 50 id: 'django/1',
50 private_address: '10.0.0.1', 51 private_address: '10.0.0.1',
51 'public-address': 'example.com', 52 'public-address': 'example.com',
52 'is-subordinate': true, 53 'is-subordinate': true,
53 'hyphens-are-delicious': '42' 54 'hyphens-are-delicious': '42'
54 }; 55 };
55 pyDelta(db, 'add', change, 'unit'); 56 pyDelta(db, 'add', change, 'unit');
56 // Retrieve the unit from the database. 57 // Retrieve the unit from the database.
57 var unit = db.units.getById('django/1'); 58 var unit = django.get('units').getById('django/1');
58 assert.strictEqual('10.0.0.1', unit.private_address); 59 assert.strictEqual('10.0.0.1', unit.private_address);
59 assert.strictEqual('example.com', unit.public_address); 60 assert.strictEqual('example.com', unit.public_address);
60 assert.isTrue(unit.is_subordinate); 61 assert.isTrue(unit.is_subordinate);
61 assert.strictEqual('42', unit.hyphens_are_delicious); 62 assert.strictEqual('42', unit.hyphens_are_delicious);
62 }); 63 });
63 64
64 it('passes through environment annotations without changes', function() { 65 it('passes through environment annotations without changes', function() {
65 pyDelta(db, 'change', {'hyphenated-key': 'peanut'}, 'annotations'); 66 pyDelta(db, 'change', {'hyphenated-key': 'peanut'}, 'annotations');
66 assert.strictEqual( 67 assert.strictEqual(
67 'peanut', 68 'peanut',
68 db.environment.get('annotations')['hyphenated-key']); 69 db.environment.get('annotations')['hyphenated-key']);
69 }); 70 });
70 71
71 it('automatically handles changes to different model lists', function() { 72 it('automatically handles changes to different model lists', function() {
72 pyDelta(db, 'add', {id: 'django'}, 'service'); 73 pyDelta(db, 'add', {id: 'django'}, 'service');
73 pyDelta(db, 'add', {id: 'django/1'}, 'unit'); 74 pyDelta(db, 'add', {id: 'django/1'}, 'unit');
74 pyDelta(db, 'add', {id: '1'}, 'machine'); 75 pyDelta(db, 'add', {id: '1'}, 'machine');
75 assert.strictEqual(1, db.services.size()); 76 assert.strictEqual(1, db.services.size());
76 assert.strictEqual(1, db.units.size());
77 assert.strictEqual(1, db.machines.size()); 77 assert.strictEqual(1, db.machines.size());
78 assert.isNotNull(db.services.getById('django')); 78 var django = db.services.getById('django');
79 assert.isNotNull(db.units.getById('django/1')); 79 assert.isNotNull(django);
80 assert.isNotNull(django.get('units').getById('django/1'));
80 assert.isNotNull(db.machines.getById('1')); 81 assert.isNotNull(db.machines.getById('1'));
81 }); 82 });
82 83
83 it('automatically handles removals of model lists', function() { 84 it('automatically handles removals of model lists', function() {
84 db.services.add({ 85 var wordpress = db.services.add({
85 id: 'wordpress', 86 id: 'wordpress',
86 charm: 'cs:quantal/wordpress-11', 87 charm: 'cs:quantal/wordpress-11',
87 exposed: true 88 exposed: true
88 }); 89 });
89 db.units.add({ 90 wordpress.get('units').add({
90 id: 'wordpress/1', 91 id: 'wordpress/1',
91 agent_state: 'pending', 92 agent_state: 'pending',
92 public_address: 'example.com', 93 public_address: 'example.com',
93 private_address: '10.0.0.1' 94 private_address: '10.0.0.1'
94 }); 95 });
95 pyDelta(db, 'remove', 'wordpress/1', 'unit'); 96 pyDelta(db, 'remove', 'wordpress/1', 'unit');
96 pyDelta(db, 'remove', 'wordpress', 'service'); 97 pyDelta(db, 'remove', 'wordpress', 'service');
97 assert.strictEqual(0, db.services.size()); 98 assert.strictEqual(0, db.services.size());
98 assert.strictEqual(0, db.units.size()); 99 assert.strictEqual(0, wordpress.get('units').size());
99 }); 100 });
100 101
101 }); 102 });
102 103
103 104
104 describe('unitInfo handler', function() { 105 describe('unitInfo handler', function() {
105 var unitInfo; 106 var unitInfo;
106 107
107 before(function() { 108 before(function() {
108 unitInfo = handlers.unitInfo; 109 unitInfo = handlers.unitInfo;
109 }); 110 });
110 111
111 it('creates a unit in the database', function() { 112 it('creates a unit in the database', function() {
113 var django = db.services.add({id: 'django'});
112 var change = { 114 var change = {
113 Name: 'django/1', 115 Name: 'django/1',
114 Service: 'django', 116 Service: 'django',
115 MachineId: '1', 117 MachineId: '1',
116 Status: 'pending', 118 Status: 'pending',
117 StatusInfo: 'info', 119 StatusInfo: 'info',
118 PublicAddress: 'example.com', 120 PublicAddress: 'example.com',
119 PrivateAddress: '10.0.0.1', 121 PrivateAddress: '10.0.0.1',
120 Ports: [{Number: 80, Protocol: 'tcp'}, {Number: 42, Protocol: 'udp'}] 122 Ports: [{Number: 80, Protocol: 'tcp'}, {Number: 42, Protocol: 'udp'}]
121 }; 123 };
122 unitInfo(db, 'add', change); 124 unitInfo(db, 'add', change);
123 assert.strictEqual(1, db.units.size());
124 // Retrieve the unit from the database. 125 // Retrieve the unit from the database.
125 var unit = db.units.getById('django/1'); 126 var unit = django.get('units').getById('django/1');
126 assert.strictEqual('django', unit.service); 127 assert.strictEqual('django', unit.service);
127 assert.strictEqual('1', unit.machine); 128 assert.strictEqual('1', unit.machine);
128 assert.strictEqual('pending', unit.agent_state); 129 assert.strictEqual('pending', unit.agent_state);
129 assert.strictEqual('info', unit.agent_state_info); 130 assert.strictEqual('info', unit.agent_state_info);
130 assert.strictEqual('example.com', unit.public_address); 131 assert.strictEqual('example.com', unit.public_address);
131 assert.strictEqual('10.0.0.1', unit.private_address); 132 assert.strictEqual('10.0.0.1', unit.private_address);
132 assert.deepEqual(['80/tcp', '42/udp'], unit.open_ports); 133 assert.deepEqual(['80/tcp', '42/udp'], unit.open_ports);
133 }); 134 });
134 135
135 it('updates a unit in the database', function() { 136 it('updates a unit in the database', function() {
136 db.units.add({ 137 var django = db.services.add({id: 'django'});
138 django.get('units').add({
137 id: 'django/2', 139 id: 'django/2',
138 agent_state: 'pending', 140 agent_state: 'pending',
139 public_address: 'example.com', 141 public_address: 'example.com',
140 private_address: '10.0.0.1' 142 private_address: '10.0.0.1'
141 }); 143 });
142 var change = { 144 var change = {
143 Name: 'django/2', 145 Name: 'django/2',
144 Status: 'started', 146 Status: 'started',
145 PublicAddress: 'example.com', 147 PublicAddress: 'example.com',
146 PrivateAddress: '192.168.0.1' 148 PrivateAddress: '192.168.0.1'
147 }; 149 };
148 unitInfo(db, 'change', change); 150 unitInfo(db, 'change', change);
149 assert.strictEqual(1, db.units.size());
150 // Retrieve the unit from the database. 151 // Retrieve the unit from the database.
151 var unit = db.units.getById('django/2'); 152 var unit = django.get('units').getById('django/2');
152 assert.strictEqual('started', unit.agent_state); 153 assert.strictEqual('started', unit.agent_state);
153 assert.strictEqual('example.com', unit.public_address); 154 assert.strictEqual('example.com', unit.public_address);
154 assert.strictEqual('192.168.0.1', unit.private_address); 155 assert.strictEqual('192.168.0.1', unit.private_address);
155 }); 156 });
156 157
157 it('creates or updates the corresponding machine', function() { 158 it('creates or updates the corresponding machine', function() {
158 var machine; 159 var machine;
160 db.services.add({id: 'django'});
159 var change = { 161 var change = {
160 Name: 'django/2', 162 Name: 'django/2',
161 MachineId: '1', 163 MachineId: '1',
162 Status: 'pending', 164 Status: 'pending',
163 PublicAddress: 'example.com' 165 PublicAddress: 'example.com'
164 }; 166 };
165 unitInfo(db, 'add', change); 167 unitInfo(db, 'add', change);
166 assert.strictEqual(1, db.machines.size()); 168 assert.strictEqual(1, db.machines.size());
167 // Retrieve the machine from the database. 169 // Retrieve the machine from the database.
168 machine = db.machines.getById(1); 170 machine = db.machines.getById(1);
169 assert.strictEqual('example.com', machine.public_address); 171 assert.strictEqual('example.com', machine.public_address);
170 // Update the machine. 172 // Update the machine.
171 change.PublicAddress = 'example.com/foo'; 173 change.PublicAddress = 'example.com/foo';
172 unitInfo(db, 'change', change); 174 unitInfo(db, 'change', change);
173 assert.strictEqual(1, db.machines.size()); 175 assert.strictEqual(1, db.machines.size());
174 // Retrieve the machine from the database (again). 176 // Retrieve the machine from the database (again).
175 machine = db.machines.getById('1'); 177 machine = db.machines.getById('1');
176 assert.strictEqual('example.com/foo', machine.public_address); 178 assert.strictEqual('example.com/foo', machine.public_address);
177 }); 179 });
178 180
179 it('removes a unit from the database', function() { 181 it('removes a unit from the database', function() {
180 db.units.add({ 182 var django = db.services.add({id: 'django'});
183 var units = django.get('units');
184 units.add({
181 id: 'django/2', 185 id: 'django/2',
182 agent_state: 'pending', 186 agent_state: 'pending',
183 public_address: 'example.com', 187 public_address: 'example.com',
184 private_address: '10.0.0.1' 188 private_address: '10.0.0.1'
185 }); 189 });
186 var change = { 190 var change = {
187 Name: 'django/2', 191 Name: 'django/2',
188 Status: 'started', 192 Status: 'started',
189 PublicAddress: 'example.com', 193 PublicAddress: 'example.com',
190 PrivateAddress: '192.168.0.1' 194 PrivateAddress: '192.168.0.1'
191 }; 195 };
192 unitInfo(db, 'remove', change); 196 unitInfo(db, 'remove', change);
193 assert.strictEqual(0, db.units.size()); 197 assert.strictEqual(0, units.size());
194 }); 198 });
195 199
196 }); 200 });
197 201
198 202
199 describe('serviceInfo handler', function() { 203 describe('serviceInfo handler', function() {
200 var serviceInfo, constraints, config; 204 var serviceInfo, constraints, config;
201 205
202 before(function() { 206 before(function() {
203 serviceInfo = handlers.serviceInfo; 207 serviceInfo = handlers.serviceInfo;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 CharmURL: 'cs:quantal/wordpress-11', 267 CharmURL: 'cs:quantal/wordpress-11',
264 Exposed: false 268 Exposed: false
265 }; 269 };
266 serviceInfo(db, 'change', change); 270 serviceInfo(db, 'change', change);
267 assert.strictEqual(1, db.services.size()); 271 assert.strictEqual(1, db.services.size());
268 // Retrieve the service from the database. 272 // Retrieve the service from the database.
269 var service = db.services.getById('wordpress'); 273 var service = db.services.getById('wordpress');
270 assert.deepEqual({}, service.get('constraints')); 274 assert.deepEqual({}, service.get('constraints'));
271 }); 275 });
272 276
273 it('if configs are not in the change stream they are {}', 277 it('if configs are not in the change stream they are {}', function() {
274 function() { 278 db.services.add({
275 db.services.add({ 279 id: 'wordpress',
276 id: 'wordpress', 280 charm: 'cs:quantal/wordpress-11',
277 charm: 'cs:quantal/wordpress-11', 281 exposed: true
278 exposed: true 282 });
279 }); 283 var change = {
280 var change = { 284 Name: 'wordpress',
281 Name: 'wordpress', 285 CharmURL: 'cs:quantal/wordpress-11',
282 CharmURL: 'cs:quantal/wordpress-11', 286 Exposed: false
283 Exposed: false 287 };
284 }; 288 serviceInfo(db, 'change', change);
285 serviceInfo(db, 'change', change); 289 assert.strictEqual(1, db.services.size());
286 assert.strictEqual(1, db.services.size()); 290 // Retrieve the service from the database.
287 // Retrieve the service from the database. 291 var service = db.services.getById('wordpress');
288 var service = db.services.getById('wordpress'); 292 assert.deepEqual({}, service.get('config'));
289 assert.deepEqual({}, service.get('config')); 293 });
290 });
291 294
292 it('handles constraint changes', function() { 295 it('handles constraint changes', function() {
293 db.services.add({ 296 db.services.add({
294 id: 'wordpress', 297 id: 'wordpress',
295 charm: 'cs:quantal/wordpress-11', 298 charm: 'cs:quantal/wordpress-11',
296 exposed: true, 299 exposed: true,
297 constraints: constraints 300 constraints: constraints
298 }); 301 });
299 var changedConstraints = {'arch': 'i386'}; 302 var changedConstraints = {'arch': 'i386'};
300 var change = { 303 var change = {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 Tag: 'service-django', 516 Tag: 'service-django',
514 Annotations: annotations 517 Annotations: annotations
515 }; 518 };
516 annotationInfo(db, 'add', change); 519 annotationInfo(db, 'add', change);
517 // Retrieve the annotations from the database. 520 // Retrieve the annotations from the database.
518 var service = db.services.getById('django'); 521 var service = db.services.getById('django');
519 assert.deepEqual(annotations, service.get('annotations')); 522 assert.deepEqual(annotations, service.get('annotations'));
520 }); 523 });
521 524
522 it('stores annotations on a unit', function() { 525 it('stores annotations on a unit', function() {
523 db.units.add({id: 'django/2'}); 526 var django = db.services.add({id: 'django'});
527 var units = django.get('units');
528 units.add({id: 'django/2'});
524 var annotations = {'foo': '42', 'bar': '47'}; 529 var annotations = {'foo': '42', 'bar': '47'};
525 var change = { 530 var change = {
526 Tag: 'unit-django-2', 531 Tag: 'unit-django-2',
527 Annotations: annotations 532 Annotations: annotations
528 }; 533 };
529 annotationInfo(db, 'add', change); 534 annotationInfo(db, 'add', change);
530 // Retrieve the annotations from the database. 535 // Retrieve the annotations from the database.
531 var unit = db.units.getById('django/2'); 536 var unit = units.getById('django/2');
532 assert.deepEqual(annotations, unit.annotations); 537 assert.deepEqual(annotations, unit.annotations);
533 }); 538 });
534 539
535 it('stores annotations on a machine', function() { 540 it('stores annotations on a machine', function() {
536 db.machines.add({id: '1'}); 541 db.machines.add({id: '1'});
537 var annotations = {'foo': '42', 'bar': '47'}; 542 var annotations = {'foo': '42', 'bar': '47'};
538 var change = { 543 var change = {
539 Tag: 'machine-1', 544 Tag: 'machine-1',
540 Annotations: annotations 545 Annotations: annotations
541 }; 546 };
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 Tag: 'service-django', 582 Tag: 'service-django',
578 Annotations: annotations 583 Annotations: annotations
579 }; 584 };
580 annotationInfo(db, 'add', change); 585 annotationInfo(db, 'add', change);
581 // Retrieve the annotations from the database. 586 // Retrieve the annotations from the database.
582 var service = db.services.getById('django'); 587 var service = db.services.getById('django');
583 assert.isTrue(service.get('exposed')); 588 assert.isTrue(service.get('exposed'));
584 }); 589 });
585 590
586 it('does not override the unit relation_errors attr', function() { 591 it('does not override the unit relation_errors attr', function() {
592 var django = db.services.add({id: 'django'});
593 var units = django.get('units');
587 var relation_errors = {'cache': ['memcached']}, 594 var relation_errors = {'cache': ['memcached']},
588 annotations = {'foo': '42', 'bar': '47'}; 595 annotations = {'foo': '42', 'bar': '47'};
589 db.units.add({id: 'django/2', relation_errors: relation_errors}); 596 units.add({id: 'django/2', relation_errors: relation_errors});
590 var change = { 597 var change = {
591 Tag: 'unit-django-2', 598 Tag: 'unit-django-2',
592 Annotations: annotations 599 Annotations: annotations
593 }; 600 };
594 annotationInfo(db, 'add', change); 601 annotationInfo(db, 'add', change);
595 // Retrieve the annotations from the database. 602 // Retrieve the annotations from the database.
596 var unit = db.units.getById('django/2'); 603 var unit = units.getById('django/2');
597 assert.deepEqual(relation_errors, unit.relation_errors); 604 assert.deepEqual(relation_errors, unit.relation_errors);
598 }); 605 });
599 606
600 it('does not create new model instances', function() { 607 it('does not create new model instances', function() {
601 var annotations = {'gui-x': '42', 'gui-y': '47'}; 608 var annotations = {'gui-x': '42', 'gui-y': '47'};
602 var change = { 609 var change = {
603 Tag: 'service-django', 610 Tag: 'service-django',
604 Annotations: annotations 611 Annotations: annotations
605 }; 612 };
606 annotationInfo(db, 'add', change); 613 annotationInfo(db, 'add', change);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 729
723 it('returns an empty list if there are no endpoints', function() { 730 it('returns an empty list if there are no endpoints', function() {
724 assert.deepEqual([], createEndpoints([])); 731 assert.deepEqual([], createEndpoints([]));
725 }); 732 });
726 733
727 }); 734 });
728 735
729 }); 736 });
730 737
731 })(); 738 })();
OLDNEW
« no previous file with comments | « test/test_model.js ('k') | test/test_notifications.js » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b