def test_init_from_path(self): create(self.test_dir, {'<name>': 'test_app'}) set_git_url(join(self.test_dir, 'test_app'), 'http://github/my_namespace/my_project') set_git_tag(join(self.test_dir, 'test_app'), '1.0.0') pack = Package.from_path(join(self.test_dir, 'test_app')) self.assertEqual('test_app', pack.name) self.assertEqual('0.0.1', pack.vsn) self.assertEqual('http://github/my_namespace/my_project', pack.url) self.assertEqual('1.0.0', pack.git_tag) self.assertEqual('master', pack.git_branch) self.assertEqual([], pack.deps)
def test_package_exists(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') pack = Package.from_path(pack_path) builder = Builder.init_from_path(pack_path) self.assertEqual(False, builder.system_config.cache.exists_local(pack)) self.assertEqual(True, builder.build()) builder.system_config.cache.add_package_local(pack) self.assertEqual(True, builder.system_config.cache.exists_local(pack))
def test_change_tag_remove_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'} ]) 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'} ]) 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 not linked to project anymore 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(False, os.path.islink(dep_link_ebin))
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_add_from_package(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') builder = Builder.init_from_path(pack_path) self.assertEqual(True, builder.build()) builder.package() new_package_path = join(self.test_dir, 'test_app.ep') # remove source project, test should work only with enot package copy_file(join(pack_path, 'test_app.ep'), new_package_path) remove_dir(pack_path) package = Package.from_package(new_package_path) self.assertEqual(False, builder.system_config.cache.exists_local(package)) # local cache is used here to determine tmp dir local_cache = builder.system_config.cache.local_cache builder.system_config.cache.add_fetched(local_cache, package) self.assertEqual(True, builder.system_config.cache.exists_local(package))
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', 'url': 'https://github.com/comtihon/dep', 'tag': '1.0.0'} ]) create(self.tmp_dir, {'<name>': 'dep'}) dep_tmp_path = join(self.tmp_dir, 'dep') set_git_url(dep_tmp_path, 'http://github/comtihon/dep') set_git_tag(dep_tmp_path, '1.0.0') builder = Builder.init_from_path(pack_path) builder.populate() self.assertEqual(True, builder.build()) # dep was added to cache self.assertEqual(True, builder.system_config.cache.exists_local(Package.from_path(dep_tmp_path))) 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_change_tag(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 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') 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))
def test_override_disable_prebuild(self, mock_conf, _): mock_conf.return_value = self.conf_file create(self.tmp_dir, {'<name>': 'project'}) project_dir = join(self.tmp_dir, 'project') set_prebuild(project_dir, [], disable_prebuild=True, override_conf=True) # root project has dep, which has some shell prebuild step set_deps(project_dir, [{ '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') test_file_path = join(project_dir, 'test_file') set_prebuild(dep_path, [{'shell': 'echo "test" > ' + test_file_path}]) builder = Builder.init_from_path(project_dir) builder.populate() self.assertEqual(True, builder.build()) self.assertEqual(False, os.path.exists( test_file_path)) # no dep's prebuild step was executed
def test_add_with_deps(self, mock_conf, _): mock_conf.return_value = self.conf_file # Create test_app with deps: A and B 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'}]) set_git_url(dep_a1_path, 'http://github/comtihon/a2_with_no_deps') set_git_tag(dep_a1_path, '1.0.0') # Create dep B (in tmp, as if we download them from git) create(self.tmp_dir, {'<name>': 'b_with_no_deps'}) dep_b_path = join(self.tmp_dir, 'b_with_no_deps') set_git_url(dep_b_path, 'http://github/comtihon/b_with_no_deps') set_git_tag(dep_b_path, '1.0.0') # Create dep A2 (in tmp, as if we download them from git) create(self.tmp_dir, {'<name>': 'a2_with_no_deps'}) dep_a2_path = join(self.tmp_dir, 'a2_with_no_deps') set_git_url(dep_a2_path, 'http://github/comtihon/a2_with_no_deps') set_git_tag(dep_a2_path, '1.0.0') # Compile test_project builder = Builder.init_from_path(pack_path) self.assertEqual(False, builder.system_config.cache.exists_local(Package.from_path(dep_a1_path))) self.assertEqual(False, builder.system_config.cache.exists_local(Package.from_path(dep_b_path))) self.assertEqual(False, builder.system_config.cache.exists_local(Package.from_path(dep_a2_path))) builder.populate() self.assertEqual(True, builder.build()) self.assertEqual(True, builder.system_config.cache.exists_local(Package.from_path(dep_a1_path))) self.assertEqual(True, builder.system_config.cache.exists_local(Package.from_path(dep_b_path))) self.assertEqual(True, builder.system_config.cache.exists_local(Package.from_path(dep_a2_path)))
def setUp(self): super().setUp() create(self.test_dir, {'<name>': 'test_project'}) pack_path = join(self.test_dir, 'test_project') set_git_url(pack_path, 'http://github/comtihon/test_app') set_git_tag(pack_path, '1.0.0')
def test_install_with_deps(self, _, mock_conf, mock_conf_dir, _local): mock_conf.return_value = self.conf_file mock_conf_dir.return_value = join(self.test_dir, 'conf') # Create test_app with deps: A and B create(self.test_dir, {'<name>': 'test_app'}) 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': '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' }]) test_install_dir = join(self.test_dir, 'test_install') modify_config( pack_path, { 'install': [ { 'shell': 'mkdir ' + test_install_dir }, { 'shell': 'cp ebin/*.* ' + test_install_dir }, { 'shell': 'cp deps/*/ebin/*.* ' + test_install_dir }, ] }) # 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' }]) set_git_url(dep_a1_path, 'http://github/comtihon/a2_with_no_deps') set_git_tag(dep_a1_path, '1.0.0') # Create dep B (in tmp, as if we download them from git) create(self.tmp_dir, {'<name>': 'b_with_no_deps'}) dep_b_path = join(self.tmp_dir, 'b_with_no_deps') set_git_url(dep_b_path, 'http://github/comtihon/b_with_no_deps') set_git_tag(dep_b_path, '1.0.0') # Create dep A2 (in tmp, as if we download them from git) create(self.tmp_dir, {'<name>': 'a2_with_no_deps'}) dep_a2_path = join(self.tmp_dir, 'a2_with_no_deps') set_git_url(dep_a2_path, 'http://github/comtihon/a2_with_no_deps') set_git_tag(dep_a2_path, '1.0.0') # Compile test_project, add to local cache self.__add_to_local(pack_path) self.assertEqual(True, Controller().install('comtihon/test_app', None)) self.assertEqual(True, os.path.isdir(test_install_dir)) installed = os.listdir(test_install_dir) expected = [ 'a2_with_no_deps.app', 'a2_with_no_deps_app.beam', 'a2_with_no_deps_sup.beam', 'a_with_dep_a2.app', 'a_with_dep_a2_app.beam', 'a_with_dep_a2_sup.beam', 'b_with_no_deps.app', 'b_with_no_deps_app.beam', 'b_with_no_deps_sup.beam', 'test_app.app', 'test_app_app.beam', 'test_app_sup.beam' ] self.assertEqual(expected, sorted(installed))