Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
Move MockEtcd object outside of test_sidekick
Browse files Browse the repository at this point in the history
  • Loading branch information
a5huynh committed Feb 11, 2016
1 parent 2709301 commit 1acafc0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
14 changes: 14 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: ahuynh
# @Date: 2016-01-28 10:04:58
# @Last Modified by: ahuynh
# @Last Modified time: 2016-02-11 14:30:08


class MockEtcd( object ):
def delete( self, value ):
pass

def write( self, value, ttl ):
pass
28 changes: 9 additions & 19 deletions tests/test_sidekick.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,20 @@
# @Author: ahuynh
# @Date: 2015-06-18 20:15:30
# @Last Modified by: ahuynh
# @Last Modified time: 2015-06-19 17:06:28
# @Last Modified time: 2016-02-11 14:31:01
import unittest

from collections import namedtuple
from sidekick import announce_services, check_name, find_matching_container
from sidekick import check_health, public_ports
from sidekick import check_health, public_ports, parse_args

# Used to test command line arguments
Args = namedtuple('Args', ['name', 'ip', 'check_ip', 'vulcand'])


class MockEtcd( object ):
def delete( self, value ):
pass

def write( self, value, ttl ):
pass
from tests import MockEtcd


class TestSidekick( unittest.TestCase ):

def setUp( self ):

self.args = Args( name='test', ip='localhost', check_ip='0.0.0.0', vulcand=False )
self.args = parse_args( [ '--name', 'test', '--ip', 'localhost', '--check-ip', '0.0.0.0' ] )

self.etcd_client = MockEtcd()

Expand All @@ -46,23 +36,23 @@ def setUp( self ):
'Status': 'Up 2 days'}

def test_announce_services( self ):
''' Test `announce_services` functionality '''
""" Test `announce_services` functionality """
services = find_matching_container( [self.container], self.args )
announce_services( services.items(), 'test', self.etcd_client, 0, 0, False )

def test_check_health( self ):
''' Test `check_health` functionality '''
""" Test `check_health` functionality """
results = find_matching_container( [self.container], self.args )
for value in results.values():
self.assertFalse( check_health( value ) )

def test_check_name( self ):
''' Test `check_name` functionality '''
""" Test `check_name` functionality """
self.assertTrue( check_name( self.container, 'test' ) )
self.assertFalse( check_name( self.container, '/test' ) )

def test_find_matching_container( self ):
''' Test `find_matching_container` functionality '''
""" Test `find_matching_container` functionality """
# Test a successful match
results = find_matching_container( [self.container], self.args )
self.assertEqual( len( results.items() ), 2 )
Expand All @@ -80,5 +70,5 @@ def test_find_matching_container( self ):
find_matching_container( [no_open_ports], self.args )

def test_public_ports( self ):
''' Test `public_ports` functionality '''
""" Test `public_ports` functionality """
self.assertEquals( len( public_ports( self.container ) ), 2 )

0 comments on commit 1acafc0

Please sign in to comment.