def test_update_erlang_relink_deps(self, mock_conf, _): mock_conf.return_value = self.conf_file pack_path = join(self.test_dir, 'test_app') set_deps(pack_path, [ {'name': 'dep_with_no_deps', 'url': 'https://github.com/comtihon/dep_with_no_deps', 'tag': '1.0.0'} ]) create(self.tmp_dir, {'<name>': 'dep_with_no_deps'}) dep_dir = join(self.tmp_dir, 'dep_with_no_deps') set_git_url(dep_dir, 'http://github/comtihon/dep_with_no_deps') set_git_tag(dep_dir, '1.0.0') # This is not needed but pretend we really fetch it from git with patch.object(Static, 'get_erlang_version', return_value='18'): builder = Builder.init_from_path(pack_path) builder.populate() self.assertEqual(True, builder.build()) dep_link_ebin = join(pack_path, 'deps', 'dep_with_no_deps', 'ebin') self.assertEqual(True, os.path.islink(dep_link_ebin)) erl = Static.get_erlang_version() real_dep = join(self.cache_dir, 'comtihon', 'dep_with_no_deps', '1.0.0', erl, 'ebin') self.assertEqual(real_dep, os.readlink(dep_link_ebin)) with patch.object(Static, 'get_erlang_version', return_value='22'): builder = Builder.init_from_path(pack_path) builder.populate() self.assertEqual(True, builder.build()) dep_link_ebin = join(pack_path, 'deps', 'dep_with_no_deps', 'ebin') self.assertEqual(True, os.path.islink(dep_link_ebin)) erl2 = Static.get_erlang_version() real_dep = join(self.cache_dir, 'comtihon', 'dep_with_no_deps', '1.0.0', erl2, 'ebin') self.assertEqual(real_dep, os.readlink(dep_link_ebin)) self.assertNotEqual(erl, erl2)
def test_change_tag_new_dep(self, mock_conf, _): mock_conf.return_value = self.conf_file pack_path = join(self.test_dir, 'test_app') set_deps(pack_path, [ {'name': 'dep_with_no_deps', 'url': 'https://github.com/comtihon/dep_with_no_deps', 'tag': '1.0.0'} ]) create(self.tmp_dir, {'<name>': 'dep_with_no_deps'}) dep_dir = join(self.tmp_dir, 'dep_with_no_deps') set_git_url(dep_dir, 'http://github/comtihon/dep_with_no_deps') set_git_tag(dep_dir, '1.0.0') builder = Builder.init_from_path(pack_path) builder.populate() self.assertEqual(True, builder.build()) dep_link_ebin = join(pack_path, 'deps', 'dep_with_no_deps', 'ebin') self.assertEqual(True, os.path.islink(dep_link_ebin)) erl = Static.get_erlang_version() real_dep = join(self.cache_dir, 'comtihon', 'dep_with_no_deps', '1.0.0', erl, 'ebin') self.assertEqual(real_dep, os.readlink(dep_link_ebin)) # Dep version was changed set_deps(pack_path, [ {'name': 'dep_with_no_deps', 'url': 'https://github.com/comtihon/dep_with_no_deps', 'tag': '1.0.1'} ]) set_git_tag(dep_dir, '1.0.1') set_deps(dep_dir, [ {'name': 'new_dep', 'url': 'https://github.com/comtihon/new_dep', 'tag': '1.0.0'} ]) create(self.tmp_dir, {'<name>': 'new_dep'}) new_dep_dir = join(self.tmp_dir, 'new_dep') set_git_url(new_dep_dir, 'http://github/comtihon/new_dep') set_git_tag(new_dep_dir, '1.0.0') builder = Builder.init_from_path(pack_path) builder.populate() self.assertEqual(True, builder.build()) dep_link_ebin = join(pack_path, 'deps', 'dep_with_no_deps', 'ebin') self.assertEqual(True, os.path.islink(dep_link_ebin)) erl = Static.get_erlang_version() real_dep = join(self.cache_dir, 'comtihon', 'dep_with_no_deps', '1.0.1', erl, 'ebin') self.assertEqual(real_dep, os.readlink(dep_link_ebin)) self.assertEqual(True, builder.system_config.cache.exists_local(Package.from_path(new_dep_dir))) new_dep_link_ebin = join(pack_path, 'deps', 'new_dep', 'ebin') self.assertEqual(True, os.path.islink(new_dep_link_ebin)) new_dep = join(self.cache_dir, 'comtihon', 'new_dep', '1.0.0', erl, 'ebin') self.assertEqual(new_dep, os.readlink(new_dep_link_ebin))
def test_change_branch(self, mock_conf, _): mock_conf.return_value = self.conf_file pack_path = join(self.test_dir, 'test_app') set_git_url(pack_path, 'http://github/comtihon/test_app') set_git_tag(pack_path, '1.0.0') set_deps(pack_path, [ {'name': 'dep', 'url': 'https://github.com/comtihon/dep', 'branch': 'master'} ]) dep_dir = join(self.tmp_dir, 'dep') builder = Builder.init_from_path(pack_path) builder.populate() self.assertEqual(True, builder.build()) dep_link_ebin = join(pack_path, 'deps', 'dep', 'ebin') self.assertEqual(True, os.path.islink(dep_link_ebin)) erl = Static.get_erlang_version() real_dep = join(self.cache_dir, 'comtihon', 'dep', 'master-some_hash', erl, 'ebin') self.assertEqual(real_dep, os.readlink(dep_link_ebin)) # change dep's branch set_deps(pack_path, [ {'name': 'dep', 'url': 'https://github.com/comtihon/dep', 'branch': 'develop'} ]) switch_branch(dep_dir, 'develop') # pretend new branch was fetched builder = Builder.init_from_path(pack_path) builder.populate() self.assertEqual(True, builder.build()) self.assertEqual(True, os.path.islink(dep_link_ebin)) real_dep = join(self.cache_dir, 'comtihon', 'dep', 'develop-some_hash', erl, 'ebin') self.assertEqual(real_dep, os.readlink(dep_link_ebin))
def test_link_multiple_deps(self, mock_conf, _): mock_conf.return_value = self.conf_file pack_path = join(self.test_dir, 'test_app') set_deps(pack_path, [ {'name': 'a_with_dep_a2', 'url': 'https://github.com/comtihon/a_with_dep_a2', 'tag': '1.0.0'}, {'name': 'b_with_no_deps', 'url': 'https://github.com/comtihon/b_with_no_deps', 'tag': '1.0.0'} ]) # Create dep A with dep A2 (in tmp, as if we download them from git) create(self.tmp_dir, {'<name>': 'a_with_dep_a2'}) dep_a1_path = join(self.tmp_dir, 'a_with_dep_a2') set_deps(dep_a1_path, [{'name': 'a2_with_no_deps', 'url': 'https://github.com/comtihon/a2_with_no_deps', 'tag': '1.0.0'}]) # Create dep B (in tmp, as if we download them from git) create(self.tmp_dir, {'<name>': 'b_with_no_deps'}) # Create dep A2 (in tmp, as if we download them from git) create(self.tmp_dir, {'<name>': 'a2_with_no_deps'}) # Compile test_project builder = Builder.init_from_path(pack_path) builder.populate() self.assertEqual(True, builder.build()) for dep in ['a_with_dep_a2', 'b_with_no_deps', 'a2_with_no_deps']: print('Check ' + dep) dep_link_ebin = join(pack_path, 'deps', dep, 'ebin') self.assertEqual(True, os.path.islink(dep_link_ebin)) erl = Static.get_erlang_version() real_dep = join(self.cache_dir, 'comtihon', dep, '1.0.0', erl, 'ebin') self.assertEqual(real_dep, os.readlink(dep_link_ebin))
def test_link_existing_dep(self, mock_conf, _): mock_conf.return_value = self.conf_file pack_path = join(self.test_dir, 'test_app') set_deps(pack_path, [{ 'name': 'dep', 'url': 'https://github.com/comtihon/dep', 'tag': '1.0.0' }]) create(self.tmp_dir, {'<name>': 'dep'}) dep_path = join(self.tmp_dir, 'dep') set_git_url(dep_path, 'https://github/comtihon/dep') set_git_tag(dep_path, '1.0.0') dep_builder = Builder.init_from_path(dep_path) self.assertEqual(True, dep_builder.build()) dep_builder.system_config.cache.add_package_local(dep_builder.project) self.assertEqual( True, dep_builder.system_config.cache.exists_local(dep_builder.project)) builder = Builder.init_from_path(pack_path) builder.populate() self.assertEqual(True, builder.build()) dep_link_ebin = join(pack_path, 'deps', 'dep', 'ebin') self.assertEqual(True, os.path.islink(dep_link_ebin)) erl = Static.get_erlang_version() real_dep = join(self.cache_dir, 'comtihon', 'dep', '1.0.0', erl, 'ebin') self.assertEqual(real_dep, os.readlink(dep_link_ebin))
def test_project_with_test_dep_test_build(self, mock_conf, _): mock_conf.return_value = self.conf_file pack_path = join(self.test_dir, 'test_app') set_deps(pack_path, [ {'name': 'dep', 'url': 'https://github.com/comtihon/dep', 'tag': '1.0.0'} ]) set_deps(pack_path, [ {'name': 'test_dep', 'url': 'https://github.com/comtihon/test_dep', 'tag': '1.0.0'} ], 'test_deps') create(self.tmp_dir, {'<name>': 'dep'}) create(self.tmp_dir, {'<name>': 'test_dep'}) builder = Builder.init_from_path(pack_path) builder.populate(include_test_deps=True) self.assertEqual(True, builder.build()) for dep in ['dep', 'test_dep']: print('Check ' + dep) dep_link_ebin = join(pack_path, 'deps', dep, 'ebin') self.assertEqual(True, os.path.islink(dep_link_ebin)) erl = Static.get_erlang_version() real_dep = join(self.cache_dir, 'comtihon', dep, '1.0.0', erl, 'ebin') self.assertEqual(real_dep, os.readlink(dep_link_ebin))
def __init__(self, name, temp_dir, path, default_erlang: str, cache_type: CacheType): self._erlang_version = Static.get_erlang_version(default_erlang) self._temp_dir = temp_dir self._path = path self._name = name self._cache_type = cache_type
def test_update_branch(self, mock_conf, _): mock_conf.return_value = self.conf_file pack_path = join(self.test_dir, 'test_app') set_git_url(pack_path, 'http://github/comtihon/test_app') set_git_tag(pack_path, '1.0.0') set_deps(pack_path, [ {'name': 'dep', 'url': 'https://github.com/comtihon/dep', 'branch': 'master'} ]) builder = Builder.init_from_path(pack_path) builder.populate() self.assertEqual(True, builder.build()) dep_link_ebin = join(pack_path, 'deps', 'dep', 'ebin') self.assertEqual(True, os.path.islink(dep_link_ebin)) erl = Static.get_erlang_version() real_dep = join(self.cache_dir, 'comtihon', 'dep', 'master-some_hash', erl, 'ebin') self.assertEqual(real_dep, os.readlink(dep_link_ebin)) # lock was set locks_file = join(pack_path, 'enot_locks.json') self.assertEqual(True, os.path.isfile(locks_file)) with open(locks_file, 'r') as file: locks = json.load(file) self.assertEqual('master-some_hash', locks['comtihon/dep']) # drop all locks and do upgrade with patch.object(LocalCache, 'fetch', side_effect=mock_fetch_commit_3): upgrade(pack_path, {}) self.assertEqual(True, os.path.isfile(locks_file)) with open(locks_file, 'r') as file: locks = json.load(file) self.assertEqual('master-some_other_hash', locks['comtihon/dep'])
def test_change_tag_remove_using_dep(self, mock_conf, _): mock_conf.return_value = self.conf_file pack_path = join(self.test_dir, 'test_app') set_deps(pack_path, [ {'name': 'dep_with_dep', 'url': 'https://github.com/comtihon/dep_with_dep', 'tag': '1.0.0'}, {'name': 'dep', 'url': 'https://github.com/comtihon/dep', 'tag': '1.0.0'} ]) create(self.tmp_dir, {'<name>': 'dep_with_dep'}) dep_dir = join(self.tmp_dir, 'dep_with_dep') set_git_url(dep_dir, 'http://github/comtihon/dep_with_dep') set_git_tag(dep_dir, '1.0.0') set_deps(dep_dir, [ {'name': 'dep', 'url': 'https://github.com/comtihon/dep', 'tag': '1.0.0'} ]) create(self.tmp_dir, {'<name>': 'dep'}) builder = Builder.init_from_path(pack_path) builder.populate() self.assertEqual(True, builder.build()) # Check all two deps linked to the project dep_link_ebin = join(pack_path, 'deps', 'dep_with_dep', 'ebin') self.assertEqual(True, os.path.islink(dep_link_ebin)) erl = Static.get_erlang_version() real_dep = join(self.cache_dir, 'comtihon', 'dep_with_dep', '1.0.0', erl, 'ebin') self.assertEqual(real_dep, os.readlink(dep_link_ebin)) dep_link_ebin = join(pack_path, 'deps', 'dep', 'ebin') self.assertEqual(True, os.path.islink(dep_link_ebin)) real_dep = join(self.cache_dir, 'comtihon', 'dep', '1.0.0', erl, 'ebin') self.assertEqual(real_dep, os.readlink(dep_link_ebin)) # Dep version was changed - dep_with_dep no longer uses dep set_deps(pack_path, [ {'name': 'dep_with_dep', 'url': 'https://github.com/comtihon/dep_with_dep', 'tag': '1.0.1'}, {'name': 'dep', 'url': 'https://github.com/comtihon/dep', 'tag': '1.0.0'} ]) set_deps(dep_dir, []) set_git_tag(dep_dir, '1.0.1') builder = Builder.init_from_path(pack_path) builder.populate() self.assertEqual(True, builder.build()) # Check dep is linked to project, as it is used by project dep_link_ebin = join(pack_path, 'deps', 'dep_with_dep', 'ebin') self.assertEqual(True, os.path.islink(dep_link_ebin)) real_dep = join(self.cache_dir, 'comtihon', 'dep_with_dep', '1.0.1', erl, 'ebin') self.assertEqual(real_dep, os.readlink(dep_link_ebin)) dep_link_ebin = join(pack_path, 'deps', 'dep', 'ebin') self.assertEqual(True, os.path.islink(dep_link_ebin))
def __write_app_file(self, all_files: list): if self.package.app_config.compose_app_file: app_src = read_file( join(self.src_path, self.project_name + '.app.src')) app_path = join(self.output_path, self.project_name + '.app') params = {x: os.environ[x] for x in os.environ} params['modules'] = all_files params['app'] = self.package params['hostname'] = socket.gethostname() params['erl'] = Static.get_erlang_version() with open(app_path, 'w') as f: f.write(Template(app_src).render(params))
def __modify_resource(self, resource, path=''): resource_path = self.__ensure_resource(resource, path) resource = read_file(resource_path) if '{{ ' in resource: params = {x: os.environ[x] for x in os.environ} params['app'] = self.package params['hostname'] = socket.gethostname() params['erl'] = Static.get_erlang_version() resource_filled = Template(resource).render(params) write_file(resource_path, resource_filled) return True, resource_path, resource return False, resource_path, resource
def test_link_with_deps(self, mock_conf, _): mock_conf.return_value = self.conf_file pack_path = join(self.test_dir, 'test_app') set_deps(pack_path, [{ 'name': 'dep_with_dep', 'url': 'https://github.com/comtihon/dep_with_dep', 'tag': '1.0.0' }]) # Create, build and add dep. create(self.tmp_dir, {'<name>': 'dep'}) dep_dep_path = join(self.tmp_dir, 'dep') set_git_url(dep_dep_path, 'https://github/comtihon/dep') set_git_tag(dep_dep_path, '1.0.0') dep_builder = Builder.init_from_path(dep_dep_path) # Build dep of dep and add to cache dep_builder.populate() self.assertEqual(True, dep_builder.build()) dep_builder.system_config.cache.add_package_local(dep_builder.project) self.assertEqual( True, dep_builder.system_config.cache.exists_local(dep_builder.project)) # Create, build and add dep with dep: dep create(self.tmp_dir, {'<name>': 'dep_with_dep'}) dep_path = join(self.tmp_dir, 'dep_with_dep') set_git_url(dep_path, 'https://github/comtihon/dep_with_dep') set_git_tag(dep_path, '1.0.0') set_deps(dep_path, [{ 'name': 'dep', 'url': 'https://github.com/comtihon/dep', 'tag': '1.0.0' }]) dep_builder = Builder.init_from_path(dep_path) dep_builder.populate() self.assertEqual(True, dep_builder.build()) dep_builder.system_config.cache.add_package_local(dep_builder.project) self.assertEqual( True, dep_builder.system_config.cache.exists_local(dep_builder.project)) builder = Builder.init_from_path(pack_path) builder.populate() self.assertEqual(True, builder.build()) for dep in ['dep_with_dep', 'dep']: # Dep and dep's dep are linked to the project print('Check ' + dep) dep_link_ebin = join(pack_path, 'deps', dep, 'ebin') self.assertEqual(True, os.path.islink(dep_link_ebin)) erl = Static.get_erlang_version() real_dep = join(self.cache_dir, 'comtihon', dep, '1.0.0', erl, 'ebin') self.assertEqual(real_dep, os.readlink(dep_link_ebin))
def test_versions_api(self, mock_conf): mock_conf.return_value = self.conf_file pack_path = join(self.test_dir, 'test_app') set_git_url(pack_path, 'http://github/comtihon/test_app') modify_config(pack_path, {'tag': '1.0.0'}) builder = Builder.init_from_path(pack_path) self.assertEqual(True, builder.build()) builder.system_config.cache.add_package_local(builder.project) modify_config(pack_path, {'tag': '1.1.0'}) builder = Builder.init_from_path(pack_path) self.assertEqual(True, builder.build()) builder.system_config.cache.add_package_local(builder.project) local_cache = builder.system_config.cache.local_cache self.assertEqual(['1.0.0', '1.1.0'], local_cache.get_versions('comtihon/test_app')) self.assertEqual([Static.get_erlang_version()], local_cache.get_erl_versions('comtihon/test_app', '1.1.0'))
def test_link_dep(self, mock_conf, _): mock_conf.return_value = self.conf_file pack_path = join(self.test_dir, 'test_app') set_deps(pack_path, [ {'name': 'dep_with_no_deps', 'url': 'https://github.com/comtihon/dep_with_no_deps', 'tag': '1.0.0'} ]) create(self.tmp_dir, {'<name>': 'dep_with_no_deps'}) builder = Builder.init_from_path(pack_path) builder.populate() self.assertEqual(True, builder.build()) dep_link_ebin = join(pack_path, 'deps', 'dep_with_no_deps', 'ebin') self.assertEqual(True, os.path.islink(dep_link_ebin)) erl = Static.get_erlang_version() real_dep = join(self.cache_dir, 'comtihon', 'dep_with_no_deps', '1.0.0', erl, 'ebin') self.assertEqual(real_dep, os.readlink(dep_link_ebin))