diff mbox series

[v2,9/9] oeqa/selftest/recipetool: Add test coverage for local go modules

Message ID 20240116082327.128990-9-uvv.mail@gmail.com
State Accepted, archived
Commit 2d0ccfdca0a6cc1146464585f529fb5115a0b3ea
Headers show
Series [v2,1/9] recipetool: Don't fail on local go modules | expand

Commit Message

Vyacheslav Yurkov Jan. 16, 2024, 8:23 a.m. UTC
Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
---
 meta/lib/oeqa/selftest/cases/recipetool.py | 55 ++++++++++++++++++++++
 1 file changed, 55 insertions(+)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/recipetool.py b/meta/lib/oeqa/selftest/cases/recipetool.py
index 83848d6170..0c296875b2 100644
--- a/meta/lib/oeqa/selftest/cases/recipetool.py
+++ b/meta/lib/oeqa/selftest/cases/recipetool.py
@@ -927,6 +927,61 @@  class RecipetoolCreateTests(RecipetoolBase):
         self.assertTrue(os.path.isfile(deps_require_file))
         self._test_recipe_contents(deps_require_file, checkvars, [])
 
+    def test_recipetool_create_go_replace_modules(self):
+        # Check handling of replaced modules
+        temprecipe = os.path.join(self.tempdir, 'recipe')
+        os.makedirs(temprecipe)
+
+        recipefile = os.path.join(temprecipe, 'openapi-generator_git.bb')
+        deps_require_file = os.path.join(temprecipe, 'openapi-generator', 'go-modules.inc')
+        lics_require_file = os.path.join(temprecipe, 'openapi-generator', 'go-licenses.inc')
+        modules_txt_file = os.path.join(temprecipe, 'openapi-generator', 'modules.txt')
+
+        srcuri = 'https://github.com/OpenAPITools/openapi-generator.git'
+        srcrev = "v7.2.0"
+        srcbranch = "master"
+        srcsubdir = "samples/openapi3/client/petstore/go"
+
+        result = runCmd('recipetool create -o %s %s -S %s -B %s --src-subdir %s' % (temprecipe, srcuri, srcrev, srcbranch, srcsubdir))
+
+        self.maxDiff = None
+        inherits = ['go-vendor']
+
+        checkvars = {}
+        checkvars['GO_IMPORT'] = "github.com/OpenAPITools/openapi-generator/samples/openapi3/client/petstore/go"
+        checkvars['SRC_URI'] = {'git://${GO_IMPORT};destsuffix=git/src/${GO_IMPORT};nobranch=1;name=${BPN};protocol=https',
+                                'file://modules.txt'}
+
+        self.assertNotIn('Traceback', result.output)
+        self.assertIn('No license file was detected for the main module', result.output)
+        self.assertTrue(os.path.isfile(recipefile))
+        self._test_recipe_contents(recipefile, checkvars, inherits)
+
+        # make sure that dependencies don't mention local directory ./go-petstore
+        dependencies = \
+            [   ('github.com/stretchr/testify','v1.8.4', '', '', ''),
+                ('go.googlesource.com/oauth2','v0.10.0','golang.org/x/oauth2', '', ''),
+                ('github.com/davecgh/go-spew','v1.1.1', '', '', ''),
+                ('github.com/golang/protobuf','v1.5.3', '', '', ''),
+                ('github.com/kr/pretty','v0.3.0', '', '', ''),
+                ('github.com/pmezard/go-difflib','v1.0.0', '', '', ''),
+                ('github.com/rogpeppe/go-internal','v1.9.0', '', '', ''),
+                ('go.googlesource.com/net','v0.12.0','golang.org/x/net', '', ''),
+                ('github.com/golang/appengine','v1.6.7','google.golang.org/appengine', '', ''),
+                ('go.googlesource.com/protobuf','v1.31.0','google.golang.org/protobuf', '', ''),
+                ('gopkg.in/check.v1','v1.0.0-20201130134442-10cb98267c6c', '', '', ''),
+                ('gopkg.in/yaml.v3','v3.0.1', '', '', ''),
+            ]
+
+        src_uri = set()
+        for d in dependencies:
+            src_uri.add(self._go_urifiy(*d))
+
+        checkvars = {}
+        checkvars['GO_DEPENDENCIES_SRC_URI'] = src_uri
+
+        self.assertTrue(os.path.isfile(deps_require_file))
+        self._test_recipe_contents(deps_require_file, checkvars, [])
 
 class RecipetoolTests(RecipetoolBase):