This repository has been archived by the owner on Oct 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tests for different sidekick functionality
- Loading branch information
Showing
6 changed files
with
149 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[run] | ||
omit=*.pyenvs*,*site-packages*,tests/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
python_paths = tests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
py.test --cov . --cov-report html --capture=no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# @Author: ahuynh | ||
# @Date: 2015-06-18 20:15:30 | ||
# @Last Modified by: ahuynh | ||
# @Last Modified time: 2015-06-18 21:07:08 | ||
import unittest | ||
|
||
from collections import namedtuple | ||
from sidekick import check_name, find_matching_container, health_check, public_ports | ||
|
||
# Used to test command line arguments | ||
Args = namedtuple('Args', ['name', 'ip']) | ||
|
||
|
||
class TestSidekick( unittest.TestCase ): | ||
|
||
def setUp( self ): | ||
|
||
self.args = Args( name='test', ip='localhost' ) | ||
|
||
self.container = { | ||
'Image': 'image:latest', | ||
'Ports': [{ | ||
'PrivatePort': 9200, | ||
'IP': '0.0.0.0', | ||
'Type': 'tcp', | ||
'PublicPort': 9200 }, { | ||
'PrivatePort': 9300, | ||
'IP': '0.0.0.0', | ||
'Type': 'tcp', | ||
'PublicPort': 9300}], | ||
'Created': 1427906382, | ||
'Names': ['/test'], | ||
'Status': 'Up 2 days'} | ||
|
||
def test_check_name( self ): | ||
''' 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 a successful match | ||
results = find_matching_container( [self.container], self.args ) | ||
self.assertEqual( len( results.keys() ), 2 ) | ||
|
||
# Test an unsuccessful match | ||
no_open_ports = dict( self.container ) | ||
no_open_ports['Ports'] = [] | ||
with self.assertRaises( Exception ): | ||
find_matching_container( [no_open_ports], self.args ) | ||
|
||
def test_health_check( self ): | ||
''' Test `health_check` functionality ''' | ||
results = find_matching_container( [self.container], self.args ) | ||
for value in results.values(): | ||
self.assertFalse( health_check( value ) ) | ||
|
||
def test_public_ports( self ): | ||
''' Test `public_ports` functionality ''' | ||
self.assertEquals( len( public_ports( self.container ) ), 2 ) |