summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2021-10-05 03:24:56 +0100
committerAndrei Zeliankou <zelenkov@nginx.com>2021-10-05 03:24:56 +0100
commit22028549c6172d8514b32ad2e31fc5512496dab6 (patch)
tree314b715a45d315b7b78e095d0ffc68493cc558ed
parent8db8330f8428ffe98e0129b8e4b9bba2042ad00e (diff)
downloadunit-22028549c6172d8514b32ad2e31fc5512496dab6.tar.gz
unit-22028549c6172d8514b32ad2e31fc5512496dab6.tar.bz2
Tests: added tests for "share" option with arrays.
-rw-r--r--test/test_static_share.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/test/test_static_share.py b/test/test_static_share.py
new file mode 100644
index 00000000..ad97cc3e
--- /dev/null
+++ b/test/test_static_share.py
@@ -0,0 +1,73 @@
+import os
+from pathlib import Path
+
+import pytest
+
+from unit.applications.proto import TestApplicationProto
+
+
+class TestStaticShare(TestApplicationProto):
+ prerequisites = {}
+
+ @pytest.fixture(autouse=True)
+ def setup_method_fixture(self, temp_dir):
+ os.makedirs(temp_dir + '/assets/dir')
+ os.makedirs(temp_dir + '/assets/dir2')
+
+ Path(temp_dir + '/assets/dir/file').write_text('1')
+ Path(temp_dir + '/assets/dir2/file2').write_text('2')
+
+ assert 'success' in self.conf(
+ {
+ "listeners": {"*:7080": {"pass": "routes"}},
+ "routes": [{"action": {"share": temp_dir + "/assets$uri"}}],
+ "applications": {},
+ }
+ )
+
+ def action_update(self, conf):
+ assert 'success' in self.conf(conf, 'routes/0/action')
+
+ def test_share_array(self, temp_dir):
+ assert self.get(url='/dir/file')['body'] == '1'
+ assert self.get(url='/dir2/file2')['body'] == '2'
+
+ self.action_update({"share": [temp_dir + "/assets/dir$uri"]})
+
+ assert self.get(url='/file')['body'] == '1'
+ assert self.get(url='/file2')['status'] == 404
+
+ self.action_update(
+ {
+ "share": [
+ temp_dir + "/assets/dir$uri",
+ temp_dir + "/assets/dir2$uri",
+ ]
+ }
+ )
+
+ assert self.get(url='/file')['body'] == '1'
+ assert self.get(url='/file2')['body'] == '2'
+
+ self.action_update(
+ {
+ "share": [
+ temp_dir + "/assets/dir2$uri",
+ temp_dir + "/assets/dir3$uri",
+ ]
+ }
+ )
+
+ assert self.get(url='/file')['status'] == 404
+ assert self.get(url='/file2')['body'] == '2'
+
+ def test_share_array_fallback(self):
+ self.action_update(
+ {"share": ["/blah", "/blah2"], "fallback": {"return": 201}}
+ )
+
+ assert self.get()['status'] == 201
+
+ def test_share_array_invalid(self):
+ assert 'error' in self.conf({"share": []}, 'routes/0/action')
+ assert 'error' in self.conf({"share": {}}, 'routes/0/action')