def test_build_with_authenticated_proxies(self): env_vars = ( ("http_proxy", "http://*****:*****@localhost:3132"), ("https_proxy", "http://*****:*****@localhost:3133"), ("no_proxy", None), ) for v in env_vars: self.useFixture(fixtures.EnvironmentVariable(v[0], v[1])) plugin = maven.MavenPlugin("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() settings_path = os.path.join(plugin.partdir, "m2", "settings.xml") self.run_mock.assert_called_once_with( ["mvn", "package", "-s", settings_path], cwd=plugin.builddir, env=mock.ANY) self.assertThat(settings_path, FileExists()) expected_content = dedent("""\ <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <interactiveMode>false</interactiveMode> <proxies> <proxy> <id>http_proxy</id> <active>true</active> <protocol>http</protocol> <host>localhost</host> <port>3132</port> <username>user1</username> <password>pass1</password> <nonProxyHosts>localhost</nonProxyHosts> </proxy> <proxy> <id>https_proxy</id> <active>true</active> <protocol>https</protocol> <host>localhost</host> <port>3133</port> <username>user2</username> <password>pass2</password> <nonProxyHosts>localhost</nonProxyHosts> </proxy> </proxies> </settings> """) self.assertSettingsEqual(expected_content, settings_path)
def test_stage_and_build_packages(self): plugin = maven.MavenPlugin("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_fail(self): env_vars = (("http_proxy", None), ("https_proxy", None)) for v in env_vars: self.useFixture(fixtures.EnvironmentVariable(v[0], v[1])) plugin = maven.MavenPlugin("test-part", self.options, self.project) self.create_assets(plugin) self.assertRaises(RuntimeError, plugin.build) self.run_mock.assert_called_once_with( ["mvn", "package"], cwd=plugin.builddir, env=mock.ANY )
def test_use_invalid_openjdk_version_fails(self, base, version, expected_message): class Options: maven_options = [] maven_targets = [""] maven_version = maven._DEFAULT_MAVEN_VERSION maven_version_checksum = maven._DEFAULT_MAVEN_CHECKSUM maven_openjdk_version = version project = Project() project._snap_meta = Snap(name="test-snap", base=base, confinement="strict") with pytest.raises(maven.UnsupportedJDKVersionError) as error: maven.MavenPlugin("test-part", Options(), project) assert str(error) == expected_message
def maven_plugin(tmp_work_path, request): """Return an instance of MavenPlugin setup with different bases and java versions.""" java_version, base = request.param class Options: maven_options = [] maven_targets = [""] maven_version = maven._DEFAULT_MAVEN_VERSION maven_version_checksum = maven._DEFAULT_MAVEN_CHECKSUM maven_openjdk_version = java_version project = Project() project._snap_meta = Snap(name="test-snap", base=base, confinement="strict") return maven.MavenPlugin("test-part", Options(), project)
def test_build_war(self): env_vars = (("http_proxy", None), ("https_proxy", None)) for v in env_vars: self.useFixture(fixtures.EnvironmentVariable(v[0], v[1])) plugin = maven.MavenPlugin("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", "war.war"), "w").close() self.run_mock.side_effect = side plugin.build() self.run_mock.assert_called_once_with( ["mvn", "package"], cwd=plugin.builddir, env=mock.ANY )