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_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_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_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_use_invalid_openjdk_version_fails(self, base, version, expected_message): class Options: ant_properties = {} ant_build_targets = None ant_channel = None ant_version = "1.10.5" ant_version_checksum = "sha512/a7f1e0cec9d5ed1b3ab6cddbb9364f127305a997bbc88ecd734f9ef142ec0332375e01ace3592759bb5c3307cd9c1ac0a78a30053f304c7030ea459498e4ce4e" ant_openjdk_version = version project = Project() project._snap_meta = Snap(name="test-snap", base=base, confinement="strict") with pytest.raises(ant.UnsupportedJDKVersionError) as error: ant.AntPlugin("test-part", Options(), project) assert str(error) == expected_message
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_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 ant_plugin(tmp_work_path, request): """Return an instance of AntPlugin setup with different bases and java versions.""" java_version, base = request.param class Options: ant_properties = {} ant_build_targets = None ant_channel = None ant_version = "1.10.5" ant_version_checksum = "sha512/a7f1e0cec9d5ed1b3ab6cddbb9364f127305a997bbc88ecd734f9ef142ec0332375e01ace3592759bb5c3307cd9c1ac0a78a30053f304c7030ea459498e4ce4e" ant_openjdk_version = java_version ant_buildfile = None project = Project() project._snap_meta = Snap(name="test-snap", base=base, confinement="strict") return ant.AntPlugin("test-part", Options(), project)
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, )