From ce52cbb64a2a5ed09725485959dc7568e8936361 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Sun, 23 Apr 2017 20:02:40 +0300
Subject: [PATCH] - Correct URLs to PHP-FPM status and ping pages, updated
 tests accordingly. - Correct service test to use sudo. - Modify the status
 test to parse the json output.

---
 defaults/main.yml     |  4 ++--
 tests/test_php-fpm.py | 33 +++++++++++++++++++--------------
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/defaults/main.yml b/defaults/main.yml
index b978e74..48c28d5 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -17,7 +17,7 @@ php_fpm_www_pool_config:
     pm.start_servers: 2
     pm.min_spare_servers: 1
     pm.max_spare_servers: 3
-    pm.status_path: /status
-    ping.path: /ping
+    pm.status_path: /status.php
+    ping.path: /ping.php
     chdir: /
     chroot: '{{ php_fpm_chroot[ansible_os_family]|default(None) }}'
diff --git a/tests/test_php-fpm.py b/tests/test_php-fpm.py
index 1df008b..284261b 100644
--- a/tests/test_php-fpm.py
+++ b/tests/test_php-fpm.py
@@ -1,27 +1,30 @@
 from testinfra.utils.ansible_runner import AnsibleRunner
+import json
 
 testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all')
 
 
-def test_php_fpm_service(Service, SystemInfo, File):
+def test_php_fpm_service(Service, SystemInfo, File, Sudo):
     if SystemInfo.type == 'openbsd':
         service = Service('php56_fpm')
         socket = File('/var/www/run/php-fpm.sock')
         user = 'www'
-    elif SystemInfo.type == 'linux' and SystemInfo.distribution in ['debian',
-                                                                    'ubuntu']:
+    elif SystemInfo.type == 'linux' and SystemInfo.distribution in [
+            'debian', 'ubuntu'
+    ]:
         service = Service('php5-fpm')
         socket = File('/var/run/php5-fpm.sock')
         user = 'www-data'
-    assert socket.is_socket
-    assert socket.mode == 0o0660
-    assert socket.user == user
-    assert socket.group == user
-    assert service.is_running
-    try:
-        assert service.is_enabled
-    except NotImplementedError:
-        pass
+    with Sudo():
+        assert socket.is_socket
+        assert socket.mode == 0o0660
+        assert socket.user == user
+        assert socket.group == user
+        assert service.is_running
+        try:
+            assert service.is_enabled
+        except NotImplementedError:
+            pass
 
 
 def test_phpinfo(Command):
@@ -40,8 +43,10 @@ def test_php_fpm_config(Command, Sudo, SystemInfo):
 
 
 def test_php_fpm_status(Command):
-    assert 'PHP version 5' in Command(
-        'curl http://localhost/status.php').stdout
+    status = json.loads(
+        Command('curl http://localhost/status.php?json').stdout)
+    assert status['pool'] == 'www'
+    assert status['process manager'] == 'dynamic'
 
 
 def test_php_fpm_ping(Command):
-- 
GitLab