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.assertEquals(sorted(['src/go/thrifttest/duck/constants.go', 'src/go/thrifttest/duck/ttypes.go', 'src/go/thrifttest/duck/feeder.go', 'src/go/thrifttest/duck/feeder-remote/feeder-remote.go']), sorted(exact_files(root)))
def test_go_thrift_gen_simple(self): with self.temporary_workdir() as workdir: args = [ 'gen', 'contrib/go/testprojects/src/thrift/thrifttest:fleem' ] pants_run = self.run_pants_with_workdir(args, workdir) self.assert_success(pants_run) with subsystem_instance(GoDistribution.Factory) as factory: go_dist = factory.create() go_dist.create_go_cmd('env', args=['GOOS']).check_output().strip() go_dist.create_go_cmd('env', args=['GOARCH']).check_output().strip() expected_files = { 'src/go/thrifttest/duck/constants.go', 'src/go/thrifttest/duck/ttypes.go', } # Fetch the hash for task impl version. go_thrift_contents = os.listdir( os.path.join(workdir, 'gen', 'go-thrift')) self.assertEqual(len(go_thrift_contents), 1) root = os.path.join( workdir, 'gen', 'go-thrift', go_thrift_contents[0], 'contrib.go.testprojects.src.thrift.thrifttest.fleem', 'current') self.assertEquals(sorted(expected_files), sorted(exact_files(root)))
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.assertEquals(sorted(['src/go/thrifttest/duck/constants.go', 'src/go/thrifttest/duck/ttypes.go', 'src/go/thrifttest/duck/feeder.go', 'src/go/thrifttest/duck/feeder-remote/feeder-remote.go']), sorted(exact_files(root)))
def test_go_thrift_gen_simple(self): with self.temporary_workdir() as workdir: with self._create_thrift_project() as (srcdir, config): args = [ 'gen', os.path.join(srcdir, 'src/thrift/thrifttest:fleem') ] 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 = os.listdir( os.path.join(workdir, 'gen', 'go-thrift')) 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.assertEquals( sorted([ 'src/go/thrifttest/duck/constants.go', 'src/go/thrifttest/duck/ttypes.go', 'src/go/thrifttest/duck/feeder.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.assertEquals( sorted([ 'com/example/HelloWorldServer.java', 'com/example/HelloWorldServerImplService.java' ]), sorted(exact_files(root)))
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), 'Expected pattern: {} in {}'.format(pattern, files))
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), 'Expected pattern: {} in {}'.format(pattern, files))
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 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
def test_go_thrift_gen_simple(self): with self.temporary_workdir() as workdir: with self._create_thrift_project() as (srcdir, config): args = ['gen', os.path.join(srcdir, 'src/thrift/thrifttest:fleem')] 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 = os.listdir(os.path.join(workdir, 'gen', 'go-thrift')) 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.assertEquals(sorted(['src/go/thrifttest/duck/constants.go', 'src/go/thrifttest/duck/ttypes.go']), sorted(exact_files(root)))
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+w') as outfile: outfile.truncate(artifact_size // 2) count += 1 return count
def test_go_thrift_gen_simple(self): with self.temporary_workdir() as workdir: args = ['gen', 'contrib/go/testprojects/src/thrift/thrifttest:fleem'] pants_run = self.run_pants_with_workdir(args, workdir) self.assert_success(pants_run) with subsystem_instance(GoDistribution.Factory) as factory: go_dist = factory.create() go_dist.create_go_cmd('env', args=['GOOS']).check_output().strip() go_dist.create_go_cmd('env', args=['GOARCH']).check_output().strip() expected_files = { 'src/go/thrifttest/duck/constants.go', 'src/go/thrifttest/duck/ttypes.go', } # Fetch the hash for task impl version. go_thrift_contents = os.listdir(os.path.join(workdir, 'gen', 'go-thrift')) self.assertEqual(len(go_thrift_contents), 1) root = os.path.join(workdir, 'gen', 'go-thrift', go_thrift_contents[0], 'contrib.go.testprojects.src.thrift.thrifttest.fleem', 'current') self.assertEquals(sorted(expected_files), sorted(exact_files(root)))