Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import json
import os
import shutil
import unittest

from clusterfuzz._internal.datastore import data_types
Expand Down Expand Up @@ -69,23 +70,28 @@ def setUp(self):
self.fuzzer2.put()

def tearDown(self):
if os.path.exists('fuzzer1_config.json'):
os.remove('fuzzer1_config.json')
if os.path.exists('fuzzer2_config.json'):
os.remove('fuzzer2_config.json')
for fuzzer_name in ['fuzzer1', 'fuzzer2', 'fuzzer_missing']:
config_dir = os.path.join('..', 'clusterfuzz-data', 'fuzzers',
fuzzer_name)
if os.path.exists(config_dir):
shutil.rmtree(config_dir)

def test_execute_success(self):
"""Test successful download."""
args = Args(['fuzzer1', 'fuzzer2'])
download_fuzzer_config.execute(args)

with open('fuzzer1_config.json') as f:
path1 = os.path.join('..', 'clusterfuzz-data', 'fuzzers', 'fuzzer1',
'clusterfuzz_config', 'fuzzer1_config.json')
with open(path1) as f:
config1 = json.load(f)
self.assertEqual(['job1'], config1['jobs'])
self.assertEqual('data_bundle1', config1['data_bundle_name'])
self.assertEqual(10, config1['timeout'])

with open('fuzzer2_config.json') as f:
path2 = os.path.join('..', 'clusterfuzz-data', 'fuzzers', 'fuzzer2',
'clusterfuzz_config', 'fuzzer2_config.json')
with open(path2) as f:
config2 = json.load(f)
self.assertEqual([], config2['jobs'])
self.assertEqual('data_bundle2', config2['data_bundle_name'])
Expand All @@ -96,5 +102,10 @@ def test_execute_not_found(self):
args = Args(['fuzzer1', 'fuzzer_missing'])
download_fuzzer_config.execute(args)

self.assertTrue(os.path.exists('fuzzer1_config.json'))
self.assertFalse(os.path.exists('fuzzer_missing_config.json'))
path1 = os.path.join('..', 'clusterfuzz-data', 'fuzzers', 'fuzzer1',
'clusterfuzz_config', 'fuzzer1_config.json')
missing_path = os.path.join('..', 'clusterfuzz-data', 'fuzzers',
'fuzzer_missing', 'clusterfuzz_config',
'fuzzer_missing_config.json')
self.assertTrue(os.path.exists(path1))
self.assertFalse(os.path.exists(missing_path))
6 changes: 5 additions & 1 deletion src/local/butler/scripts/download_fuzzer_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Download fuzzer config as a JSON file."""

import json
import os
import sys

from clusterfuzz._internal.datastore import data_types
Expand All @@ -40,7 +41,10 @@ def execute(args):

for fuzzer in fuzzers:
config = fuzzer.get_config_dict()
filename = f'{fuzzer.name}_config.json'
output_dir = os.path.join('..', 'clusterfuzz-data', 'fuzzers', fuzzer.name,
'clusterfuzz_config')
os.makedirs(output_dir, exist_ok=True)
filename = os.path.join(output_dir, f'{fuzzer.name}_config.json')

with open(filename, 'w') as f:
json.dump(config, f, indent=4)
Expand Down
Loading