Esempio n. 1
0
    def test_build(self):
        self.useFixture(tests.fixture_setup.CleanEnvironment())
        self.useFixture(fixtures.EnvironmentVariable(
            'PATH', '/bin'))

        class Options:
            source = '.'
            gulp_tasks = []
            node_engine = '4'

        plugin = gulp.GulpPlugin('test-part', Options(), self.project_options)

        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, 'package.json'), 'w').close()

        plugin.build()

        path = '{}:/bin'.format(os.path.join(plugin._npm_dir, 'bin'))
        self.run_mock.assert_has_calls([
            mock.call(['npm', 'install', '-g', 'gulp-cli'],
                      cwd=plugin.builddir,
                      env={'PATH': path,
                           'NPM_CONFIG_PREFIX': plugin._npm_dir}),
            mock.call(['npm', 'install', '--only-development'],
                      cwd=plugin.builddir,
                      env={'PATH': path,
                           'NPM_CONFIG_PREFIX': plugin._npm_dir}),
        ])

        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs.get_nodejs_release(plugin.options.node_engine),
                os.path.join(plugin._npm_dir)),
            mock.call().provision(
                plugin._npm_dir, clean_target=False, keep_tarball=True)])
Esempio n. 2
0
    def test_build_local_sources(self):
        class Options:
            source = '.'
            node_packages = []
            node_engine = '4'

        plugin = nodejs.NodePlugin('test-part', Options(),
                                   self.project_options)

        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, 'package.json'), 'w').close()

        plugin.build()

        self.run_mock.assert_has_calls([
            mock.call(['npm', '--cache-min=Infinity', 'install'],
                      cwd=plugin.builddir),
            mock.call(['npm', '--cache-min=Infinity', 'install', '--global'],
                      cwd=plugin.builddir)])
        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs.get_nodejs_release(plugin.options.node_engine),
                path.join(os.path.abspath('.'), 'parts', 'test-part', 'npm')),
            mock.call().provision(
                plugin.installdir, clean_target=False, keep_tarball=True)])
    def test_build(self):
        self.useFixture(tests.fixture_setup.CleanEnvironment())
        self.useFixture(fixtures.EnvironmentVariable('PATH', '/bin'))

        class Options:
            source = '.'
            gulp_tasks = []
            node_engine = '4'

        plugin = gulp.GulpPlugin('test-part', Options(), self.project_options)

        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, 'package.json'), 'w').close()

        plugin.build()

        path = '{}:/bin'.format(os.path.join(plugin._npm_dir, 'bin'))
        self.run_mock.assert_has_calls([
            mock.call(['npm', 'install', '-g', 'gulp-cli'],
                      cwd=plugin.builddir,
                      env={'PATH': path}),
            mock.call(['npm', 'install', '--only-development'],
                      cwd=plugin.builddir,
                      env={'PATH': path}),
        ])

        self.tar_mock.assert_has_calls([
            mock.call(nodejs.get_nodejs_release(plugin.options.node_engine),
                      os.path.join(plugin._npm_dir)),
            mock.call().provision(plugin._npm_dir,
                                  clean_target=False,
                                  keep_tarball=True)
        ])
Esempio n. 4
0
    def test_build_local_sources(self):
        class Options:
            source = '.'
            node_packages = []
            node_engine = '4'
            npm_run = []

        plugin = nodejs.NodePlugin('test-part', Options(),
                                   self.project_options)

        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, 'package.json'), 'w').close()

        plugin.build()

        self.run_mock.assert_has_calls([
            mock.call(['npm', '--cache-min=Infinity', 'install'],
                      cwd=plugin.builddir),
            mock.call(['npm', '--cache-min=Infinity', 'install', '--global'],
                      cwd=plugin.builddir)
        ])
        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs.get_nodejs_release(plugin.options.node_engine),
                path.join(os.path.abspath('.'), 'parts', 'test-part', 'npm')),
            mock.call().provision(plugin.installdir,
                                  clean_target=False,
                                  keep_tarball=True)
        ])
Esempio n. 5
0
    def test_pull_and_build_node_packages_sources(self):
        class Options:
            source = None
            node_packages = ['my-pkg']
            node_engine = '4'

        plugin = nodejs.NodePlugin('test-part', Options(),
                                   self.project_options)

        os.makedirs(plugin.sourcedir)

        plugin.pull()
        plugin.build()

        self.run_mock.assert_has_calls([
            mock.call(['npm', 'install', '-g', 'my-pkg'], cwd=plugin.builddir)
        ])
        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs.get_nodejs_release(plugin.options.node_engine),
                path.join(os.path.abspath('.'), 'parts', 'test-part', 'npm')),
            mock.call().download(),
            mock.call().provision(plugin.installdir,
                                  clean_target=False,
                                  keep_tarball=True)
        ])
Esempio n. 6
0
    def test_pull_and_build_node_packages_sources(self):
        class Options:
            source = None
            node_packages = ['my-pkg']
            node_engine = '4'
            npm_run = []

        plugin = nodejs.NodePlugin('test-part', Options(),
                                   self.project_options)

        os.makedirs(plugin.sourcedir)

        plugin.pull()
        plugin.build()

        self.run_mock.assert_has_calls([
            mock.call(['npm', '--cache-min=Infinity', 'install', '--global',
                       'my-pkg'], cwd=plugin.builddir)])
        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs.get_nodejs_release(plugin.options.node_engine),
                path.join(os.path.abspath('.'), 'parts', 'test-part', 'npm')),
            mock.call().download(),
            mock.call().provision(
                plugin.installdir, clean_target=False, keep_tarball=True)])
Esempio n. 7
0
    def setUp(self):
        super().setUp()

        class Options:
            source = '.'
            node_packages = []
            node_engine = nodejs._NODEJS_VERSION
            npm_run = []
            node_package_manager = 'npm'
            source = '.'
        self.options = Options()

        self.project_options = snapcraft.ProjectOptions()

        self.useFixture(tests.fixture_setup.CleanEnvironment())

        patcher = mock.patch('snapcraft.internal.common.run')
        self.run_mock = patcher.start()
        self.addCleanup(patcher.stop)

        patcher = mock.patch('snapcraft.internal.common.run_output')
        self.run_output_mock = patcher.start()
        self.addCleanup(patcher.stop)
        self.run_output_mock.return_value = '{"dependencies": []}'

        patcher = mock.patch('snapcraft.sources.Tar')
        self.tar_mock = patcher.start()
        self.addCleanup(patcher.stop)

        patcher = mock.patch('sys.stdout')
        patcher.start()
        self.addCleanup(patcher.stop)

        self.nodejs_url = nodejs.get_nodejs_release(
            nodejs._NODEJS_VERSION, self.project_options.deb_arch)
Esempio n. 8
0
    def setUp(self):
        super().setUp()

        class Options:
            source = '.'
            node_packages = []
            node_engine = nodejs._NODEJS_VERSION
            npm_run = []
            node_package_manager = 'npm'
            source = '.'
        self.options = Options()

        self.project_options = snapcraft.ProjectOptions()

        self.useFixture(fixture_setup.CleanEnvironment())

        patcher = mock.patch('snapcraft.internal.common.run')
        self.run_mock = patcher.start()
        self.addCleanup(patcher.stop)

        patcher = mock.patch('snapcraft.internal.common.run_output')
        self.run_output_mock = patcher.start()
        self.addCleanup(patcher.stop)
        self.run_output_mock.return_value = '{"dependencies": []}'

        patcher = mock.patch('snapcraft.sources.Tar')
        self.tar_mock = patcher.start()
        self.addCleanup(patcher.stop)

        patcher = mock.patch('sys.stdout')
        patcher.start()
        self.addCleanup(patcher.stop)

        self.nodejs_url = nodejs.get_nodejs_release(
            nodejs._NODEJS_VERSION, self.project_options.deb_arch)
Esempio n. 9
0
 def __init__(self, name, options, project):
     super().__init__(name, options, project)
     self._npm_dir = os.path.join(self.partdir, "npm")
     self._nodejs_tar = sources.Tar(
         nodejs.get_nodejs_release(self.options.node_engine, self.project.deb_arch),
         self._npm_dir,
     )
Esempio n. 10
0
 def __init__(self, name, options, project):
     super().__init__(name, options, project)
     self._npm_dir = os.path.join(self.partdir, "npm")
     self._nodejs_tar = sources.Tar(
         nodejs.get_nodejs_release(self.options.node_engine,
                                   self.project.deb_arch),
         self._npm_dir,
     )
Esempio n. 11
0
    def test_build(self, platform_machine_mock, platform_architecture_mock):
        self.useFixture(fixture_setup.CleanEnvironment())
        self.useFixture(fixtures.EnvironmentVariable("PATH", "/bin"))

        class Options:
            source = "."
            gulp_tasks = []
            node_engine = "4"

        platform_machine_mock.return_value = "x86_64"
        platform_architecture_mock.return_value = ("64bit", "ELF")
        plugin = gulp.GulpPlugin("test-part", Options(), self.project_options)

        os.makedirs(plugin.builddir)
        open(os.path.join(plugin.builddir, "package.json"), "w").close()

        plugin.build()

        path = "{}:/bin".format(os.path.join(plugin._npm_dir, "bin"))
        self.run_mock.assert_has_calls([
            mock.call(
                ["npm", "install", "-g", "gulp-cli"],
                cwd=plugin.builddir,
                env={
                    "PATH": path,
                    "NPM_CONFIG_PREFIX": plugin._npm_dir
                },
            ),
            mock.call(
                ["npm", "install", "--only-development"],
                cwd=plugin.builddir,
                env={
                    "PATH": path,
                    "NPM_CONFIG_PREFIX": plugin._npm_dir
                },
            ),
        ])

        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs.get_nodejs_release(plugin.options.node_engine,
                                          plugin.project.deb_arch),
                os.path.join(plugin._npm_dir),
            ),
            mock.call().provision(plugin._npm_dir,
                                  clean_target=False,
                                  keep_tarball=True),
        ])
Esempio n. 12
0
    def test_build(self, platform_machine_mock, platform_architecture_mock):
        self.useFixture(fixture_setup.CleanEnvironment())
        self.useFixture(fixtures.EnvironmentVariable("PATH", "/bin"))

        class Options:
            source = "."
            gulp_tasks = []
            node_engine = "4"

        platform_machine_mock.return_value = "x86_64"
        platform_architecture_mock.return_value = ("64bit", "ELF")
        plugin = gulp.GulpPlugin("test-part", Options(), self.project_options)

        os.makedirs(plugin.builddir)
        open(os.path.join(plugin.builddir, "package.json"), "w").close()

        plugin.build()

        path = "{}:/bin".format(os.path.join(plugin._npm_dir, "bin"))
        self.run_mock.assert_has_calls(
            [
                mock.call(
                    ["npm", "install", "-g", "gulp-cli"],
                    cwd=plugin.builddir,
                    env={"PATH": path, "NPM_CONFIG_PREFIX": plugin._npm_dir},
                ),
                mock.call(
                    ["npm", "install", "--only-development"],
                    cwd=plugin.builddir,
                    env={"PATH": path, "NPM_CONFIG_PREFIX": plugin._npm_dir},
                ),
            ]
        )

        self.tar_mock.assert_has_calls(
            [
                mock.call(
                    nodejs.get_nodejs_release(
                        plugin.options.node_engine, plugin.project.deb_arch
                    ),
                    os.path.join(plugin._npm_dir),
                ),
                mock.call().provision(
                    plugin._npm_dir, clean_target=False, keep_tarball=True
                ),
            ]
        )
Esempio n. 13
0
    def test_pull_local_sources(self):
        class Options:
            source = '.'
            gulp_tasks = []
            node_engine = '4'

        plugin = gulp.GulpPlugin('test-part', Options(), self.project_options)

        os.makedirs(plugin.sourcedir)

        plugin.pull()

        self.assertFalse(self.run_mock.called, 'run() was called')
        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs.get_nodejs_release(plugin.options.node_engine),
                path.join(os.path.abspath('.'), 'parts', 'test-part', 'npm')),
            mock.call().download()])
Esempio n. 14
0
    def setUp(self):
        super().setUp()

        snapcraft_yaml_path = self.make_snapcraft_yaml(
            dedent(
                """\
            name: go-snap
            base: core18
        """
            )
        )

        self.project = Project(snapcraft_yaml_file_path=snapcraft_yaml_path)

        class Options:
            source = "."
            nodejs_version = nodejs._NODEJS_VERSION
            nodejs_package_manager = "npm"
            nodejs_yarn_version = ""
            source = "."

        self.options = Options()

        # always have a package.json stub under source
        open("package.json", "w").close()

        patcher = mock.patch("snapcraft.internal.common.run")
        self.run_mock = patcher.start()
        self.addCleanup(patcher.stop)

        patcher = mock.patch("snapcraft.internal.common.run_output")
        self.run_output_mock = patcher.start()
        self.addCleanup(patcher.stop)
        self.run_output_mock.return_value = '{"dependencies": []}'

        patcher = mock.patch("snapcraft.sources.Tar")
        self.tar_mock = patcher.start()
        self.addCleanup(patcher.stop)

        self.nodejs_url = nodejs.get_nodejs_release(
            nodejs._NODEJS_VERSION, self.project.deb_arch
        )

        self.useFixture(fixture_setup.CleanEnvironment())
Esempio n. 15
0
    def setUp(self):
        super().setUp()

        self.project_options = snapcraft.ProjectOptions()

        patcher = mock.patch('snapcraft.internal.common.run')
        self.run_mock = patcher.start()
        self.addCleanup(patcher.stop)

        patcher = mock.patch('snapcraft.sources.Tar')
        self.tar_mock = patcher.start()
        self.addCleanup(patcher.stop)

        patcher = mock.patch('sys.stdout')
        patcher.start()
        self.addCleanup(patcher.stop)

        self.nodejs_url = nodejs.get_nodejs_release(
            nodejs._NODEJS_VERSION, self.project_options.deb_arch)
Esempio n. 16
0
    def test_pull_local_sources(self):
        class Options:
            source = '.'
            gulp_tasks = []
            node_engine = '4'

        plugin = gulp.GulpPlugin('test-part', Options(), self.project_options)

        os.makedirs(plugin.sourcedir)

        plugin.pull()

        self.assertFalse(self.run_mock.called, 'run() was called')
        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs.get_nodejs_release(plugin.options.node_engine),
                path.join(os.path.abspath('.'), 'parts', 'test-part', 'npm')),
            mock.call().download()
        ])
Esempio n. 17
0
    def test_pull_local_sources(self):
        class Options:
            source = '.'
            node_packages = []
            node_engine = '4'
            npm_run = []

        plugin = nodejs.NodePlugin('test-part', Options(),
                                   self.project_options)

        os.makedirs(plugin.sourcedir)

        plugin.pull()

        self.assertFalse(self.run_mock.called, 'run() was called')
        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs.get_nodejs_release(
                    plugin.options.node_engine, plugin.project.deb_arch),
                path.join(self.parts_dir, 'test-part', 'npm')),
            mock.call().download()])
Esempio n. 18
0
    def test_pull_local_sources(self):
        class Options:
            source = "."
            gulp_tasks = []
            node_engine = "4"

        plugin = gulp.GulpPlugin("test-part", Options(), self.project_options)

        os.makedirs(plugin.sourcedir)

        plugin.pull()

        self.assertFalse(self.run_mock.called, "run() was called")
        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs.get_nodejs_release(plugin.options.node_engine,
                                          plugin.project.deb_arch),
                path.join(self.parts_dir, "test-part", "npm"),
            ),
            mock.call().download(),
        ])
Esempio n. 19
0
    def test_pull_local_sources(self):
        class Options:
            source = '.'
            node_packages = []
            node_engine = '4'
            npm_run = []

        plugin = nodejs.NodePlugin('test-part', Options(),
                                   self.project_options)

        os.makedirs(plugin.sourcedir)

        plugin.pull()

        self.assertFalse(self.run_mock.called, 'run() was called')
        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs.get_nodejs_release(plugin.options.node_engine,
                                          plugin.project.deb_arch),
                path.join(self.parts_dir, 'test-part', 'npm')),
            mock.call().download()
        ])
Esempio n. 20
0
    def test_pull_local_sources(self):
        class Options:
            source = "."
            gulp_tasks = []
            node_engine = "4"

        plugin = gulp.GulpPlugin("test-part", Options(), self.project_options)

        os.makedirs(plugin.sourcedir)

        plugin.pull()

        self.assertFalse(self.run_mock.called, "run() was called")
        self.tar_mock.assert_has_calls(
            [
                mock.call(
                    nodejs.get_nodejs_release(
                        plugin.options.node_engine, plugin.project.deb_arch
                    ),
                    path.join(self.parts_dir, "test-part", "npm"),
                ),
                mock.call().download(),
            ]
        )
Esempio n. 21
0
 def test_get_nodejs_release(self, machine_mock):
     machine_mock.return_value = self.machine
     node_url = nodejs.get_nodejs_release(self.engine)
     self.assertEqual(node_url, self.expected_url)
Esempio n. 22
0
 def test_get_nodejs_release(self, machine_mock, architecture_mock):
     machine_mock.return_value = self.machine
     architecture_mock.return_value = self.architecture
     project = snapcraft.ProjectOptions()
     node_url = nodejs.get_nodejs_release(self.engine, project.deb_arch)
     self.assertThat(node_url, Equals(self.expected_url))
Esempio n. 23
0
 def test_get_nodejs_release(self, machine_mock):
     machine_mock.return_value = self.machine
     node_url = nodejs.get_nodejs_release(self.engine)
     self.assertEqual(node_url, self.expected_url)
Esempio n. 24
0
 def test_get_nodejs_release(self, machine_mock, architecture_mock):
     machine_mock.return_value = self.machine
     architecture_mock.return_value = self.architecture
     project = snapcraft.ProjectOptions()
     node_url = nodejs.get_nodejs_release(self.engine, project.deb_arch)
     self.assertThat(node_url, Equals(self.expected_url))
Esempio n. 25
0
 def test_get_nodejs_release(self):
     node_url = nodejs.get_nodejs_release(self.engine, self.deb_arch)
     self.assertThat(node_url, Equals(self.expected_url))