def test_get_build_environment(self): plugin = NpmPlugin(part_name="my-part", options=lambda: None) self.assertThat( plugin.get_build_environment(), Equals({"PATH": "${SNAPCRAFT_PART_INSTALL}/bin:${PATH}"}), )
def test_get_architecture_from_platform_for_x86(self): for platform_architecture, node_arch in [("32bit", "x86"), ("64bit", "x64")]: self.useFixture( fixtures.MockPatch("platform.machine", return_value="x86_64")) self.useFixture( fixtures.MockPatch("platform.architecture", return_value=("64bit", "ELF"))) self.expectThat(NpmPlugin._get_architecture(), Equals("x64"))
def test_get_build_commands(self): self.useFixture(fixtures.EnvironmentVariable("SNAP_ARCH", "amd64")) class Options: npm_node_version = "6.0.0" plugin = NpmPlugin(part_name="my-part", options=Options()) self.assertThat( plugin.get_build_commands(), Equals([ dedent("""\ if [ ! -f "${SNAPCRAFT_PART_INSTALL}/bin/node" ]; then curl -s "https://nodejs.org/dist/v6.0.0/node-v6.0.0-linux-x64.tar.gz" | tar xzf - -C "${SNAPCRAFT_PART_INSTALL}/" --strip-components=1 fi """), 'npm install -g --prefix "${SNAPCRAFT_PART_INSTALL}" $(npm pack . | tail -1)', ]), )
def test_get_architecture_from_snap_arch(self): for snap_arch, node_arch in [ ("amd64", "x64"), ("i386", "x86"), ("armhf", "armv7l"), ("arm64", "arm64"), ("ppc64el", "ppc64le"), ("s390x", "s390x"), ]: self.useFixture( fixtures.EnvironmentVariable("SNAP_ARCH", snap_arch)) self.expectThat(NpmPlugin._get_architecture(), Equals(node_arch))
def test_schema(self): schema = NpmPlugin.get_schema() self.assertThat( schema, Equals({ "$schema": "http://json-schema.org/draft-04/schema#", "additionalProperties": False, "properties": { "npm-node-version": { "type": "string" } }, "required": ["source", "npm-node-version"], "type": "object", }), )
def test_get_build_packages(self): plugin = NpmPlugin(part_name="my-part", options=lambda: None) self.assertThat(plugin.get_build_packages(), Equals({"curl", "gcc"}))
def test_get_build_environment(self): plugin = NpmPlugin(part_name="my-part", options=lambda: None) self.assertThat(plugin.get_build_environment(), Equals(dict()))