import re import pytest from unit.applications.lang.go import TestApplicationGo class TestGoApplication(TestApplicationGo): prerequisites = {'modules': {'go': 'all'}} @pytest.fixture(autouse=True) def setup_method_fixture(self, skip_alert): skip_alert(r'\[unit\] close\(\d+\) failed: Bad file descriptor') def test_go_application_variables(self): self.load('variables') body = 'Test body string.' resp = self.post( headers={ 'Host': 'localhost', 'Content-Type': 'text/html', 'Custom-Header': 'blah', 'Connection': 'close', }, body=body, ) assert resp['status'] == 200, 'status' headers = resp['headers'] header_server = headers.pop('Server') assert re.search(r'Unit/[\d\.]+', header_server), 'server header' date = headers.pop('Date') assert date[-4:] == ' GMT', 'date header timezone' assert ( abs(self.date_to_sec_epoch(date) - self.sec_epoch()) < 5 ), 'date header' assert headers == { 'Content-Length': str(len(body)), 'Content-Type': 'text/html', 'Request-Method': 'POST', 'Request-Uri': '/', 'Http-Host': 'localhost', 'Server-Protocol': 'HTTP/1.1', 'Server-Protocol-Major': '1', 'Server-Protocol-Minor': '1', 'Custom-Header': 'blah', 'Connection': 'close', }, 'headers' assert resp['body'] == body, 'body' def test_go_application_get_variables(self): self.load('get_variables') resp = self.get(url='/?var1=val1&var2=&var3') assert resp['headers']['X-Var-1'] == 'val1', 'GET variables' assert resp['headers']['X-Var-2'] == '', 'GET variables 2' assert resp['headers']['X-Var-3'] == '', 'GET variables 3' def test_go_application_post_variables(self): self.load('post_variables') resp = self.post( headers={ 'Host': 'localhost', 'Content-Type': 'application/x-www-form-urlencoded', 'Connection': 'close', }, body='var1=val1&var2=&var3', ) assert resp['headers']['X-Var-1'] == 'val1', 'POST variables' assert resp['headers']['X-Var-2'] == '', 'POST variables 2' assert resp['headers']['X-Var-3'] == '', 'POST variables 3' def test_go_application_404(self): self.load('404') resp = self.get() assert resp['status'] == 404, '404 status' assert re.search( r'