'Tests that glob doesn\'t use too many client round trips.'

def testGlobRoundtrips(self):

    for (pattern, num_find, num_stat, duplicated_ok) in [('test_data/test_artifact.json', 0, 1, False), ('test_data/test_*', 1, 0, False), ('test_da*/test_artifact.json', 1, 1, False), ('test_da*/test_*', 2, 0, False), ('test_da*/test_{artifact,artifacts}.json', 1, 2, True), ('test_data/test_{artifact,artifacts}.json', 0, 2, False), ('test_data/{ntfs_img.dd,*.log,*.raw}', 1, 1, False), ('test_data/{*.log,*.raw}', 1, 0, False), ('test_data/a/**/helloc.txt', 1, None, False), ('test_data/a/**/hello{c,d}.txt', 1, None, True), ('test_data/a/**/hello*.txt', 4, None, False), ('test_data/a/**.txt', 1, None, False), ('test_data/a/**5*.txt', 1, None, False), ('test_data/a/**{.json,.txt}', 1, 0, False)]:
        path = os.path.join(os.path.dirname(self.base_path), pattern)
        client_mock = action_mocks.GlobClientMock()
        for _ in flow_test_lib.TestFlowHelper(filesystem.Glob.__name__, client_mock, client_id=self.client_id, paths=[path], token=self.token):
            pass
        if (num_find is not None):
            self.assertEqual(client_mock.action_counts.get('Find', 0), num_find)
        if (num_stat is not None):
            self.assertEqual(client_mock.action_counts.get('StatFile', 0), num_stat)
        if (not duplicated_ok):
            for method in ('StatFile', 'Find'):
                stat_args = client_mock.recorded_args.get(method, [])
                stat_paths = [c.pathspec.CollapsePath() for c in stat_args]
                self.assertListEqual(sorted(stat_paths), sorted(set(stat_paths)))
