diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2021-03-26 15:42:58 +0000 |
---|---|---|
committer | Andrei Zeliankou <zelenkov@nginx.com> | 2021-03-26 15:42:58 +0000 |
commit | c093ee7ec50233feb3ff0444c91e394abee4c52a (patch) | |
tree | 8767933f2f28fa074003f230ff91575d76ea3374 /test | |
parent | 97b4de0d4accfc7ccda561da9856db5f0f560b6b (diff) | |
download | unit-c093ee7ec50233feb3ff0444c91e394abee4c52a.tar.gz unit-c093ee7ec50233feb3ff0444c91e394abee4c52a.tar.bz2 |
Tests: added test for Ruby default encoding.
Diffstat (limited to '')
-rw-r--r-- | test/ruby/encoding/config.ru | 8 | ||||
-rw-r--r-- | test/test_ruby_application.py | 47 |
2 files changed, 55 insertions, 0 deletions
diff --git a/test/ruby/encoding/config.ru b/test/ruby/encoding/config.ru new file mode 100644 index 00000000..60bf0efa --- /dev/null +++ b/test/ruby/encoding/config.ru @@ -0,0 +1,8 @@ +app = Proc.new do |env| + ['200', { + 'Content-Length' => '0', + 'X-Enc' => Encoding.default_external.to_s, + }, ['']] +end + +run app diff --git a/test/test_ruby_application.py b/test/test_ruby_application.py index b18a6cee..12a078b7 100644 --- a/test/test_ruby_application.py +++ b/test/test_ruby_application.py @@ -1,4 +1,5 @@ import re +import subprocess import pytest from unit.applications.lang.ruby import TestApplicationRuby @@ -223,6 +224,52 @@ class TestRubyApplication(TestApplicationRuby): self.wait_for_record(r'\[error\].+At exit called\.') is not None ), 'at exit' + def test_ruby_application_encoding(self): + self.load('encoding') + + try: + locales = subprocess.check_output( + ['locale', '-a'], stderr=subprocess.STDOUT, + ).decode().split('\n') + + except (FileNotFoundError, subprocess.CalledProcessError): + pytest.skip('require locale') + + def get_locale(pattern): + return next( + ( + l + for l in locales + if re.match(pattern, l.upper()) is not None + ), + None, + ) + + utf8 = get_locale(r'.*UTF[-_]?8') + iso88591 = get_locale(r'.*ISO[-_]?8859[-_]?1') + + def check_locale(enc): + assert 'success' in self.conf( + {"LC_CTYPE": enc}, '/config/applications/encoding/environment', + ) + + resp = self.get() + assert resp['status'] == 200, 'status' + + enc_default = re.sub(r'[-_]', '', resp['headers']['X-Enc']).upper() + assert ( + enc_default == re.sub(r'[-_]', '', enc.split('.')[-1]).upper() + ) + + if utf8: + check_locale(utf8) + + if iso88591: + check_locale(iso88591) + + if not utf8 and not iso88591: + pytest.skip('no available locales') + def test_ruby_application_header_custom(self): self.load('header_custom') |