diff mbox series

[RFC,7/7] bitbake-layers: Add test case update-layer-setup

Message ID 20231107152641.1043-9-jermain.horsman@nedap.com
State New
Headers show
Series bitbake-layers: Add update-layers-setup | expand

Commit Message

jhatnedap@gmail.com Nov. 7, 2023, 3:26 p.m. UTC
From: Jermain Horsman <jermain.horsman@nedap.com>

The test creates a layer setup, modifies it to use a branch,
attempts a checkout using the modified file, it modifies the
layers setup again to use a revision restoring it to the
original state.
A final checkout is skipped as the revision might not be
present, additionally this functionality is covered by the
setup test.

Signed-off-by: Jermain Horsman <jermain.horsman@nedap.com>
---
 meta/lib/oeqa/selftest/cases/bblayers.py | 58 +++++++++++++++++++++---
 1 file changed, 52 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/bblayers.py b/meta/lib/oeqa/selftest/cases/bblayers.py
index 8faa060234..bac4d5bbb5 100644
--- a/meta/lib/oeqa/selftest/cases/bblayers.py
+++ b/meta/lib/oeqa/selftest/cases/bblayers.py
@@ -142,6 +142,14 @@  class BitbakeLayers(OESelftestTestCase):
         jsonschema = os.path.join(get_bb_var('COREBASE'), 'meta/files/layers.schema.json')
         result = runCmd("{} {} -i {} {}".format(python, jsonvalidator, json, jsonschema))
 
+    def validate_layerscheckout(self, path):
+        testcheckoutdir = os.path.join(self.builddir, 'test-layer-checkout')
+        result = runCmd('{}/setup-layers --destdir {}'.format(path, testcheckoutdir))
+        # May not necessarily be named 'poky' or 'openembedded-core'
+        oecoredir = os.listdir(testcheckoutdir)[0]
+        testcheckoutfile = os.path.join(testcheckoutdir, oecoredir, "oe-init-build-env")
+        self.assertTrue(os.path.exists(testcheckoutfile), "File {} not found in test layer checkout".format(testcheckoutfile))
+
     def test_validate_examplelayersjson(self):
         json = os.path.join(get_bb_var('COREBASE'), "meta/files/layers.example.json")
         self.validate_layersjson(json)
@@ -161,9 +169,47 @@  class BitbakeLayers(OESelftestTestCase):
         with open(jsonfile, 'w') as f:
             json.dump(data, f)
 
-        testcheckoutdir = os.path.join(self.builddir, 'test-layer-checkout')
-        result = runCmd('{}/setup-layers --destdir {}'.format(self.testlayer_path, testcheckoutdir))
-        # May not necessarily be named 'poky' or 'openembedded-core'
-        oecoredir = os.listdir(testcheckoutdir)[0]
-        testcheckoutfile = os.path.join(testcheckoutdir, oecoredir, "oe-init-build-env")
-        self.assertTrue(os.path.exists(testcheckoutfile), "File {} not found in test layer checkout".format(testcheckoutfile))
+        self.validate_layerscheckout(self.testlayer_path)
+
+    def test_bitbakelayers_updatelayer(self):
+        result = runCmd('bitbake-layers create-layers-setup {}'.format(self.testlayer_path))
+        jsonfile = os.path.join(self.testlayer_path, "setup-layers.json")
+        self.validate_layersjson(jsonfile)
+
+        import json
+        with open(jsonfile) as f:
+            data = json.load(f)
+        test_repo = None
+        for s in data['sources']:
+            if 'contains_this_file' not in data['sources'][s].keys():
+                test_repo = s
+                test_rev = data['sources'][s]['git-remote']['rev']
+                test_desc = data['sources'][s]['git-remote']['describe']
+                break
+
+        self.assertTrue(test_repo, "No test repo found")
+
+        result = runCmd('bitbake-layers update-layers-setup {json} {repo} --branch'.format(json=jsonfile, repo=test_repo))
+        self.validate_layersjson(jsonfile)
+
+        with open(jsonfile) as f:
+            data = json.load(f)
+
+        curr_rev = data['sources'][test_repo]['git-remote']['rev']
+        curr_desc = data['sources'][test_repo]['git-remote']['describe']
+
+        self.assertEqual(curr_rev, '', "Revision not cleared: '{}'".format(curr_rev))
+        self.assertEqual(curr_desc, '', "Describe not cleared: '{}'".format(curr_desc))
+
+        self.validate_layerscheckout(self.testlayer_path)
+
+        result = runCmd('bitbake-layers update-layers-setup {json} {repo}'.format(json=jsonfile, repo=test_repo))
+        self.validate_layersjson(jsonfile)
+
+        with open(jsonfile) as f:
+            data = json.load(f)
+
+        curr_rev = data['sources'][test_repo]['git-remote']['rev']
+        curr_desc = data['sources'][test_repo]['git-remote']['describe']
+        self.assertEqual(curr_rev, test_rev, "Revision incorrect: '{}', expected '{}'".format(curr_rev, test_rev))
+        self.assertEqual(curr_desc, test_desc, "Describe incorrect: '{}', expected '{}'".format(curr_desc, test_desc))