| 1 | import importlib.util |
| 2 | from pathlib import Path |
| 3 | import unittest |
| 4 | import sys |
| 5 | |
| 6 | sys.dont_write_bytecode = True |
| 7 | |
| 8 | spec = importlib.util.spec_from_file_location('editor_migrate', Path(__file__).with_name('editor-migrate.py')) |
| 9 | helper = importlib.util.module_from_spec(spec) |
| 10 | spec.loader.exec_module(helper) |
| 11 | |
| 12 | |
| 13 | class EditorIdentityTests(unittest.TestCase): |
| 14 | def setUp(self): |
| 15 | self.argv = [helper.NODE, helper.ROOT, '--bind-addr', '127.0.0.1:18080', '--config', helper.CONFIG, '--disable-telemetry', '/shared/project'] |
| 16 | self.exe = str(Path(helper.NODE).resolve()) |
| 17 | |
| 18 | def test_only_installed_cage_editor_identity_matches(self): |
| 19 | self.assertTrue(helper.is_legacy_editor(self.argv, self.exe, 1000, 1000)) |
| 20 | direct = self.argv.copy() |
| 21 | direct[1] = helper.ENTRY |
| 22 | self.assertTrue(helper.is_legacy_editor(direct, self.exe, 1000, 1000)) |
| 23 | self.assertFalse(helper.is_legacy_editor(self.argv, '/home/cage/fake-node', 1000, 1000)) |
| 24 | self.assertFalse(helper.is_legacy_editor(self.argv, self.exe, 1001, 1000)) |
| 25 | for index, value in ((1, '/home/cage/custom.js'), (3, '127.0.0.1:18081'), (5, '/home/cage/other.yaml')): |
| 26 | other = self.argv.copy() |
| 27 | other[index] = value |
| 28 | self.assertFalse(helper.is_legacy_editor(other, self.exe, 1000, 1000)) |
| 29 | self.assertFalse(helper.is_legacy_editor(['/bin/bash', '-l'], '/bin/bash', 1000, 1000)) |
| 30 | |
| 31 | |
| 32 | if __name__ == '__main__': |
| 33 | unittest.main() |