Andrew Geissler | 6aa7eec | 2023-03-03 12:41:14 -0600 | [diff] [blame] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | import os |
| 8 | import sys |
| 9 | import subprocess |
| 10 | import shutil |
| 11 | from oeqa.selftest.case import OESelftestTestCase |
| 12 | from yocto_testresults_query import get_sha1, create_workdir |
| 13 | basepath = os.path.abspath(os.path.dirname(__file__) + '/../../../../../') |
| 14 | lib_path = basepath + '/scripts/lib' |
| 15 | sys.path = sys.path + [lib_path] |
| 16 | |
| 17 | |
| 18 | class TestResultsQueryTests(OESelftestTestCase): |
| 19 | def test_get_sha1(self): |
| 20 | test_data_get_sha1 = [ |
| 21 | {"input": "yocto-4.0", "expected": "00cfdde791a0176c134f31e5a09eff725e75b905"}, |
| 22 | {"input": "4.1_M1", "expected": "95066dde6861ee08fdb505ab3e0422156cc24fae"}, |
| 23 | ] |
| 24 | for data in test_data_get_sha1: |
| 25 | test_name = data["input"] |
| 26 | with self.subTest(f"Test SHA1 from {test_name}"): |
| 27 | self.assertEqual( |
| 28 | get_sha1(basepath, data["input"]), data["expected"]) |
| 29 | |
| 30 | def test_create_workdir(self): |
| 31 | workdir = create_workdir() |
| 32 | try: |
| 33 | url = subprocess.check_output( |
| 34 | ["git", "-C", workdir, "remote", "get-url", "origin"]).strip().decode("utf-8") |
| 35 | except: |
| 36 | shutil.rmtree(workdir, ignore_errors=True) |
| 37 | self.fail(f"Can not execute git commands in {workdir}") |
| 38 | shutil.rmtree(workdir) |
| 39 | self.assertEqual(url, "git://git.yoctoproject.org/yocto-testresults") |