Skip to content

Commit

Permalink
Merge pull request saltstack-formulas#197 from n-rodriguez/wip/tests
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
myii authored Sep 5, 2019
2 parents a2d094c + 6cba4af commit c40b983
Show file tree
Hide file tree
Showing 14 changed files with 346 additions and 46 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ services:
env:
matrix:
- INSTANCE: debian-debian-9-develop-py3
# - INSTANCE: debian-ubuntu-1804-develop-py3
# - INSTANCE: ubuntu-ubuntu-1804-develop-py3
# - INSTANCE: redhat-centos-7-develop-py3
# - INSTANCE: redhat-fedora-29-develop-py3
# - INSTANCE: suse-opensuse-leap-15-develop-py3
# - INSTANCE: debian-debian-9-2019-2-py3
- INSTANCE: debian-ubuntu-1804-2019-2-py3
- INSTANCE: ubuntu-ubuntu-1804-2019-2-py3
- INSTANCE: redhat-centos-7-2019-2-py3
# - INSTANCE: redhat-fedora-29-2019-2-py3
# - INSTANCE: suse-opensuse-leap-15-2019-2-py3
# - INSTANCE: debian-debian-9-2018-3-py2
# - INSTANCE: debian-ubuntu-1604-2018-3-py2
# - INSTANCE: ubuntu-ubuntu-1604-2018-3-py2
# - INSTANCE: redhat-centos-7-2018-3-py2
- INSTANCE: redhat-fedora-29-2018-3-py2
- INSTANCE: suse-opensuse-leap-42-2018-3-py2
# - INSTANCE: debian-debian-8-2017-7-py2
# - INSTANCE: debian-ubuntu-1604-2017-7-py2
# - INSTANCE: ubuntu-ubuntu-1604-2017-7-py2
- INSTANCE: redhat-centos-6-2017-7-py2
# - INSTANCE: redhat-fedora-28-2017-7-py2
# - INSTANCE: suse-opensuse-leap-42-2017-7-py2
Expand All @@ -54,7 +54,7 @@ jobs:
# Install and run `yamllint`
- pip install --user yamllint
# yamllint disable-line rule:line-length
- yamllint -s . .yamllint pillar.example test/salt/pillar/debian.sls test/salt/pillar/redhat.sls test/salt/pillar/suse.sls
- yamllint -s . .yamllint pillar.example test/salt/pillar/debian.sls test/salt/pillar/ubuntu.sls test/salt/pillar/redhat.sls test/salt/pillar/suse.sls
# Install and run `commitlint`
- npm install @commitlint/config-conventional -D
- npm install @commitlint/travis-cli -D
Expand Down
37 changes: 33 additions & 4 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,54 @@ suites:
- name: debian
includes:
- debian-9-develop-py3
- ubuntu-1804-develop-py3
- debian-9-2019-2-py3
- ubuntu-1804-2019-2-py3
- debian-9-2018-3-py2
- ubuntu-1604-2018-3-py2
- debian-8-2017-7-py2
provisioner:
state_top:
base:
'*':
- php.repo
- php.fpm.install
- php.fpm.config
- php.fpm.pools
- php.modules
- php.fpm.service
pillars:
top.sls:
base:
'*':
- php
pillars_from_files:
php.sls: test/salt/pillar/debian.sls
verifier:
inspec_tests:
- path: test/integration/default
- name: ubuntu
includes:
- ubuntu-1804-develop-py3
- ubuntu-1804-2019-2-py3
- ubuntu-1604-2018-3-py2
- ubuntu-1604-2017-7-py2
provisioner:
state_top:
base:
'*':
- php
- php.repo
- php.fpm.install
- php.fpm.config
- php.fpm.pools
- php.modules
- php.fpm.service
pillars:
top.sls:
base:
'*':
- php
- ubuntu
pillars_from_files:
php.sls: test/salt/pillar/debian.sls
ubuntu.sls: test/salt/pillar/ubuntu.sls
verifier:
inspec_tests:
- path: test/integration/default
Expand Down
36 changes: 23 additions & 13 deletions php/fpm/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,49 @@ include:
- php.fpm.pools

{% set pillar_php_version = salt['pillar.get']('php:version', '7.0') %}

extend:
php_fpm_service:
{% if pillar_php_version is iterable and pillar_php_version is not string %}
{% for version in pillar_php_version %}

php_fpm_service_{{ version }}:
service:
- watch:
{% if pillar_php_version is iterable and pillar_php_version is not string %}
{% for version in pillar_php_version %}
- file: php_fpm_ini_config_{{ version }}
- file: php_fpm_conf_config_{{ version }}
{% endfor %}
{% else %}
- file: php_fpm_ini_config
- file: php_fpm_conf_config
{% endif %}
- require:
- sls: php.fpm.config
{% if pillar_php_version is iterable and pillar_php_version is not string %}
{% for version in pillar_php_version %}

php_fpm_ini_config_{{ version }}:
file:
- require:
- pkg: php_install_fpm

php_fpm_conf_config_{{ version }}:
file:
- require:
- pkg: php_install_fpm
{% endfor %}
{% else %}

{% endfor %}

{% else %}

php_fpm_service:
service:
- watch:
- file: php_fpm_ini_config
- file: php_fpm_conf_config
- require:
- sls: php.fpm.config

php_fpm_ini_config:
file:
- require:
- pkg: php_install_fpm

php_fpm_conf_config:
file:
- require:
- pkg: php_install_fpm
{% endif %}

{% endif %}
26 changes: 20 additions & 6 deletions php/fpm/pools.sls
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
# Manages the php-fpm pools config files
{% from "php/map.jinja" import php with context %}
{% from "php/macro.jinja" import sls_block %}
{% from "php/macro.jinja" import file_requisites %}
{% from "php/fpm/pools_config.sls" import pool_states with context %}
{% macro file_requisites(states) %}
{%- for state in states %}
- file: {{ state }}
{%- endfor -%}
{% endmacro %}
include:
- php.fpm.service
- php.fpm.pools_config
{% set pillar_php_version = salt['pillar.get']('php:version', '7.0') %}
{% if pool_states %}
extend:
{% if pillar_php_version is iterable and pillar_php_version is not string %}
{% for version in pillar_php_version %}
php_fpm_service_{{ version }}:
service:
- watch:
{{ file_requisites(pool_states) }}
- require:
{{ file_requisites(pool_states) }}
{% endfor %}
{% else %}
php_fpm_service:
service:
- watch:
{{ file_requisites(pool_states) }}
- require:
{{ file_requisites(pool_states) }}
{% endif %}
{% endif %}
20 changes: 20 additions & 0 deletions php/fpm/service.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,28 @@
{% from "php/macro.jinja" import sls_block %}
{% set service_function = {True:'running', False:'dead'}.get(php.fpm.service.enabled) %}
{% set pillar_php_version = salt['pillar.get']('php:version', '7.0') %}
include:
- php.fpm.install
{% if pillar_php_version is iterable and pillar_php_version is not string %}
{% for version in pillar_php_version %}
php_fpm_service_{{ version }}:
service.{{ service_function }}:
{{ sls_block(php.fpm.service.opts) }}
- name: {{ 'php' ~ version ~ '-fpm' }}
- enable: {{ php.fpm.service.enabled }}
- require:
- sls: php.fpm.install
- watch:
- pkg: php_install_fpm
{% endfor %}
{% else %}
php_fpm_service:
service.{{ service_function }}:
{{ sls_block(php.fpm.service.opts) }}
Expand All @@ -16,3 +34,5 @@ php_fpm_service:
- sls: php.fpm.install
- watch:
- pkg: php_install_fpm
{% endif %}
14 changes: 14 additions & 0 deletions php/macro.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,17 @@

{{ ret|json() }}
{%- endmacro -%}

{% macro file_requisites(states) %}
{%- for state in states %}
- file: {{ state }}
{%- endfor -%}
{% endmacro %}

{%- macro format_kwargs(kwarg) -%}
{%- filter indent(4) %}
{%- for k, v in kwarg|dictsort() %}
- {{ k }}: {{ v }}
{%- endfor %}
{%- endfilter %}
{%- endmacro %}
7 changes: 4 additions & 3 deletions php/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
'php': 'php' + php_version,
'phpenmod_command': 'phpenmod -v' + php_version,
'pspell': 'php' + php_version + '-pspell',
'redis': 'php' + php_version + '-redis',
'readline': 'php' + php_version + '-readline',
'redis': 'php-redis',
'seclib': ['php-phpseclib', 'php-seclib'],
'snmp': 'php' + php_version + '-snmp',
'soap': 'php' + php_version + '-soap',
Expand All @@ -81,7 +82,7 @@
'tcpdf': 'php-tcpdf',
'temp_dir': '/tmp',
'tidy': 'php' + php_version + '-tidy',
'xdebug': 'php' + php_version + '-xdebug',
'xdebug': 'php-xdebug',
'xml': ['php' + php_version + '-xml', 'php' + php_version + '-xmlrpc'],
'xsl': 'php' + php_version + '-xsl',
'zip': 'php' + php_version + '-zip',
Expand Down Expand Up @@ -2263,7 +2264,7 @@
'tcpdf': 'php-tcpdf',
'temp_dir': '/tmp',
'tidy': 'php' + php_version + '-tidy',
'xdebug': 'php' + php_version + '-xdebug',
'xdebug': 'php-xdebug',
'xml': ['php' + php_version + '-xml', 'php' + php_version + '-xmlrpc'],
'xsl': 'php' + php_version + '-xsl',
'zip': 'php' + php_version + '-zip',
Expand Down
5 changes: 5 additions & 0 deletions php/repo/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .install
11 changes: 11 additions & 0 deletions php/repo/install.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import php with context %}
{%- from tplroot ~ "/macro.jinja" import format_kwargs with context %}
php/repo/install:
pkgrepo.managed:
{{- format_kwargs(php.repo) }}
38 changes: 38 additions & 0 deletions test/integration/default/controls/config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
control 'Php configuration' do
title 'should match desired lines'

def test_debian
describe file('/etc/php/5.6/fpm/pool.d/radius-admin.conf') do
its('content') { should include '[radius-admin]' }
its('content') { should include 'php_admin_value[date.timezone] = Europe/Paris' }
end

describe file('/etc/php/7.3/fpm/pool.d/ldap-admin.conf') do
its('content') { should include '[ldap-admin]' }
its('content') { should include 'php_admin_value[date.timezone] = Europe/Paris' }
end

describe file('/etc/php/5.6/fpm/php.ini') do
its('content') { should include 'date.timezone = Europe/Paris' }
end

describe file('/etc/php/7.3/fpm/php.ini') do
its('content') { should include 'date.timezone = Europe/Paris' }
end
end

def test_redhat
end

def test_suse
end

case os[:family]
when 'debian'
test_debian
when 'redhat', 'fedora'
test_redhat
when 'suse'
test_suse
end
end
Loading

0 comments on commit c40b983

Please sign in to comment.