From ddbaebae46a0815d4b80e63986656dcc05b58b38 Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Thu, 10 Sep 2015 11:20:06 +0200 Subject: [PATCH] add mysql unit tests Signed-off-by: Dominik Richter --- test/helper.rb | 5 ++++- test/unit/mock/files/mysql.conf | 8 ++++++++ test/unit/mock/files/mysql2.conf | 2 ++ test/unit/resource_mysql_conf_test.rb | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/unit/mock/files/mysql.conf create mode 100644 test/unit/mock/files/mysql2.conf create mode 100644 test/unit/resource_mysql_conf_test.rb diff --git a/test/helper.rb b/test/helper.rb index 5775a2260..b7ac1ee6f 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -12,6 +12,7 @@ SimpleCov.start do end require 'vulcano/backend' +require 'vulcano/resource' # loads a resource class and instantiates the class with the given arguments def loadResource (resource, *args) @@ -40,7 +41,9 @@ def loadResource (resource, *args) '/etc/security/limits.conf' => mockfile.('limits.conf'), '/etc/inetd.conf' => mockfile.('inetd.conf'), '/etc/group' => mockfile.('group'), - '/etc/audit/auditd.conf' => mockfile.('auditd.conf') + '/etc/audit/auditd.conf' => mockfile.('auditd.conf'), + '/etc/mysql/my.cnf' => mockfile.('mysql.conf'), + '/etc/mysql/mysql2.conf' => mockfile.('mysql2.conf') } # create all mock commands diff --git a/test/unit/mock/files/mysql.conf b/test/unit/mock/files/mysql.conf new file mode 100644 index 000000000..1bd5fb5cb --- /dev/null +++ b/test/unit/mock/files/mysql.conf @@ -0,0 +1,8 @@ +# a comment... +[client] +port = 3306 + +[mysqld] +user = mysql + +!include mysql2.conf diff --git a/test/unit/mock/files/mysql2.conf b/test/unit/mock/files/mysql2.conf new file mode 100644 index 000000000..da2d831c9 --- /dev/null +++ b/test/unit/mock/files/mysql2.conf @@ -0,0 +1,2 @@ +[mysqld] +key_buffer_size=16M diff --git a/test/unit/resource_mysql_conf_test.rb b/test/unit/resource_mysql_conf_test.rb new file mode 100644 index 000000000..11bd614e4 --- /dev/null +++ b/test/unit/resource_mysql_conf_test.rb @@ -0,0 +1,14 @@ +# encoding: utf-8 +require 'helper' + +describe 'Vulcano::Resources::MysqlConf' do + describe 'mysql_conf' do + let(:resource) { loadResource('mysql_conf', '/etc/mysql/my.cnf') } + + it 'verify mysql.conf config parsing' do + _(resource.client['port']).must_equal '3306' + _(resource.mysqld['user']).must_equal 'mysql' + _(resource.mysqld['key_buffer_size']).must_equal '16M' + end + end +end