tools: Add tool's versions update with checksum file

'idf_tools.py add-version' has new options:
--override            Override tool versions with new data
--checksum-file       URL or path to local file with checksum/size for artifacts

Usage e.g.:
CHECKSUM_URL=https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/crosstool-NG-esp-2021r2-checksum.sha256
idf_tools.py add-version --tool xtensa-esp32-elf --version esp-2021r2 --override --checksum-file $CHECKSUM_URL

Positional argument 'files' moved to optional argument '--artifact-file'

Add tests for add-version logic
This commit is contained in:
Alexey Lapshin
2022-03-15 23:02:37 +04:00
committed by BOT
parent dcaa74ebb3
commit e49d4a83d9
7 changed files with 395 additions and 13 deletions

View File

@@ -386,6 +386,13 @@ class TestUsage(unittest.TestCase):
class TestMaintainer(unittest.TestCase):
@classmethod
def setUpClass(cls):
idf_path = os.getenv('IDF_PATH')
cls.tools_old = os.path.join(idf_path, 'tools/tools.json')
cls.tools_new = os.path.join(idf_path, 'tools/tools.new.json')
cls.test_tool_name = 'xtensa-esp32-elf'
def test_validation(self):
idf_tools.main(['validate'])
@@ -394,12 +401,88 @@ class TestMaintainer(unittest.TestCase):
idf_path = os.getenv('IDF_PATH')
if not idf_path:
self.fail('IDF_PATH needs to be set to run this test')
with open(os.path.join(idf_path, 'tools/tools.json'), 'r') as f:
with open(self.tools_old, 'r') as f:
json_old = f.read()
with open(os.path.join(idf_path, 'tools/tools.new.json'), 'r') as f:
with open(self.tools_new, 'r') as f:
json_new = f.read()
self.assertEqual(json_old, json_new, "Please check 'tools/tools.new.json' to find a cause!")
def add_version_get_expected_json(self, addition_file, replace=False):
with open(self.tools_old, 'r') as f:
expected_json = json.load(f)
with open(addition_file, 'r') as f:
addition_json = json.load(f)
for tool in expected_json['tools']:
if tool['name'] == self.test_tool_name:
if replace:
tool['versions'] = [addition_json]
else:
tool['versions'].append(addition_json)
return expected_json
return None
def test_add_version_artifact_addition(self):
filenames = []
with open('add_version/artifact_input.json', 'r') as f:
add_tools_info = json.load(f)
for tool in add_tools_info:
filenames.append(tool['filename'])
with open(tool['filename'], 'w') as f:
self.addCleanup(os.remove, f.name)
f.write('1' * tool['size'])
idf_tools.main(
[
'add-version',
'--tool',
self.test_tool_name,
'--url-prefix',
'http://test.com',
'--version',
'test',
'--artifact-file'
] + filenames
)
expected_json = self.add_version_get_expected_json('add_version/artifact_expected_addition.json')
with open(self.tools_new, 'r') as f1:
self.assertEqual(json.load(f1), expected_json, "Please check 'tools/tools.new.json' to find a cause!")
def test_add_version_checksum_addition(self):
idf_tools.main(
[
'add-version',
'--tool',
self.test_tool_name,
'--url-prefix',
'http://test.com',
'--version',
'test',
'--checksum-file',
'add_version/checksum.sha256',
]
)
expected_json = self.add_version_get_expected_json('add_version/checksum_expected_addition.json')
with open(self.tools_new, 'r') as f1:
self.assertEqual(json.load(f1), expected_json, "Please check 'tools/tools.new.json' to find a cause!")
def test_add_version_checksum_with_override(self):
idf_tools.main(
[
'add-version',
'--tool',
self.test_tool_name,
'--url-prefix',
'http://test.com',
'--version',
'test',
'--override',
'--checksum-file',
'add_version/checksum.sha256'
]
)
expected_json = self.add_version_get_expected_json('add_version/checksum_expected_override.json', True)
with open(self.tools_new, 'r') as f1:
self.assertEqual(json.load(f1), expected_json, "Please check 'tools/tools.new.json' to find a cause!")
if __name__ == '__main__':
unittest.main()