diff mbox series

[RFC,21/21] tests: fetch: add test cases for cargolock

Message ID 20241220112613.22647-22-stefan.herbrechtsmeier-oss@weidmueller.com
State New
Headers show
Series Concept for tightly coupled package manager (Node.js, Go, Rust) | expand

Commit Message

Stefan Herbrechtsmeier Dec. 20, 2024, 11:26 a.m. UTC
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

---

 lib/bb/tests/fetch.py | 75 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
diff mbox series

Patch

diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py
index 30c821a67..37146c087 100644
--- a/lib/bb/tests/fetch.py
+++ b/lib/bb/tests/fetch.py
@@ -3495,3 +3495,78 @@  class GoSumTest(FetcherTest):
         self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "azblob/go.sum")))
         self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "azblob/pkg/mod/cache/download/golang.org/x/net/@v/v0.0.0-20220425223048-2871e0cb64e4.zip")))
         self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "azblob/pkg/mod/cache/download/golang.org/x/net/@v/v0.0.0-20220425223048-2871e0cb64e4.mod")))
+
+class CargoLockTest(FetcherTest):
+    def setUp(self):
+        super().setUp()
+        self.localsrcdir = os.path.join(self.tempdir, "localsrc")
+        os.makedirs(self.localsrcdir)
+        self.d.setVar("FILESPATH", self.localsrcdir)
+
+    def create_cargo_lock_file(self, data):
+        import tomllib
+        filename = "Cargo.lock"
+        with open(os.path.join(self.localsrcdir, filename), "w") as f:
+            for package in data.get("package", []):
+                f.write("\n[[package]]\n")
+                for key in package.keys():
+                    f.write(f'{key} = "{package[key]}"\n')
+        return filename
+
+    @skipIfNoNetwork()
+    def test_cargolock(self):
+        filename = self.create_cargo_lock_file({
+            "package": [
+                {
+                    "name": "regex",
+                    "version": "1.4.0",
+                    "source": "registry+https://github.com/rust-lang/crates.io-index",
+                    "checksum": "36f45b719a674bf4b828ff318906d6c133264c793eff7a41e30074a45b5099e2"
+                }, {
+                    "name": "regex",
+                    "version": "1.5.0",
+                    "source": "git+https://github.com/rust-lang/regex.git#9f9f693768c584971a4d53bc3c586c33ed3a6831"
+                }
+            ]
+        })
+        fetcher = bb.fetch.Fetch([f"cargolock://{filename}"], self.d)
+        fetcher.download()
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "regex-1.4.0.crate")))
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "regex-1.4.0.crate.done")))
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "git2/github.com.rust-lang.regex.git")))
+        fetcher.unpack(self.unpackdir)
+        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "Cargo.lock")))
+        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "cargo_home/bitbake/regex-1.4.0/Cargo.toml")))
+        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "cargo_home/bitbake/regex-1.5.0/Cargo.toml")))
+
+    @skipIfNoNetwork()
+    def test_cargolock_https(self):
+        urls = [
+            "cargolock+https://download.gnome.org/sources/librsvg/2.58/librsvg-2.58.2.tar.xz;"
+            "striplevel=1;subdir=librsvg-2.58.2;"
+            "sha256sum=18e9d70c08cf25f50d610d6d5af571561d67cf4179f962e04266475df6e2e224"
+        ]
+        fetcher = bb.fetch.Fetch(urls, self.d)
+        fetcher.download()
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "librsvg-2.58.2.tar.xz")))
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "librsvg-2.58.2.tar.xz.done")))
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "adler-1.0.2.crate")))
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "adler-1.0.2.crate.done")))
+        fetcher.unpack(self.unpackdir)
+        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "librsvg-2.58.2/Cargo.toml")))
+        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "librsvg-2.58.2/cargo_home/bitbake/adler-1.0.2/Cargo.toml")))
+
+    @skipIfNoNetwork()
+    def test_cargolock_git(self):
+        urls = [
+            "cargolock+git://gitlab.gnome.org/GNOME/librsvg.git;protocol=https;"
+            "nobranch=1;rev=ef5c94d8362c35573d7eb651cf9a07c6df9df6da"
+        ]
+        fetcher = bb.fetch.Fetch(urls, self.d)
+        fetcher.download()
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "git2/gitlab.gnome.org.GNOME.librsvg.git")))
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "adler-1.0.2.crate")))
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "adler-1.0.2.crate.done")))
+        fetcher.unpack(self.unpackdir)
+        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "git/Cargo.toml")))
+        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "git/cargo_home/bitbake/adler-1.0.2/Cargo.toml")))