def test_env(self): plugin = ant.AntPlugin('test-part', self.options, self.project_options) os.makedirs(os.path.join(plugin.installdir, 'jar')) open(os.path.join(plugin.installdir, 'jar', 'lib1.jar'), 'w').close() open(os.path.join(plugin.installdir, 'jar', 'lib2.jar'), 'w').close() plugin.env(plugin.partdir)
def test_get_non_defaul_openjdk(self): self.options.ant_openjdk_version = "8" plugin = ant.AntPlugin("test-part", self.options, self.project) self.assertThat(plugin.stage_packages, Equals(["openjdk-8-jre-headless"])) self.assertThat(plugin.build_packages, Equals(["openjdk-8-jdk-headless"]))
def test_build_fail(self, run_mock): plugin = ant.AntPlugin('test-part', self.options, self.project_options) os.makedirs(plugin.sourcedir) with self.assertRaises(RuntimeError): plugin.build() run_mock.assert_has_calls([ mock.call(['ant']), ])
def test_env(self): plugin = ant.AntPlugin('test-part', self.options, self.project_options) os.makedirs(os.path.join(plugin.installdir, 'jar')) open(os.path.join(plugin.installdir, 'jar', 'lib1.jar'), 'w').close() open(os.path.join(plugin.installdir, 'jar', 'lib2.jar'), 'w').close() env = plugin.env(plugin.partdir) self.assertIn( 'CLASSPATH={}/jar/lib1.jar:{}/jar/lib2.jar:$CLASSPATH'.format( plugin.partdir, plugin.partdir), env)
def test_stage_and_build_packages(self): plugin = ant.AntPlugin("test-part", self.options, self.project) self.assertThat( plugin.stage_packages, Equals(["openjdk-{}-jre-headless".format(self.expected_java_version)]), ) self.assertThat( plugin.build_packages, Equals(["openjdk-{}-jdk-headless".format(self.expected_java_version)]), )
def test_build_with_explicit_buildfile(self): self.options.ant_buildfile = "test.xml" plugin = ant.AntPlugin("test-part", self.options, self.project) self.create_assets(plugin) plugin.build() self.run_mock.assert_called_once_with( ["ant", "-f", "test.xml"], cwd=plugin.builddir, env=mock.ANY )
def test_env(self): plugin = ant.AntPlugin("test-part", self.options, self.project) os.makedirs(os.path.join(plugin.installdir, "jar")) open(os.path.join(plugin.installdir, "jar", "lib1.jar"), "w").close() open(os.path.join(plugin.installdir, "jar", "lib2.jar"), "w").close() env = plugin.env(plugin.partdir) self.assertIn( "CLASSPATH={}/jar/lib1.jar:{}/jar/lib2.jar:$CLASSPATH".format( plugin.partdir, plugin.partdir), env, )
def test_build(self, run_mock): plugin = ant.AntPlugin("test-part", self.options, self.project_options) def side(l): os.makedirs(os.path.join(plugin.builddir, "target")) open(os.path.join(plugin.builddir, "target", "dummy.jar"), "w").close() run_mock.side_effect = side os.makedirs(plugin.sourcedir) plugin.build() run_mock.assert_has_calls([mock.call(["ant"])])
def test_env_proxies(self): env_vars = ( ('http_proxy', 'http://localhost:3132'), ('https_proxy', 'http://localhost2:3133'), ) for v in env_vars: self.useFixture(fixtures.EnvironmentVariable(v[0], v[1])) plugin = ant.AntPlugin('test-part', self.options, self.project_options) env = plugin.env(plugin.partdir) self.assertIn( "ANT_OPTS='" "-Dhttp.proxyHost=localhost -Dhttp.proxyPort=3132 " "-Dhttps.proxyHost=localhost2 -Dhttps.proxyPort=3133'", env)
def test_build_with_options(self): self.options.ant_build_targets = ["artifacts", "jar"] self.options.ant_properties = {"basedir": "."} plugin = ant.AntPlugin("test-part", self.options, self.project) self.create_assets(plugin) plugin.build() self.run_mock.assert_called_once_with( ["ant", "artifacts", "jar", "-Dbasedir=."], cwd=plugin.builddir, env=mock.ANY, )
def test_build(self, run_mock): plugin = ant.AntPlugin('test-part', self.options, self.project_options) def side(l): os.makedirs(os.path.join(plugin.builddir, 'target')) open(os.path.join(plugin.builddir, 'target', 'dummy.jar'), 'w').close() run_mock.side_effect = side os.makedirs(plugin.sourcedir) plugin.build() run_mock.assert_has_calls([ mock.call(['ant']), ])
def test_build(self): plugin = ant.AntPlugin("test-part", self.options, self.project) self.create_assets(plugin) def side(l, **kwargs): os.makedirs(os.path.join(plugin.builddir, "target")) open(os.path.join(plugin.builddir, "target", "dummy.jar"), "w").close() self.run_mock.side_effect = side plugin.build() self.run_mock.assert_called_once_with( ["ant"], cwd=plugin.builddir, env=mock.ANY )
def test_env_proxies(self): env_vars = ( ('http_proxy', 'http://*****:*****@localhost:3132'), ('https_proxy', 'http://*****:*****@localhost2:3133'), ) for key, value in env_vars: self.useFixture(fixtures.EnvironmentVariable(key, value)) plugin = ant.AntPlugin('test-part', self.options, self.project_options) env = plugin.env(plugin.partdir) self.assertIn( "ANT_OPTS='" "-Dhttp.proxyHost=localhost -Dhttp.proxyPort=3132 " "-Dhttp.proxyUser=user -Dhttp.proxyPassword=pass " "-Dhttps.proxyHost=localhost2 -Dhttps.proxyPort=3133 " "-Dhttps.proxyUser=user2 -Dhttps.proxyPassword=pass2'", env)
def test_build_with_options(self, run_mock): options = copy.deepcopy(self.options) plugin = ant.AntPlugin("test-part", options, self.project_options) options.ant_build_targets = ["artifacts", "jar"] options.ant_properties = {"basedir": ".", "dist.dir": plugin.installdir} os.makedirs(plugin.sourcedir) plugin.build() destination = "-Ddist.dir={}".format(plugin.installdir) basedir = "-Dbasedir=." args = run_mock.call_args[0][0] self.assertThat(args[0], Equals("ant")) self.assertThat(args[1], Equals("artifacts")) self.assertThat(args[2], Equals("jar")) self.assertIn(destination, args) self.assertIn(basedir, args)
def test_build_with_explicit_buildfile(self): self.options.ant_buildfile = "test.xml" plugin = ant.AntPlugin("test-part", self.options, self.project) self.create_assets(plugin) plugin.build() self.run_mock.assert_called_once_with(["ant", "-f", "test.xml"], cwd=plugin.builddir, env=mock.ANY) self.tar_mock.assert_called_once_with( ant._ANT_ARCHIVE_FORMAT_URL.format( version=self.options.ant_version), mock.ANY, source_checksum=self.options.ant_version_checksum, )
def test_build_env_proxies(self): env_vars = ( ("http_proxy", "http://*****:*****@localhost:3132"), ("https_proxy", "http://*****:*****@localhost2:3133"), ) for key, value in env_vars: self.useFixture(fixtures.EnvironmentVariable(key, value)) plugin = ant.AntPlugin("test-part", self.options, self.project) env = plugin._build_environment() self.assertThat(env, Contains("ANT_OPTS")) self.assertThat( env["ANT_OPTS"], Equals("-Dhttp.proxyHost=localhost -Dhttp.proxyPort=3132 " "-Dhttp.proxyUser=user -Dhttp.proxyPassword=pass " "-Dhttps.proxyHost=localhost2 -Dhttps.proxyPort=3133 " "-Dhttps.proxyUser=user2 -Dhttps.proxyPassword=pass2"), )
def test_build_with_options(self, run_mock): options = copy.deepcopy(self.options) plugin = ant.AntPlugin('test-part', options, self.project_options) options.ant_build_targets = ['artifacts', 'jar'] options.ant_properties = {'basedir': '.', 'dist.dir': plugin.installdir} os.makedirs(plugin.sourcedir) plugin.build() destination = '-Ddist.dir={}'.format(plugin.installdir) basedir = '-Dbasedir=.' args = run_mock.call_args[0][0] self.assertEqual(args[0], 'ant') self.assertEqual(args[1], 'artifacts') self.assertEqual(args[2], 'jar') self.assertIn(destination, args) self.assertIn(basedir, args)
def test_build_with_default_snap(self): plugin = ant.AntPlugin("test-part", self.options, self.project) self.create_assets(plugin) def side(l, **kwargs): os.makedirs(os.path.join(plugin.builddir, "target")) open(os.path.join(plugin.builddir, "target", "dummy.jar"), "w").close() self.run_mock.side_effect = side plugin.build() self.tar_mock.assert_not_called() self.run_mock.assert_called_once_with(["ant"], cwd=plugin.builddir, env=mock.ANY) self.assertEqual(plugin.build_snaps, ["ant/" + ant._DEFAULT_ANT_SNAP_CHANNEL])
def test_build_with_explicit_snap(self): self.options.ant_channel = "other/channel" plugin = ant.AntPlugin("test-part", self.options, self.project) self.create_assets(plugin) def side(l, **kwargs): os.makedirs(os.path.join(plugin.builddir, "target")) open(os.path.join(plugin.builddir, "target", "dummy.jar"), "w").close() self.run_mock.side_effect = side plugin.build() self.tar_mock.assert_not_called() self.run_mock.assert_called_once_with(["ant"], cwd=plugin.builddir, env=mock.ANY) self.assertEqual(plugin.build_snaps, ["ant/other/channel"])
def test_build_with_options(self): self.options.ant_build_targets = ["artifacts", "jar"] self.options.ant_properties = {"basedir": "."} plugin = ant.AntPlugin("test-part", self.options, self.project) self.create_assets(plugin) plugin.build() self.run_mock.assert_called_once_with( ["ant", "artifacts", "jar", "-Dbasedir=."], cwd=plugin.builddir, env=mock.ANY, ) self.tar_mock.assert_called_once_with( ant._ANT_ARCHIVE_FORMAT_URL.format( version=self.options.ant_version), mock.ANY, source_checksum=self.options.ant_version_checksum, )
def test_build(self): plugin = ant.AntPlugin("test-part", self.options, self.project) self.create_assets(plugin) def side(l, **kwargs): os.makedirs(os.path.join(plugin.builddir, "target")) open(os.path.join(plugin.builddir, "target", "dummy.jar"), "w").close() self.run_mock.side_effect = side plugin.build() self.run_mock.assert_called_once_with(["ant"], cwd=plugin.builddir, env=mock.ANY) self.tar_mock.assert_called_once_with( ant._ANT_ARCHIVE_FORMAT_URL.format( version=self.options.ant_version), mock.ANY, source_checksum=self.options.ant_version_checksum, )