Example #1
0
    def test_find_matching_container( self ):
        ''' Test `find_matching_container` functionality '''
        # Test a successful match
        results = find_matching_container( [self.container], self.args )
        self.assertEqual( len( results.items() ), 2 )

        # Test an unsuccessful match (no matching names)
        invalid_name = dict( self.container )
        invalid_name[ 'Names' ] = [ '/invalid_name' ]
        results = find_matching_container( [invalid_name], self.args )
        self.assertEqual( len( results.items() ), 0 )

        # Test an unsuccessful match (no public ports)
        no_open_ports = dict( self.container )
        no_open_ports['Ports'] = []
        with self.assertRaises( Exception ):
            find_matching_container( [no_open_ports], self.args )
Example #2
0
    def test_vulcand_announce( self ):
        """ Test `announce_services` functionality """
        services = find_matching_container( [ self.container ], self.args )

        # Successful health check
        with patch( 'sidekick.check_health', return_value=True ):
            announce_services( services.items(), 'test', self.etcd_client, 0, 0, True, self.args )
            self.assertEqual( len( self.etcd_client.written.keys() ), 4 )

        # Unsuccessful health check
        self.etcd_client._reset()
        with patch( 'sidekick.check_health', return_value=False ):
            announce_services( services.items(), 'test', self.etcd_client, 0, 0, True, self.args )
            self.assertEqual( len( self.etcd_client.deleted ), 4 )

        # Correct etcd exception handling
        self.etcd_client = MockEtcd( raise_exception=True )
        with patch( 'logging.error' ) as mock_method:
            announce_services( services.items(), 'test', self.etcd_client, 0, 0, True, self.args )
            self.assertEquals( str(mock_method.call_args[0][0]), 'Test Exception' )
Example #3
0
 def test_check_health( self ):
     ''' Test `check_health` functionality '''
     results = find_matching_container( [self.container], self.args )
     for value in results.values():
         self.assertFalse( check_health( value ) )
Example #4
0
 def test_announce_services( self ):
     ''' Test `announce_services` functionality '''
     services = find_matching_container( [self.container], self.args )
     announce_services( services.items(), 'test', self.etcd_client, 0, 0, False )