Skip to content

Commit

Permalink
Adjust unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Jun 25, 2022
1 parent 5142f37 commit bab1e14
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions tests/unit/plugins/inventory/test_docker_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,29 +93,22 @@ def get_option(option):

class FakeClient(object):
def __init__(self, *hosts):
self.hosts = dict()
self.list_reply = []
self.get_results = {}
list_reply = []
for host in hosts:
self.list_reply.append({
list_reply.append({
'Id': host['Id'],
'Names': [host['Name']] if host['Name'] else [],
'Image': host['Config']['Image'],
'ImageId': host['Image'],
})
self.hosts[host['Name']] = host
self.hosts[host['Id']] = host
self.get_results['/containers/{0}/json'.format(host['Name'])] = host
self.get_results['/containers/{0}/json'.format(host['Id'])] = host
self.get_results['/containers/json'] = list_reply

def containers(self, all=False):
return list(self.list_reply)

def inspect_container(self, id):
return self.hosts[id]

def port(self, container, port):
host = self.hosts[container['Id']]
network_settings = host.get('NetworkSettings') or dict()
ports = network_settings.get('Ports') or dict()
return ports.get('{0}/tcp'.format(port)) or []
def get_json(self, url, *param, **kwargs):
url = url.format(*param)
return self.get_results[url]


def test_populate(inventory, mocker):
Expand Down

0 comments on commit bab1e14

Please sign in to comment.