Skip to content

Commit c40b983

Browse files
authored
Merge pull request #197 from n-rodriguez/wip/tests
Add tests
2 parents a2d094c + 6cba4af commit c40b983

File tree

14 files changed

+346
-46
lines changed

14 files changed

+346
-46
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ services:
2020
env:
2121
matrix:
2222
- INSTANCE: debian-debian-9-develop-py3
23-
# - INSTANCE: debian-ubuntu-1804-develop-py3
23+
# - INSTANCE: ubuntu-ubuntu-1804-develop-py3
2424
# - INSTANCE: redhat-centos-7-develop-py3
2525
# - INSTANCE: redhat-fedora-29-develop-py3
2626
# - INSTANCE: suse-opensuse-leap-15-develop-py3
2727
# - INSTANCE: debian-debian-9-2019-2-py3
28-
- INSTANCE: debian-ubuntu-1804-2019-2-py3
28+
- INSTANCE: ubuntu-ubuntu-1804-2019-2-py3
2929
- INSTANCE: redhat-centos-7-2019-2-py3
3030
# - INSTANCE: redhat-fedora-29-2019-2-py3
3131
# - INSTANCE: suse-opensuse-leap-15-2019-2-py3
3232
# - INSTANCE: debian-debian-9-2018-3-py2
33-
# - INSTANCE: debian-ubuntu-1604-2018-3-py2
33+
# - INSTANCE: ubuntu-ubuntu-1604-2018-3-py2
3434
# - INSTANCE: redhat-centos-7-2018-3-py2
3535
- INSTANCE: redhat-fedora-29-2018-3-py2
3636
- INSTANCE: suse-opensuse-leap-42-2018-3-py2
3737
# - INSTANCE: debian-debian-8-2017-7-py2
38-
# - INSTANCE: debian-ubuntu-1604-2017-7-py2
38+
# - INSTANCE: ubuntu-ubuntu-1604-2017-7-py2
3939
- INSTANCE: redhat-centos-6-2017-7-py2
4040
# - INSTANCE: redhat-fedora-28-2017-7-py2
4141
# - INSTANCE: suse-opensuse-leap-42-2017-7-py2
@@ -54,7 +54,7 @@ jobs:
5454
# Install and run `yamllint`
5555
- pip install --user yamllint
5656
# yamllint disable-line rule:line-length
57-
- yamllint -s . .yamllint pillar.example test/salt/pillar/debian.sls test/salt/pillar/redhat.sls test/salt/pillar/suse.sls
57+
- 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
5858
# Install and run `commitlint`
5959
- npm install @commitlint/config-conventional -D
6060
- npm install @commitlint/travis-cli -D

kitchen.yml

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,25 +137,54 @@ suites:
137137
- name: debian
138138
includes:
139139
- debian-9-develop-py3
140-
- ubuntu-1804-develop-py3
141140
- debian-9-2019-2-py3
142-
- ubuntu-1804-2019-2-py3
143141
- debian-9-2018-3-py2
144-
- ubuntu-1604-2018-3-py2
145142
- debian-8-2017-7-py2
143+
provisioner:
144+
state_top:
145+
base:
146+
'*':
147+
- php.repo
148+
- php.fpm.install
149+
- php.fpm.config
150+
- php.fpm.pools
151+
- php.modules
152+
- php.fpm.service
153+
pillars:
154+
top.sls:
155+
base:
156+
'*':
157+
- php
158+
pillars_from_files:
159+
php.sls: test/salt/pillar/debian.sls
160+
verifier:
161+
inspec_tests:
162+
- path: test/integration/default
163+
- name: ubuntu
164+
includes:
165+
- ubuntu-1804-develop-py3
166+
- ubuntu-1804-2019-2-py3
167+
- ubuntu-1604-2018-3-py2
146168
- ubuntu-1604-2017-7-py2
147169
provisioner:
148170
state_top:
149171
base:
150172
'*':
151-
- php
173+
- php.repo
174+
- php.fpm.install
175+
- php.fpm.config
176+
- php.fpm.pools
177+
- php.modules
178+
- php.fpm.service
152179
pillars:
153180
top.sls:
154181
base:
155182
'*':
156183
- php
184+
- ubuntu
157185
pillars_from_files:
158186
php.sls: test/salt/pillar/debian.sls
187+
ubuntu.sls: test/salt/pillar/ubuntu.sls
159188
verifier:
160189
inspec_tests:
161190
- path: test/integration/default

php/fpm/init.sls

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,49 @@ include:
66
- php.fpm.pools
77

88
{% set pillar_php_version = salt['pillar.get']('php:version', '7.0') %}
9+
910
extend:
10-
php_fpm_service:
11+
{% if pillar_php_version is iterable and pillar_php_version is not string %}
12+
{% for version in pillar_php_version %}
13+
14+
php_fpm_service_{{ version }}:
1115
service:
1216
- watch:
13-
{% if pillar_php_version is iterable and pillar_php_version is not string %}
14-
{% for version in pillar_php_version %}
1517
- file: php_fpm_ini_config_{{ version }}
1618
- file: php_fpm_conf_config_{{ version }}
17-
{% endfor %}
18-
{% else %}
19-
- file: php_fpm_ini_config
20-
- file: php_fpm_conf_config
21-
{% endif %}
2219
- require:
2320
- sls: php.fpm.config
24-
{% if pillar_php_version is iterable and pillar_php_version is not string %}
25-
{% for version in pillar_php_version %}
21+
2622
php_fpm_ini_config_{{ version }}:
2723
file:
2824
- require:
2925
- pkg: php_install_fpm
26+
3027
php_fpm_conf_config_{{ version }}:
3128
file:
3229
- require:
3330
- pkg: php_install_fpm
34-
{% endfor %}
35-
{% else %}
31+
32+
{% endfor %}
33+
34+
{% else %}
35+
36+
php_fpm_service:
37+
service:
38+
- watch:
39+
- file: php_fpm_ini_config
40+
- file: php_fpm_conf_config
41+
- require:
42+
- sls: php.fpm.config
43+
3644
php_fpm_ini_config:
3745
file:
3846
- require:
3947
- pkg: php_install_fpm
48+
4049
php_fpm_conf_config:
4150
file:
4251
- require:
4352
- pkg: php_install_fpm
44-
{% endif %}
53+
54+
{% endif %}

php/fpm/pools.sls

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
11
# Manages the php-fpm pools config files
22
{% from "php/map.jinja" import php with context %}
33
{% from "php/macro.jinja" import sls_block %}
4+
{% from "php/macro.jinja" import file_requisites %}
45
{% from "php/fpm/pools_config.sls" import pool_states with context %}
56
6-
{% macro file_requisites(states) %}
7-
{%- for state in states %}
8-
- file: {{ state }}
9-
{%- endfor -%}
10-
{% endmacro %}
11-
127
include:
138
- php.fpm.service
149
- php.fpm.pools_config
1510
11+
{% set pillar_php_version = salt['pillar.get']('php:version', '7.0') %}
12+
1613
{% if pool_states %}
1714
extend:
15+
16+
{% if pillar_php_version is iterable and pillar_php_version is not string %}
17+
{% for version in pillar_php_version %}
18+
php_fpm_service_{{ version }}:
19+
service:
20+
- watch:
21+
{{ file_requisites(pool_states) }}
22+
- require:
23+
{{ file_requisites(pool_states) }}
24+
25+
{% endfor %}
26+
27+
{% else %}
28+
1829
php_fpm_service:
1930
service:
2031
- watch:
2132
{{ file_requisites(pool_states) }}
2233
- require:
2334
{{ file_requisites(pool_states) }}
35+
36+
{% endif %}
37+
2438
{% endif %}

php/fpm/service.sls

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,28 @@
33
{% from "php/macro.jinja" import sls_block %}
44
55
{% set service_function = {True:'running', False:'dead'}.get(php.fpm.service.enabled) %}
6+
{% set pillar_php_version = salt['pillar.get']('php:version', '7.0') %}
67
78
include:
89
- php.fpm.install
910
11+
{% if pillar_php_version is iterable and pillar_php_version is not string %}
12+
{% for version in pillar_php_version %}
13+
14+
php_fpm_service_{{ version }}:
15+
service.{{ service_function }}:
16+
{{ sls_block(php.fpm.service.opts) }}
17+
- name: {{ 'php' ~ version ~ '-fpm' }}
18+
- enable: {{ php.fpm.service.enabled }}
19+
- require:
20+
- sls: php.fpm.install
21+
- watch:
22+
- pkg: php_install_fpm
23+
24+
{% endfor %}
25+
26+
{% else %}
27+
1028
php_fpm_service:
1129
service.{{ service_function }}:
1230
{{ sls_block(php.fpm.service.opts) }}
@@ -16,3 +34,5 @@ php_fpm_service:
1634
- sls: php.fpm.install
1735
- watch:
1836
- pkg: php_install_fpm
37+
38+
{% endif %}

php/macro.jinja

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,17 @@
2727

2828
{{ ret|json() }}
2929
{%- endmacro -%}
30+
31+
{% macro file_requisites(states) %}
32+
{%- for state in states %}
33+
- file: {{ state }}
34+
{%- endfor -%}
35+
{% endmacro %}
36+
37+
{%- macro format_kwargs(kwarg) -%}
38+
{%- filter indent(4) %}
39+
{%- for k, v in kwarg|dictsort() %}
40+
- {{ k }}: {{ v }}
41+
{%- endfor %}
42+
{%- endfilter %}
43+
{%- endmacro %}

php/map.jinja

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
'php': 'php' + php_version,
6868
'phpenmod_command': 'phpenmod -v' + php_version,
6969
'pspell': 'php' + php_version + '-pspell',
70-
'redis': 'php' + php_version + '-redis',
70+
'readline': 'php' + php_version + '-readline',
71+
'redis': 'php-redis',
7172
'seclib': ['php-phpseclib', 'php-seclib'],
7273
'snmp': 'php' + php_version + '-snmp',
7374
'soap': 'php' + php_version + '-soap',
@@ -81,7 +82,7 @@
8182
'tcpdf': 'php-tcpdf',
8283
'temp_dir': '/tmp',
8384
'tidy': 'php' + php_version + '-tidy',
84-
'xdebug': 'php' + php_version + '-xdebug',
85+
'xdebug': 'php-xdebug',
8586
'xml': ['php' + php_version + '-xml', 'php' + php_version + '-xmlrpc'],
8687
'xsl': 'php' + php_version + '-xsl',
8788
'zip': 'php' + php_version + '-zip',
@@ -2263,7 +2264,7 @@
22632264
'tcpdf': 'php-tcpdf',
22642265
'temp_dir': '/tmp',
22652266
'tidy': 'php' + php_version + '-tidy',
2266-
'xdebug': 'php' + php_version + '-xdebug',
2267+
'xdebug': 'php-xdebug',
22672268
'xml': ['php' + php_version + '-xml', 'php' + php_version + '-xmlrpc'],
22682269
'xsl': 'php' + php_version + '-xsl',
22692270
'zip': 'php' + php_version + '-zip',

php/repo/init.sls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
include:
5+
- .install

php/repo/install.sls

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
{#- Get the `tplroot` from `tpldir` #}
5+
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- from tplroot ~ "/map.jinja" import php with context %}
7+
{%- from tplroot ~ "/macro.jinja" import format_kwargs with context %}
8+
9+
php/repo/install:
10+
pkgrepo.managed:
11+
{{- format_kwargs(php.repo) }}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
control 'Php configuration' do
2+
title 'should match desired lines'
3+
4+
def test_debian
5+
describe file('/etc/php/5.6/fpm/pool.d/radius-admin.conf') do
6+
its('content') { should include '[radius-admin]' }
7+
its('content') { should include 'php_admin_value[date.timezone] = Europe/Paris' }
8+
end
9+
10+
describe file('/etc/php/7.3/fpm/pool.d/ldap-admin.conf') do
11+
its('content') { should include '[ldap-admin]' }
12+
its('content') { should include 'php_admin_value[date.timezone] = Europe/Paris' }
13+
end
14+
15+
describe file('/etc/php/5.6/fpm/php.ini') do
16+
its('content') { should include 'date.timezone = Europe/Paris' }
17+
end
18+
19+
describe file('/etc/php/7.3/fpm/php.ini') do
20+
its('content') { should include 'date.timezone = Europe/Paris' }
21+
end
22+
end
23+
24+
def test_redhat
25+
end
26+
27+
def test_suse
28+
end
29+
30+
case os[:family]
31+
when 'debian'
32+
test_debian
33+
when 'redhat', 'fedora'
34+
test_redhat
35+
when 'suse'
36+
test_suse
37+
end
38+
end

0 commit comments

Comments
 (0)