summary refs log tree commit diff
diff options
context:
space:
mode:
authorWinter <winter@winter.cafe>2022-11-13 21:10:27 -0500
committerWinter <winter@winter.cafe>2022-11-21 15:00:08 -0500
commitb117b359db1610173c81737a3f79da1b39032551 (patch)
tree291c974ac3d7077ca516d3d9b1c606cc7242d5b5
parent3d5f77f496147a4ae553154a2fb66c4a88066325 (diff)
prefetch-npm-deps: move tests to separate file
-rw-r--r--pkgs/build-support/node/fetch-npm-deps/src/main.rs94
-rw-r--r--pkgs/build-support/node/fetch-npm-deps/src/tests.rs90
2 files changed, 92 insertions, 92 deletions
diff --git a/pkgs/build-support/node/fetch-npm-deps/src/main.rs b/pkgs/build-support/node/fetch-npm-deps/src/main.rs
index 5f1e0096d5706..070f16f45a311 100644
--- a/pkgs/build-support/node/fetch-npm-deps/src/main.rs
+++ b/pkgs/build-support/node/fetch-npm-deps/src/main.rs
@@ -14,6 +14,8 @@ use tempfile::tempdir;
 use url::Url;
 
 mod cacache;
+#[cfg(test)]
+mod tests;
 
 #[derive(Deserialize)]
 struct PackageLock {
@@ -343,95 +345,3 @@ fn main() -> anyhow::Result<()> {
 
     Ok(())
 }
-
-#[cfg(test)]
-mod tests {
-    use super::{
-        get_hosted_git_url, get_ideal_hash, get_initial_url, to_new_packages, OldPackage, Package,
-        UrlOrString,
-    };
-    use std::collections::HashMap;
-    use url::Url;
-
-    #[test]
-    fn hosted_git_urls() {
-        for (input, expected) in [
-            (
-                "git+ssh://git@github.com/castlabs/electron-releases.git#fc5f78d046e8d7cdeb66345a2633c383ab41f525",
-                Some("https://codeload.github.com/castlabs/electron-releases/tar.gz/fc5f78d046e8d7cdeb66345a2633c383ab41f525"),
-            ),
-            (
-                "https://user@github.com/foo/bar#fix/bug",
-                Some("https://codeload.github.com/foo/bar/tar.gz/fix/bug")
-            ),
-            (
-                "https://github.com/eligrey/classList.js/archive/1.2.20180112.tar.gz",
-                None
-            ),
-            (
-                "git+ssh://bitbucket.org/foo/bar#branch",
-                Some("https://bitbucket.org/foo/bar/get/branch.tar.gz")
-            ),
-            (
-                "ssh://git@gitlab.com/foo/bar.git#fix/bug",
-                Some("https://gitlab.com/foo/bar/repository/archive.tar.gz?ref=fix/bug")
-            ),
-            (
-                "git+ssh://git.sr.ht/~foo/bar#branch",
-                Some("https://git.sr.ht/~foo/bar/archive/branch.tar.gz")
-            ),
-        ] {
-            assert_eq!(
-                get_hosted_git_url(&Url::parse(input).unwrap()),
-                expected.map(|u| Url::parse(u).unwrap())
-            );
-        }
-    }
-
-    #[test]
-    fn ideal_hashes() {
-        for (input, expected) in [
-            ("sha512-foo sha1-bar", Some("sha512-foo")),
-            ("sha1-bar md5-foo", Some("sha1-bar")),
-            ("sha1-bar", Some("sha1-bar")),
-            ("sha512-foo", Some("sha512-foo")),
-            ("foo-bar sha1-bar", Some("sha1-bar")),
-            ("foo-bar baz-foo", None),
-        ] {
-            assert_eq!(get_ideal_hash(input).ok(), expected);
-        }
-    }
-
-    #[test]
-    fn git_shorthand_v1() -> anyhow::Result<()> {
-        let old =
-            {
-                let mut o = HashMap::new();
-                o.insert(
-                String::from("sqlite3"),
-                OldPackage {
-                    version: UrlOrString::Url(Url::parse(
-                        "github:mapbox/node-sqlite3#593c9d498be2510d286349134537e3bf89401c4a",
-                    ).unwrap()),
-                    bundled: false,
-                    resolved: None,
-                    integrity: None,
-                    dependencies: None,
-                },
-            );
-                o
-            };
-
-        let initial_url = get_initial_url()?;
-
-        let new = to_new_packages(old, &initial_url)?;
-
-        assert_eq!(new.len(), 1, "new packages map should contain 1 value");
-        assert_eq!(new.into_values().next().unwrap(), Package {
-            resolved: Some(UrlOrString::Url(Url::parse("git+ssh://git@github.com/mapbox/node-sqlite3.git#593c9d498be2510d286349134537e3bf89401c4a").unwrap())),
-            integrity: None
-        });
-
-        Ok(())
-    }
-}
diff --git a/pkgs/build-support/node/fetch-npm-deps/src/tests.rs b/pkgs/build-support/node/fetch-npm-deps/src/tests.rs
new file mode 100644
index 0000000000000..99e091cbc2c2e
--- /dev/null
+++ b/pkgs/build-support/node/fetch-npm-deps/src/tests.rs
@@ -0,0 +1,90 @@
+use super::{
+    get_hosted_git_url, get_ideal_hash, get_initial_url, to_new_packages, OldPackage, Package,
+    UrlOrString,
+};
+use std::collections::HashMap;
+use url::Url;
+
+#[test]
+fn hosted_git_urls() {
+    for (input, expected) in [
+        (
+            "git+ssh://git@github.com/castlabs/electron-releases.git#fc5f78d046e8d7cdeb66345a2633c383ab41f525",
+            Some("https://codeload.github.com/castlabs/electron-releases/tar.gz/fc5f78d046e8d7cdeb66345a2633c383ab41f525"),
+        ),
+        (
+            "https://user@github.com/foo/bar#fix/bug",
+            Some("https://codeload.github.com/foo/bar/tar.gz/fix/bug")
+        ),
+        (
+            "https://github.com/eligrey/classList.js/archive/1.2.20180112.tar.gz",
+            None
+        ),
+        (
+            "git+ssh://bitbucket.org/foo/bar#branch",
+            Some("https://bitbucket.org/foo/bar/get/branch.tar.gz")
+        ),
+        (
+            "ssh://git@gitlab.com/foo/bar.git#fix/bug",
+            Some("https://gitlab.com/foo/bar/repository/archive.tar.gz?ref=fix/bug")
+        ),
+        (
+            "git+ssh://git.sr.ht/~foo/bar#branch",
+            Some("https://git.sr.ht/~foo/bar/archive/branch.tar.gz")
+        ),
+    ] {
+        assert_eq!(
+            get_hosted_git_url(&Url::parse(input).unwrap()),
+            expected.map(|u| Url::parse(u).unwrap())
+        );
+    }
+}
+
+#[test]
+fn ideal_hashes() {
+    for (input, expected) in [
+        ("sha512-foo sha1-bar", Some("sha512-foo")),
+        ("sha1-bar md5-foo", Some("sha1-bar")),
+        ("sha1-bar", Some("sha1-bar")),
+        ("sha512-foo", Some("sha512-foo")),
+        ("foo-bar sha1-bar", Some("sha1-bar")),
+        ("foo-bar baz-foo", None),
+    ] {
+        assert_eq!(get_ideal_hash(input).ok(), expected);
+    }
+}
+
+#[test]
+fn git_shorthand_v1() -> anyhow::Result<()> {
+    let old = {
+        let mut o = HashMap::new();
+        o.insert(
+            String::from("sqlite3"),
+            OldPackage {
+                version: UrlOrString::Url(
+                    Url::parse(
+                        "github:mapbox/node-sqlite3#593c9d498be2510d286349134537e3bf89401c4a",
+                    )
+                    .unwrap(),
+                ),
+                bundled: false,
+                resolved: None,
+                integrity: None,
+                dependencies: None,
+            },
+        );
+        o
+    };
+
+    let initial_url = get_initial_url()?;
+
+    let new = to_new_packages(old, &initial_url)?;
+
+    assert_eq!(new.len(), 1, "new packages map should contain 1 value");
+    assert_eq!(new.into_values().next().unwrap(), Package {
+        resolved: Some(UrlOrString::Url(Url::parse("git+ssh://git@github.com/mapbox/node-sqlite3.git#593c9d498be2510d286349134537e3bf89401c4a").unwrap())),
+        integrity: None
+    });
+
+    Ok(())
+}