Exemplo n.º 1
0
    def test_template_error(self):
        """
        Template errors result in the process exiting and an error message
        printed to stderr.
        Packer prints machine-readable output to stderr and
        ``publish-installer-images`` echos those lines to its stderr as well as
        parsing the output.
        """
        sys_module = FakeSysModule()
        self.addCleanup(lambda: self.addDetail(
            name="stderr",
            content_object=text_content(sys_module.stderr.getvalue())))

        configuration_path = self.make_temporary_file(content='')

        d = async_perform(
            dispatcher=RealPerformers(sys_module=sys_module, ).dispatcher(),
            effect=Effect(
                intent=PackerBuild(configuration_path=configuration_path, )))

        d = self.assertFailure(d, ProcessTerminated)

        def check_error(exception):
            self.assertEqual(1, exception.exitCode)
            self.assertIn("Failed to parse template",
                          sys_module.stderr.getvalue())

        return d.addCallback(check_error)
Exemplo n.º 2
0
    def test_run(self):
        """
        ``BuildScript.main`` calls ``run`` on the instance returned by
        ``build_command``.
        """
        expected_destination_path = FilePath(self.mktemp())
        expected_distribution = 'centos7'
        expected_package_uri = 'http://www.example.com/foo/bar.whl'
        fake_sys_module = FakeSysModule(argv=[
            'build-command-name', '--destination-path',
            expected_destination_path.path,
            '--distribution=%s' %
            (expected_distribution, ), expected_package_uri
        ])
        script = BuildScript(sys_module=fake_sys_module)
        build_step = SpyStep()
        arguments = []

        def record_arguments(*args, **kwargs):
            arguments.append((args, kwargs))
            return build_step

        script.build_command = record_arguments
        script.main()
        expected_build_arguments = [
            ((),
             dict(destination_path=expected_destination_path,
                  distribution=expected_distribution,
                  package_uri=expected_package_uri,
                  top_level=None))
        ]
        self.assertEqual(expected_build_arguments, arguments)
        self.assertTrue(build_step.ran)
Exemplo n.º 3
0
    def test_run(self):
        """
        ``DockerBuildScript.main`` calls ``run`` on the instance returned by
        ``build_command``.
        """
        expected_destination_path = FilePath(self.mktemp())
        expected_package_uri = 'http://www.example.com/foo/bar.whl'
        fake_sys_module = FakeSysModule(argv=[
            'build-command-name',
            '--destination-path=%s' %
            (expected_destination_path.path, ), expected_package_uri
        ])
        distribution = Distribution(name='test-distro', version='30')
        self.patch(packaging, 'CURRENT_DISTRIBUTION', distribution)
        script = DockerBuildScript(sys_module=fake_sys_module)
        build_step = SpyStep()
        arguments = []

        def record_arguments(*args, **kwargs):
            arguments.append((args, kwargs))
            return build_step

        script.build_command = record_arguments
        script.main()
        expected_build_arguments = [
            ((),
             dict(destination_path=expected_destination_path,
                  package_uri=expected_package_uri,
                  distribution=distribution))
        ]
        self.assertEqual(expected_build_arguments, arguments)
        self.assertTrue(build_step.ran)
Exemplo n.º 4
0
 def test_usage_error_status(self):
     """
     ``BuildScript.main`` raises ``SystemExit`` if there are missing command
     line options.
     """
     fake_sys_module = FakeSysModule(argv=[])
     script = BuildScript(sys_module=fake_sys_module)
     exception = self.assertRaises(SystemExit, script.main)
     self.assertEqual(1, exception.code)
Exemplo n.º 5
0
 def test_perform(self):
     """
     ``StandardOut`` has a performer that writes content to sys.stdout.
     """
     fake_sys_module = FakeSysModule()
     intent = StandardOut(content=random_name(self).encode('ascii'), )
     result = sync_perform(
         dispatcher=RealPerformers(sys_module=fake_sys_module).dispatcher(),
         effect=Effect(intent=intent))
     self.assertIs(None, result)
     self.assertEqual(intent.content, fake_sys_module.stdout.getvalue())
Exemplo n.º 6
0
 def test_usage_error_message(self):
     """
     ``BuildScript.main`` prints a usage error to ``stderr`` if there are
     missing command line options.
     """
     fake_sys_module = FakeSysModule(argv=[])
     script = BuildScript(sys_module=fake_sys_module)
     try:
         script.main()
     except SystemExit:
         pass
     self.assertEqual('Wrong number of arguments.',
                      fake_sys_module.stderr.getvalue().splitlines()[-1])