Ejemplo n.º 1
0
  def test_go_thrift_gen_single(self):
    # Compile with one thrift file.
    thrift_files = {
        'src/thrift/thrifttest/duck.thrift':
          _NAMESPACE + _DUCK_STRUCT + _FEEDER_STRUCT_TEMPLATE.format(include=''),
      }
    with self.temporary_workdir() as workdir:
      with self._create_thrift_project(thrift_files) as (srcdir, config):
        args = [
            'compile',
            os.path.join(srcdir, 'src/go/usethrift')
          ]
        pants_run = self.run_pants_with_workdir(args, workdir, config=config)
        self.assert_success(pants_run)

        # Fetch the hash for task impl version.
        go_thrift_contents = [p for p in os.listdir(os.path.join(workdir, 'gen', 'go-thrift'))
                              if p != 'current']  # Ignore the 'current' symlink.
        self.assertEqual(len(go_thrift_contents), 1)
        hash_dir = go_thrift_contents[0]

        target_dir = os.path.relpath(os.path.join(srcdir, 'src/thrift/thrifttest/fleem'),
                                     get_buildroot())
        root = os.path.join(workdir, 'gen', 'go-thrift', hash_dir,
                            target_dir.replace(os.path.sep, '.'), 'current')

        self.assertEqual(sorted(['src/go/thrifttest/duck/duck-consts.go',
                                  'src/go/thrifttest/duck/duck.go',
                                  'src/go/thrifttest/duck/GoUnusedProtection__.go',
                                  'src/go/thrifttest/duck/feeder-remote/feeder-remote.go']),
                          sorted(exact_files(root)))
    def test_hello_service(self):
        with self.temporary_workdir() as workdir:
            cmd = ["gen", self.jax_ws_test_target("hello-service")]
            pants_run = self.run_pants_with_workdir(cmd,
                                                    workdir,
                                                    config=self.full_config)
            self.assert_success(pants_run)
            self.assertIn("[jax-ws]", pants_run.stdout_data)

            jax_ws_contents = [
                p for p in os.listdir(os.path.join(workdir, "gen", "jax-ws"))
                if p != "current"
            ]
            self.assertEqual(len(jax_ws_contents), 1)
            hash_dir = jax_ws_contents[0]

            root = os.path.join(
                workdir,
                "gen",
                "jax-ws",
                hash_dir,
                "contrib.jax_ws.tests.wsdl.org.pantsbuild.contrib.jax_ws.hello-service",
                "current",
            )

            self.assertEqual(
                sorted([
                    "com/example/HelloWorldServer.java",
                    "com/example/HelloWorldServerImplService.java",
                ]),
                sorted(exact_files(root)),
            )
    def test_hello_service(self):
        with self.temporary_workdir() as workdir:
            cmd = ['gen', self.jax_ws_test_target('hello-service')]
            pants_run = self.run_pants_with_workdir(cmd,
                                                    workdir,
                                                    config=self.full_config)
            self.assert_success(pants_run)
            self.assertIn('[jax-ws]', pants_run.stdout_data)

            jax_ws_contents = [
                p for p in os.listdir(os.path.join(workdir, 'gen', 'jax-ws'))
                if p != 'current'
            ]
            self.assertEqual(len(jax_ws_contents), 1)
            hash_dir = jax_ws_contents[0]

            root = os.path.join(
                workdir, 'gen', 'jax-ws', hash_dir,
                'contrib.jax_ws.tests.wsdl.org.pantsbuild.contrib.jax_ws.hello-service',
                'current')

            self.assertEqual(
                sorted([
                    'com/example/HelloWorldServer.java',
                    'com/example/HelloWorldServerImplService.java'
                ]), sorted(exact_files(root)))
Ejemplo n.º 4
0
    def test_good(self):
        # wire example should compile without warnings with correct wire files.

        # force a compile to happen, we count on compile output in this test
        self.assert_success(self.run_pants(['clean-all']))

        with self.temporary_workdir() as workdir:
            cmd = [
                'compile',
                'examples/src/java/org/pantsbuild/example/wire/temperatureservice'
            ]
            pants_run = self.run_pants_with_workdir(cmd, workdir)
            self.assert_success(pants_run)

            pattern = 'gen/wire/[^/]*/[^/]*/[^/]*/org/pantsbuild/example/temperature/Temperature.java'
            files = exact_files(workdir)
            self.assertTrue(
                any(re.match(pattern, f) is not None for f in files),
                f'Expected pattern: {pattern} in {files}')
Ejemplo n.º 5
0
    def corrupt_artifacts(self, pattern):
        """Corrupts any artifacts matching the given pattern.

    Returns the number of files affected.
    """
        regex = re.compile(pattern)
        count = 0
        for f in exact_files(self._cache_root, ignore_links=True):
            if not regex.match(f):
                continue

            # Truncate the file.
            abspath = os.path.join(self._cache_root, f)
            artifact_size = os.path.getsize(abspath)
            with open(abspath, 'r+') as outfile:
                outfile.truncate(artifact_size // 2)

            count += 1

        return count