[PATCH v6 07/15] Tests: added tests for "index" option.

Alejandro Colomar alx.manpages at gmail.com
Tue Feb 15 14:57:47 UTC 2022


From: Andrei Zeliankou <zelenkov at nginx.com>

Authored-by: Andrei Zeliankou <zelenkov at nginx.com>
Signed-off-by: Alejandro Colomar <alx.manpages at gmail.com>
Cc: Nginx Unit <unit at nginx.org>
Cc: "Valentin V. Bartenev" <vbart at nginx.com>
Cc: Zhidao HONG <z.hong at f5.com>
Cc: Igor Sysoev <igor at sysoev.ru>
Cc: Oisin Canty <o.canty at f5.com>
Cc: Maxim Romanov <m.romanov at f5.com>
---
 test/test_static.py | 47 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/test/test_static.py b/test/test_static.py
index 656bb7d..bb96f09 100644
--- a/test/test_static.py
+++ b/test/test_static.py
@@ -91,6 +91,53 @@ class TestStatic(TestApplicationProto):
         assert self.get(url='/')['body'] == '0123456789', 'before 1.26.0 2'
 
     def test_static_index(self):
+        def set_index(index):
+            assert 'success' in self.conf(
+                {"share": option.temp_dir + "/assets$uri", "index": index},
+                'routes/0/action',
+            ), 'configure index'
+
+        set_index('README')
+        assert self.get()['body'] == 'readme', 'index'
+
+        self.conf_delete('routes/0/action/index')
+        assert self.get()['body'] == '0123456789', 'delete index'
+
+        set_index('$host')
+        assert (
+            self.get(headers={"Host": "README", "Connection": "close"})['body']
+            == 'readme'
+        ), 'index var'
+        self.get(headers={"Connection": "close"})[
+            'status'
+        ] == 404, 'index var empty'
+
+        set_index([])
+        self.get()['status'] == 404, 'index array empty'
+
+        set_index(['blah'])
+        self.get()['status'] == 404, 'index array not found'
+
+        set_index(['$host', 'blah', 'index.html'])
+        assert self.get()['body'] == '0123456789', 'index array'
+        assert (
+            self.get(headers={"Host": "README", "Connection": "close"})['body']
+            == 'readme'
+        ), 'index array 2'
+
+    def test_static_index_invalid(self, skip_alert):
+        skip_alert(r'failed to apply new conf')
+
+        def check_index(index):
+            assert 'error' in self.conf(
+                {"share": option.temp_dir + "/assets$uri", "index": index},
+                'routes/0/action',
+            )
+
+        check_index({})
+        check_index(['index.html', '$blah'])
+
+    def test_static_index_default(self):
         assert self.get(url='/index.html')['body'] == '0123456789', 'index'
         assert self.get(url='/')['body'] == '0123456789', 'index 2'
         assert self.get(url='//')['body'] == '0123456789', 'index 3'
-- 
2.34.1



More information about the unit mailing list