def test_utilio_exists(self): assets_dir = fetch_unittest_assets_dir() self.assertTrue(path_exists(assets_dir)) self.assertTrue(path_exists(assets_dir, 'copy-check-01')) self.assertTrue(path_exists(assets_dir, 'copy-check-01', 'test-file-a'))
def test_site_url_fetch_archive_tar_valid_external_extract(self): if not TAR.exists(): raise unittest.SkipTest('environment does not have a tar command') with httpd_context() as httpd: host, port = httpd.server_address site = 'http://{}:{}/test.tar'.format(host, port) httpd_assets = fetch_unittest_assets_dir('sample-files') archive = os.path.join(httpd_assets, 'sample-files.tar') with open(archive, 'rb') as f: data = f.read() httpd.rsp.append((200, data)) with prepare_testenv(template='minimal') as engine: root_dir = engine.opts.root_dir pkg_script = os.path.join(root_dir, 'package', 'minimal', 'minimal') with open(pkg_script, 'a') as f: f.write('MINIMAL_SITE="{}"\n'.format(site)) rv = engine.run() self.assertTrue(rv) outdir = os.environ['MINIMAL_BUILD_DIR'] stripped_file = os.path.join(outdir, 'tar-file-container.txt') self.assertTrue(os.path.exists(stripped_file))
def setUpClass(cls): opts = RelengEngineOptions() registry = RelengRegistry() cls.manager = RelengPackageManager(opts, registry) assets_dir = fetch_unittest_assets_dir() cls.configs_dir = os.path.join(assets_dir, CONFIGS_DIR)
def test_utilio_shebang_interpreter(self): si_dir = fetch_unittest_assets_dir('shebang-interpreter') si01 = [os.path.join(si_dir, 'interpreter')] si02 = [os.path.join(si_dir, 'interpreter-arg')] si03 = [os.path.join(si_dir, 'interpreter-args-multiple')] si04 = [os.path.join(si_dir, 'interpreter-extremely-long')] si05 = [os.path.join(si_dir, 'interpreter-whitespaces')] si06 = [os.path.join(si_dir, 'example.py')] # encode helper as helper utility will execute with encoded strings def E(val): rv = [] for v in val: rv.append(v.encode()) return rv # simple interpreter self.assertEqual(psi(si01), [b'interpreter'] + E(si01)) # interpreter with a single argument self.assertEqual(psi(si02), [b'interpreter', b'arg'] + E(si02)) # interpreter with a single argument (with whitespaces) self.assertEqual(psi(si03), [b'interpreter', b'arg1 arg2'] + E(si03)) # too long of an interpreter self.assertEqual(psi(si04), si04) # interpreter with whitespaces self.assertEqual(psi(si05), [b'interpreter'] + E(si05)) # real example of an interpreter self.assertEqual(psi(si06), [b'/usr/bin/env', b'python'] + E(si06))
def setUpClass(cls): cls.assets_dir = fetch_unittest_assets_dir() def assertExists(cls, path, *args): target = os.path.join(path, *args) cls.assertTrue(os.path.exists(target), 'missing file: ' + target) cls.assertExists = assertExists
def fetch_cert_files(): """ find certificate files for unit testing Returns a tuple of a key file and certificate file used to create a unit testing "secure" HTTP server. Dummy pem files are included in the testing asserts folder, which this call can return the paths to these files. Returns: 2-tuple of a key file and certificate file """ httpd_assets = fetch_unittest_assets_dir('httpd') keyfile = os.path.join(httpd_assets, 'test-notprivate-key-pem') certfile = os.path.join(httpd_assets, 'test-cert-pem') return keyfile, certfile
def test_site_url_fetch_archive_zip_valid(self): with httpd_context() as httpd: host, port = httpd.server_address site = 'http://{}:{}/test.zip'.format(host, port) httpd_assets = fetch_unittest_assets_dir('sample-files') archive = os.path.join(httpd_assets, 'sample-files.zip') with open(archive, 'rb') as f: data = f.read() httpd.rsp.append((200, data)) with prepare_testenv(template='minimal') as engine: root_dir = engine.opts.root_dir pkg_script = os.path.join(root_dir, 'package', 'minimal', 'minimal') with open(pkg_script, 'a') as f: f.write('MINIMAL_SITE="{}"\n'.format(site)) rv = engine.run() self.assertTrue(rv)
def setUpClass(cls): cls.assets_dir = fetch_unittest_assets_dir() cls.sample_files = os.path.join(cls.assets_dir, 'sample-files')
def setUpClass(cls): cls.template_base = 'subdir' sample_files = fetch_unittest_assets_dir('sample-files') archive = os.path.join(sample_files, 'sample-files.tar') cls.site = 'TEST_SITE=r"file:///{}"'.format(archive)
def test_site_url_fetch_archive_tar_valid_internal_extract(self): with httpd_context() as httpd: host, port = httpd.server_address site = 'http://{}:{}/test.tar'.format(host, port) httpd_assets = fetch_unittest_assets_dir('sample-files') archive = os.path.join(httpd_assets, 'sample-files.tar') with open(archive, 'rb') as f: data = f.read() with prepare_testenv(template='minimal') as engine: root_dir = engine.opts.root_dir pkg_script = os.path.join(root_dir, 'package', 'minimal', 'minimal') with open(pkg_script, 'a') as f: f.write('MINIMAL_SITE="{}"\n'.format(site)) otes = TAR.exists() try: # temporarily force a non-external tar command (if needed) RelengTool.detected[TAR_COMMAND] = False httpd.rsp.append((200, data)) rv = engine.run() finally: RelengTool.detected[TAR_COMMAND] = otes self.assertTrue(rv) outdir = os.environ['MINIMAL_BUILD_DIR'] stripped_file = os.path.join(outdir, 'tar-file-container.txt') self.assertTrue(os.path.exists(stripped_file)) with prepare_testenv(template='minimal') as engine: root_dir = engine.opts.root_dir pkg_script = os.path.join(root_dir, 'package', 'minimal', 'minimal') # redo tar fetch but with a no strip option with open(pkg_script, 'a') as f: f.write('MINIMAL_SITE="{}"\n'.format(site)) f.write('MINIMAL_STRIP_COUNT=0\n') try: RelengTool.detected[TAR_COMMAND] = False httpd.rsp.append((200, data)) rv = engine.run() finally: RelengTool.detected[TAR_COMMAND] = otes self.assertTrue(rv) outdir = os.environ['MINIMAL_BUILD_DIR'] sample_root_file = os.path.join(outdir, 'tar-file-root') container_dir = os.path.join(outdir, 'container') sample_container_file = os.path.join( container_dir, 'tar-file-container.txt') self.assertTrue(os.path.exists(sample_root_file)) self.assertTrue(os.path.exists(sample_container_file))