add tests

This commit is contained in:
Daniel Wallace 2017-05-02 16:16:51 -06:00
parent d32dfe46e3
commit 948830a4cb
2 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,6 @@
FROM opensuse/python:latest
RUN useradd -m daniel
USER daniel
ENTRYPOINT ["tail", "-f", "/dev/null"]

View File

@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
'''
Integration tests for the docker_container states
'''
# Import Python Libs
from __future__ import absolute_import
import functools
import random
import tempfile
# Import Salt Testing Libs
from tests.support.unit import skipIf
from tests.support.case import ModuleCase
from tests.support.paths import FILES, TMP
from tests.support.helpers import destructiveTest
from tests.support.mixins import SaltReturnAssertsMixin
def _random_name(prefix=''):
ret = prefix
for _ in range(8):
ret += random.choice(string.ascii_lowercase)
return ret
def with_random_name(func):
'''
generate a randomized name for a container
'''
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
name = _random_name(prefix='salt_')
return func(self, _random_name(prefix='salt_test_'), *args, **kwargs)
return wrapper
@destructiveTest
@skipIf(not salt.utils.which('dockerd'), 'Docker not installed')
class DockerCallTestCase(ModuleCase, SaltReturnAssertsMixin):
'''
Test docker_container states
'''
@with_random_name
def setUp(self, name):
'''
'''
# Create temp dir
self.random_name = name
tmp_build_dir= tempfile.mkdtemp(dir=TMP)
self.run_state('file.managed',
source='salt://docker_non_root/Dockerfile'
name='{0}/Dockerfile'.format(tmp_build_dir))
self.run_state('docker_image.present',
build=tmp_build_dir,
name=self.random_name)
self.run_state('docker_container.running',
name=self.random_name,
image=self.random_name)
def tearDown(self):
pass
def test_docker_call(self):
ret = self.run_function('docker.call', [self.random_name, 'test.ping'])
self.assertTrue(ret)