From 3e4fa1e2022970dee003bea0932ea0c10f8744ba Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Thu, 25 May 2023 14:26:12 +0100 Subject: Tests: removed unused variables. --- test/test_go_isolation_rootfs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/test_go_isolation_rootfs.py') diff --git a/test/test_go_isolation_rootfs.py b/test/test_go_isolation_rootfs.py index d246a48d..b321bc3f 100644 --- a/test/test_go_isolation_rootfs.py +++ b/test/test_go_isolation_rootfs.py @@ -8,7 +8,7 @@ class TestGoIsolationRootfs(TestApplicationGo): prerequisites = {'modules': {'go': 'all'}} @pytest.fixture(autouse=True) - def setup_method_fixture(self, request, skip_alert): + def setup_method_fixture(self, skip_alert): skip_alert(r'\[unit\] close\(\d+\) failed: Bad file descriptor') def test_go_isolation_rootfs_chroot(self, is_su, temp_dir): -- cgit From b034bf67034c4f0e966ebd207ba2f407f6f15fa8 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Thu, 25 May 2023 16:56:14 +0100 Subject: Tests: assertion related fixes. --- test/test_go_isolation_rootfs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/test_go_isolation_rootfs.py') diff --git a/test/test_go_isolation_rootfs.py b/test/test_go_isolation_rootfs.py index b321bc3f..b4d73ec8 100644 --- a/test/test_go_isolation_rootfs.py +++ b/test/test_go_isolation_rootfs.py @@ -26,7 +26,7 @@ class TestGoIsolationRootfs(TestApplicationGo): obj = self.getjson(url='/?file=/go/app')['body'] - assert obj['FileExists'] == True, 'app relative to rootfs' + assert obj['FileExists'], 'app relative to rootfs' obj = self.getjson(url='/?file=/bin/sh')['body'] - assert obj['FileExists'] == False, 'file should not exists' + assert not obj['FileExists'], 'file should not exists' -- cgit From ce2405ec3dd97e8bdf8f63312e3c6ce59ef562d4 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Mon, 12 Jun 2023 14:16:59 +0100 Subject: Tests: prerequisites checking reworked. Prerequisites check moved to the module level to simplify class structure. Discovery and prerequisites checks functions moved to the separate files. Introduced "require" fixture to provide per-test requirements check. --- test/test_go_isolation_rootfs.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'test/test_go_isolation_rootfs.py') diff --git a/test/test_go_isolation_rootfs.py b/test/test_go_isolation_rootfs.py index b4d73ec8..aa07b80d 100644 --- a/test/test_go_isolation_rootfs.py +++ b/test/test_go_isolation_rootfs.py @@ -1,26 +1,20 @@ -import os - import pytest from unit.applications.lang.go import TestApplicationGo +prerequisites = { + 'modules': {'go': 'all'}, + 'features': {'isolation': True}, + 'privileged_user': True, +} -class TestGoIsolationRootfs(TestApplicationGo): - prerequisites = {'modules': {'go': 'all'}} +class TestGoIsolationRootfs(TestApplicationGo): @pytest.fixture(autouse=True) def setup_method_fixture(self, skip_alert): skip_alert(r'\[unit\] close\(\d+\) failed: Bad file descriptor') - def test_go_isolation_rootfs_chroot(self, is_su, temp_dir): - if not is_su: - pytest.skip('requires root') - - if os.uname().sysname == 'Darwin': - pytest.skip('chroot tests not supported on OSX') - - isolation = { - 'rootfs': temp_dir, - } + def test_go_isolation_rootfs_chroot(self, temp_dir): + isolation = {'rootfs': temp_dir} self.load('ns_inspect', isolation=isolation) -- cgit From c6d05191a069ac150cc8eb2bece75cf79c0a465a Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Mon, 12 Jun 2023 17:28:42 +0100 Subject: Tests: removed alert skip, unnecessary after 1a48ea61fec8. --- test/test_go_isolation_rootfs.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'test/test_go_isolation_rootfs.py') diff --git a/test/test_go_isolation_rootfs.py b/test/test_go_isolation_rootfs.py index aa07b80d..1f5e93a1 100644 --- a/test/test_go_isolation_rootfs.py +++ b/test/test_go_isolation_rootfs.py @@ -9,10 +9,6 @@ prerequisites = { class TestGoIsolationRootfs(TestApplicationGo): - @pytest.fixture(autouse=True) - def setup_method_fixture(self, skip_alert): - skip_alert(r'\[unit\] close\(\d+\) failed: Bad file descriptor') - def test_go_isolation_rootfs_chroot(self, temp_dir): isolation = {'rootfs': temp_dir} -- cgit From c183bd8749a19477390f8cb77efe5f6d223f0905 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Wed, 14 Jun 2023 18:20:09 +0100 Subject: Tests: get rid of classes in test files. Class usage came from the unittest framework and it was always redundant after migration to the pytest. This commit removes classes from files containing tests to make them more readable and understandable. --- test/test_go_isolation_rootfs.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'test/test_go_isolation_rootfs.py') diff --git a/test/test_go_isolation_rootfs.py b/test/test_go_isolation_rootfs.py index 1f5e93a1..b627b515 100644 --- a/test/test_go_isolation_rootfs.py +++ b/test/test_go_isolation_rootfs.py @@ -1,5 +1,4 @@ -import pytest -from unit.applications.lang.go import TestApplicationGo +from unit.applications.lang.go import ApplicationGo prerequisites = { 'modules': {'go': 'all'}, @@ -7,16 +6,14 @@ prerequisites = { 'privileged_user': True, } +client = ApplicationGo() -class TestGoIsolationRootfs(TestApplicationGo): - def test_go_isolation_rootfs_chroot(self, temp_dir): - isolation = {'rootfs': temp_dir} - self.load('ns_inspect', isolation=isolation) +def test_go_isolation_rootfs_chroot(temp_dir): + client.load('ns_inspect', isolation={'rootfs': temp_dir}) - obj = self.getjson(url='/?file=/go/app')['body'] + obj = client.getjson(url='/?file=/go/app')['body'] + assert obj['FileExists'], 'app relative to rootfs' - assert obj['FileExists'], 'app relative to rootfs' - - obj = self.getjson(url='/?file=/bin/sh')['body'] - assert not obj['FileExists'], 'file should not exists' + obj = client.getjson(url='/?file=/bin/sh')['body'] + assert not obj['FileExists'], 'file should not exists' -- cgit