~tvansteenburgh/charms/precise/haproxy/sticky-sessions

« back to all changes in this revision

Viewing changes to hooks/tests/test_reverseproxy_hooks.py

  • Committer: Marco Ceppi
  • Date: 2014-01-24 12:44:31 UTC
  • mfrom: (74.1.7 fix-service-entries)
  • Revision ID: marco@ceppi.net-20140124124431-xbgxxhdxcu9qkv6y
[davidpbritton] Add test case and fix for backend "server" entries not getting unioned, when multiple units join the relation

Show diffs side-by-side

added added

removed removed

Lines of Context:
348
348
        self.assertEqual(expected, hooks.create_services())
349
349
        self.write_service_config.assert_called_with(expected)
350
350
 
351
 
    def test_with_service_options_in_relation(self):
 
351
    def test_with_multiple_units_in_relation(self):
 
352
        """
 
353
        Have multiple units specifying "services" in the relation.
 
354
        Make sure data is created correctly with create_services()
 
355
        """
352
356
        self.get_config_services.return_value = {
353
357
            None: {
354
358
                "service_name": "service",
364
368
                              4242, ["maxconn 4"])]
365
369
                 }])
366
370
             },
 
371
            {"port": 4242,
 
372
             "private-address": "1.2.3.5",
 
373
             "__unit__": "foo/1",
 
374
             "services": yaml.safe_dump([{
 
375
                 "service_name": "service",
 
376
                 "servers": [('foo-0', '1.2.3.5',
 
377
                              4242, ["maxconn 4"])]
 
378
                 }])
 
379
             },
367
380
        ]
368
381
 
369
382
        expected = {
371
384
                'service_name': 'service',
372
385
                'service_host': '0.0.0.0',
373
386
                'service_port': 10002,
374
 
                'servers': [('foo-0', '1.2.3.4',
375
 
                             4242, ["maxconn 4"])],
 
387
                'servers': [
 
388
                    ['foo-0', '1.2.3.4', 4242, ["maxconn 4"]],
 
389
                    ['foo-0', '1.2.3.5', 4242, ["maxconn 4"]]
 
390
                    ]
376
391
                },
377
392
            }
378
393
        self.assertEqual(expected, hooks.create_services())
379
394
        self.write_service_config.assert_called_with(expected)
 
395
 
 
396
    def test_merge_service(self):
 
397
        """ Make sure merge_services maintains "server" entries. """
 
398
        s1 = {'service_name': 'f', 'servers': [['f', '4', 4, ['maxconn 4']]]}
 
399
        s2 = {'service_name': 'f', 'servers': [['f', '5', 5, ['maxconn 4']]]}
 
400
 
 
401
        expected = {'service_name': 'f', 'servers': [
 
402
            ['f', '4', 4, ['maxconn 4']],
 
403
            ['f', '5', 5, ['maxconn 4']]]}
 
404
 
 
405
        self.assertEqual(expected, hooks.merge_service(s1, s2))
 
406
 
 
407
    def test_merge_service_removes_duplicates(self):
 
408
        """
 
409
        Make sure merge services strips strict duplicates from the
 
410
        'servers' entries.
 
411
        """
 
412
        s1 = {'servers': [['f', '4', 4, ['maxconn 4']]]}
 
413
        s2 = {'servers': [['f', '4', 4, ['maxconn 4']]]}
 
414
        expected = {'servers': [['f', '4', 4, ['maxconn 4']]]}
 
415
        self.assertEqual(expected, hooks.merge_service(s1, s2))
 
416
 
 
417
    def test_merge_service_merge_order(self):
 
418
        """ Make sure merge_services prefers the left side. """
 
419
        s1 = {'service_name': 'left', 'foo': 'bar'}
 
420
        s2 = {'service_name': 'right', 'bar': 'baz'}
 
421
 
 
422
        expected = {'service_name': 'left', 'foo': 'bar', 'bar': 'baz'}
 
423
        self.assertEqual(expected, hooks.merge_service(s1, s2))