Skip to content
This repository has been archived by the owner on Nov 8, 2019. It is now read-only.

Add tests for mysql container #143

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "cont-postgresql"]
path = postgresql/cont-postgresql
url = https://github.com/devexp-db/cont-postgresql.git
[submodule "mysql/tests/steps/common_steps"]
path = mysql/tests/steps/common_steps
url = https://github.com/Containers-Testing-Framework/common-steps.git
[submodule "mysql/tests/features/common_features"]
path = mysql/tests/features/common_features
url = https://github.com/Containers-Testing-Framework/common-features.git
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sudo: required
services: docker
language: python

install:
- pip install behave ansible ctf-cli --upgrade

before_script:
- cd mysql

script:
- docker build -t fedora/mysql . && ctf-cli run -d IMAGE=fedora/mysql
2 changes: 1 addition & 1 deletion mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM fedora:20
FROM fedora:latest
MAINTAINER http://fedoraproject.org/wiki/Cloud

RUN yum -y update && yum clean all
Expand Down
7 changes: 7 additions & 0 deletions mysql/ctf.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[ctf]
ExecType=ansible

[ansible]
Host=192.168.1.1
Method=local
User=root
11 changes: 11 additions & 0 deletions mysql/tests/environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from steps.common_steps.common_environment import docker_setup


def before_all(context):
docker_setup(context)
context.build_or_pull_image(skip_pull=True, skip_build=True)
context.mysql = {}


def after_scenario(context, scenario):
context.remove_container()
1 change: 1 addition & 0 deletions mysql/tests/features/common_features
Submodule common_features added at 10a799
23 changes: 23 additions & 0 deletions mysql/tests/features/mysql.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Feature: MySQL connection

Scenario: Root account - positive test
When mysql container is started
Then mysql connection with parameters can be established:
| param | value |
| MYSQL_USER | root |
| MYSQL_PASSWORD | mysqlPassword |
| MYSQL_DATABASE | testdb |

Scenario Outline: Incorrect connection data for root account
When mysql container is started
Then mysql connection with parameters can not be established:
| param | value |
| MYSQL_USER | root |
| MYSQL_PASSWORD | <password> |
| MYSQL_DATABASE | <db> |

Examples:
| password | db |
| mysqlPassword1 | testdb |
| mysqlPassword | testdb1 |
| ' | testdb |
Empty file added mysql/tests/steps/__init__.py
Empty file.
1 change: 1 addition & 0 deletions mysql/tests/steps/common_steps
Submodule common_steps added at 6db5a3
41 changes: 41 additions & 0 deletions mysql/tests/steps/steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: UTF-8 -*-
from behave import when, then, given
from time import sleep
from common_steps import common_docker_steps, common_connection_steps


@when(u'mysql container is started')
def mysql_container_is_started(context):
# Read mysql params from context var
context.execute_steps(u'* Docker container is started with params " --privileged=true --name=ctf"')
sleep(10)


@then(u'mysql connection can be established')
@then(u'mysql connection can {action:w} be established')
@then(u'mysql connection with parameters can be established')
@then(u'mysql connection with parameters can {action:w} be established')
def mysql_connect(context, action=False):
if context.table:
for row in context.table:
context.mysql[row['param']] = row['value']

user = context.mysql['MYSQL_USER']
password = context.mysql['MYSQL_PASSWORD']
db = context.mysql['MYSQL_DATABASE']

context.execute_steps(u'* port 3306 is open')

for attempts in xrange(0, 5):
try:
context.run('docker run --rm -i --volumes-from=ctf %s mysql -u"%s" -p"%s" -e "SELECT 1;" %s' % (
context.image, user, password, db))
return
except AssertionError:
# If negative part was set, then we expect a bad code
# This enables steps like "can not be established"
if action != 'can':
return
sleep(5)

raise Exception("Failed to connect to mysql")