Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9dfc011

Browse filesBrowse files
committed
refactor: remove default registry values
1 parent fccea34 commit 9dfc011
Copy full SHA for 9dfc011

File tree

Expand file treeCollapse file tree

15 files changed

+91
-164
lines changed
Filter options
Expand file treeCollapse file tree

15 files changed

+91
-164
lines changed

‎examples/archive_async/src/main.rs

Copy file name to clipboardExpand all lines: examples/archive_async/src/main.rs
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#![forbid(unsafe_code)]
22
#![deny(clippy::pedantic)]
33

4-
use postgresql_archive::{extract, get_archive, Result, VersionReq, DEFAULT_POSTGRESQL_URL};
4+
use postgresql_archive::{
5+
extract, get_archive, Result, VersionReq, THESEUS_POSTGRESQL_BINARIES_URL,
6+
};
57

68
#[tokio::main]
79
async fn main() -> Result<()> {
810
let version_req = VersionReq::STAR;
9-
let (archive_version, archive) = get_archive(DEFAULT_POSTGRESQL_URL, &version_req).await?;
11+
let (archive_version, archive) =
12+
get_archive(THESEUS_POSTGRESQL_BINARIES_URL, &version_req).await?;
1013
let out_dir = tempfile::tempdir()?.into_path();
1114
extract(&archive, &out_dir).await?;
1215
println!(

‎examples/archive_sync/src/main.rs

Copy file name to clipboardExpand all lines: examples/archive_sync/src/main.rs
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#![deny(clippy::pedantic)]
33

44
use postgresql_archive::blocking::{extract, get_archive};
5-
use postgresql_archive::{Result, VersionReq, DEFAULT_POSTGRESQL_URL};
5+
use postgresql_archive::{Result, VersionReq, THESEUS_POSTGRESQL_BINARIES_URL};
66

77
fn main() -> Result<()> {
88
let version_req = VersionReq::STAR;
9-
let (archive_version, archive) = get_archive(DEFAULT_POSTGRESQL_URL, &version_req)?;
9+
let (archive_version, archive) = get_archive(THESEUS_POSTGRESQL_BINARIES_URL, &version_req)?;
1010
let out_dir = tempfile::tempdir()?.into_path();
1111
extract(&archive, &out_dir)?;
1212
println!(

‎postgresql_archive/benches/archive.rs

Copy file name to clipboardExpand all lines: postgresql_archive/benches/archive.rs
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use criterion::{criterion_group, criterion_main, Criterion};
22
use postgresql_archive::blocking::{extract, get_archive};
3-
use postgresql_archive::{Result, VersionReq, DEFAULT_POSTGRESQL_URL};
3+
use postgresql_archive::{Result, VersionReq, THESEUS_POSTGRESQL_BINARIES_URL};
44
use std::fs::{create_dir_all, remove_dir_all};
55
use std::time::Duration;
66

@@ -10,7 +10,7 @@ fn benchmarks(criterion: &mut Criterion) {
1010

1111
fn bench_extract(criterion: &mut Criterion) -> Result<()> {
1212
let version_req = VersionReq::STAR;
13-
let (_archive_version, archive) = get_archive(DEFAULT_POSTGRESQL_URL, &version_req)?;
13+
let (_archive_version, archive) = get_archive(THESEUS_POSTGRESQL_BINARIES_URL, &version_req)?;
1414

1515
criterion.bench_function("extract", |bencher| {
1616
bencher.iter(|| {

‎postgresql_archive/src/archive.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/archive.rs
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use std::time::Duration;
1616
use tar::Archive;
1717
use tracing::{debug, instrument, warn};
1818

19-
pub const DEFAULT_POSTGRESQL_URL: &str = "https://github.com/theseus-rs/postgresql-binaries";
19+
pub const THESEUS_POSTGRESQL_BINARIES_URL: &str =
20+
"https://github.com/theseus-rs/postgresql-binaries";
2021

2122
/// Gets the version for the specified [version requirement](VersionReq). If a version for the
2223
/// [version requirement](VersionReq) is not found, then an error is returned.
@@ -213,15 +214,15 @@ mod tests {
213214
#[tokio::test]
214215
async fn test_get_version() -> Result<()> {
215216
let version_req = VersionReq::parse("=16.3.0")?;
216-
let version = get_version(DEFAULT_POSTGRESQL_URL, &version_req).await?;
217+
let version = get_version(THESEUS_POSTGRESQL_BINARIES_URL, &version_req).await?;
217218
assert_eq!(Version::new(16, 3, 0), version);
218219
Ok(())
219220
}
220221

221222
#[tokio::test]
222223
async fn test_get_archive() -> Result<()> {
223224
let version_req = VersionReq::parse("=16.3.0")?;
224-
let (version, bytes) = get_archive(DEFAULT_POSTGRESQL_URL, &version_req).await?;
225+
let (version, bytes) = get_archive(THESEUS_POSTGRESQL_BINARIES_URL, &version_req).await?;
225226
assert_eq!(Version::new(16, 3, 0), version);
226227
assert!(!bytes.is_empty());
227228
Ok(())

‎postgresql_archive/src/hasher/registry.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/hasher/registry.rs
+26-51Lines changed: 26 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::hasher::{blake2b_512, blake2s_256, sha2_256, sha2_512, sha3_256, sha3_512};
2-
use crate::Error::{PoisonedLock, UnsupportedRepository};
3-
use crate::Result;
1+
use crate::hasher::sha2_256;
2+
use crate::Error::{PoisonedLock, UnsupportedHasher};
3+
use crate::{Result, THESEUS_POSTGRESQL_BINARIES_URL};
44
use lazy_static::lazy_static;
55
use std::sync::{Arc, Mutex, RwLock};
66

@@ -57,20 +57,20 @@ impl HasherRegistry {
5757
}
5858
}
5959

60-
Err(UnsupportedRepository(url.to_string()))
60+
Err(UnsupportedHasher(url.to_string()))
6161
}
6262
}
6363

6464
impl Default for HasherRegistry {
6565
/// Creates a new hasher registry with the default hashers registered.
6666
fn default() -> Self {
6767
let mut registry = Self::new();
68-
registry.register(|_, extension| Ok(extension == "blake2s"), blake2s_256::hash);
69-
registry.register(|_, extension| Ok(extension == "blake2b"), blake2b_512::hash);
70-
registry.register(|_, extension| Ok(extension == "sha256"), sha2_256::hash);
71-
registry.register(|_, extension| Ok(extension == "sha512"), sha2_512::hash);
72-
registry.register(|_, extension| Ok(extension == "sha3-256"), sha3_256::hash);
73-
registry.register(|_, extension| Ok(extension == "sha3-512"), sha3_512::hash);
68+
registry.register(
69+
|url, extension| {
70+
Ok(url.starts_with(THESEUS_POSTGRESQL_BINARIES_URL) && extension == "sha256")
71+
},
72+
sha2_256::hash,
73+
);
7474
registry
7575
}
7676
}
@@ -115,57 +115,32 @@ mod tests {
115115
#[test]
116116
fn test_register() -> Result<()> {
117117
register(
118-
|_, extension| Ok(extension == "foo"),
118+
|_, extension| Ok(extension == "test"),
119119
|_| Ok("42".to_string()),
120120
)?;
121-
test_hasher("foo", "42")
122-
}
123-
124-
#[test]
125-
fn test_sha2_256() -> Result<()> {
126-
test_hasher(
127-
"sha256",
128-
"9a89c68c4c5e28b8c4a5567673d462fff515db46116f9900624d09c474f593fb",
129-
)
130-
}
131-
132-
#[test]
133-
fn test_sha2_512() -> Result<()> {
134-
test_hasher(
135-
"sha512",
136-
"3ad3f36979450d4f53366244ecf1010f4f9121d6888285ff14104fd5aded85d48aa171bf1e33a112602f92b7a7088b298789012fb87b9056321241a19fb74e0b",
137-
)
138-
}
139-
140-
#[test]
141-
fn test_sha3_256() -> Result<()> {
142-
test_hasher(
143-
"sha3-256",
144-
"c0188232190e0427fc9cc78597221c76c799528660889bd6ce1f3563148ff84d",
145-
)
121+
test_hasher("test", "42")
146122
}
147123

148124
#[test]
149-
fn test_sha3_512() -> Result<()> {
150-
test_hasher(
151-
"sha3-512",
152-
"9429fc1f9772cc1d8039fe75cc1b033cd60f0ec4face0f8a514d25b0649ba8a5954b6c7a41cc3697a56db3ff321475be1fa14b70c7eb78fec6ce62dbfc54c9d3",
153-
)
125+
fn test_get_invalid_url_error() {
126+
let error = get("https://foo.com", "foo").unwrap_err();
127+
assert_eq!(
128+
"unsupported hasher for 'https://foo.com'",
129+
error.to_string()
130+
);
154131
}
155132

156133
#[test]
157-
fn test_blake2s_256() -> Result<()> {
158-
test_hasher(
159-
"blake2s",
160-
"7125921e06071710350390fe902856dbea366a5d6f5ee26c18e741143ac80061",
161-
)
134+
fn test_get_invalid_extension_error() {
135+
let error = get(THESEUS_POSTGRESQL_BINARIES_URL, "foo").unwrap_err();
136+
assert_eq!(
137+
format!("unsupported hasher for '{THESEUS_POSTGRESQL_BINARIES_URL}'"),
138+
error.to_string()
139+
);
162140
}
163141

164142
#[test]
165-
fn test_blake2b_512() -> Result<()> {
166-
test_hasher(
167-
"blake2b",
168-
"67767f1cab415502dcceec9f099fb84539b1c73c5ebdcfe1bb8ca7411e3b6cb33e304f49222edac9bdaa74129e9e13f11f215b8560f9081f0e8f1f869162bf46",
169-
)
143+
fn test_get_theseus_postgresql_binaries() {
144+
assert!(get(THESEUS_POSTGRESQL_BINARIES_URL, "sha256").is_ok());
170145
}
171146
}

‎postgresql_archive/src/lib.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/lib.rs
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
//! ### Asynchronous API
2222
//!
2323
//! ```no_run
24-
//! use postgresql_archive::{extract, get_archive, Result, VersionReq, DEFAULT_POSTGRESQL_URL};
24+
//! use postgresql_archive::{extract, get_archive, Result, VersionReq, THESEUS_POSTGRESQL_BINARIES_URL};
2525
//!
2626
//! #[tokio::main]
2727
//! async fn main() -> Result<()> {
28-
//! let (archive_version, archive) = get_archive(DEFAULT_POSTGRESQL_URL, &VersionReq::STAR).await?;
28+
//! let (archive_version, archive) = get_archive(THESEUS_POSTGRESQL_BINARIES_URL, &VersionReq::STAR).await?;
2929
//! let out_dir = std::env::temp_dir();
3030
//! extract(&archive, &out_dir).await
3131
//! }
@@ -34,10 +34,10 @@
3434
//! ### Synchronous API
3535
//! ```no_run
3636
//! #[cfg(feature = "blocking")] {
37-
//! use postgresql_archive::{VersionReq, DEFAULT_POSTGRESQL_URL};
37+
//! use postgresql_archive::{VersionReq, THESEUS_POSTGRESQL_BINARIES_URL};
3838
//! use postgresql_archive::blocking::{extract, get_archive};
3939
//!
40-
//! let (archive_version, archive) = get_archive(DEFAULT_POSTGRESQL_URL, &VersionReq::STAR).unwrap();
40+
//! let (archive_version, archive) = get_archive(THESEUS_POSTGRESQL_BINARIES_URL, &VersionReq::STAR).unwrap();
4141
//! let out_dir = std::env::temp_dir();
4242
//! let result = extract(&archive, &out_dir).unwrap();
4343
//! }
@@ -118,7 +118,7 @@ pub mod matcher;
118118
pub mod repository;
119119
mod version;
120120

121-
pub use archive::DEFAULT_POSTGRESQL_URL;
121+
pub use archive::THESEUS_POSTGRESQL_BINARIES_URL;
122122
pub use archive::{extract, get_archive, get_version};
123123
pub use error::{Error, Result};
124124
pub use semver::{Version, VersionReq};

‎postgresql_archive/src/matcher/mod.rs

Copy file name to clipboard
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
pub mod default;
21
pub mod postgresql_binaries;
32
pub mod registry;
3+
pub mod target_os_arch;

‎postgresql_archive/src/matcher/registry.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/matcher/registry.rs
+10-13Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::matcher::{default, postgresql_binaries};
1+
use crate::matcher::postgresql_binaries;
22
use crate::Error::{PoisonedLock, UnsupportedMatcher};
3-
use crate::{Result, DEFAULT_POSTGRESQL_URL};
3+
use crate::{Result, THESEUS_POSTGRESQL_BINARIES_URL};
44
use lazy_static::lazy_static;
55
use semver::Version;
66
use std::sync::{Arc, Mutex, RwLock};
@@ -66,10 +66,9 @@ impl Default for MatchersRegistry {
6666
fn default() -> Self {
6767
let mut registry = Self::new();
6868
registry.register(
69-
|url| Ok(url == DEFAULT_POSTGRESQL_URL),
69+
|url| Ok(url == THESEUS_POSTGRESQL_BINARIES_URL),
7070
postgresql_binaries::matcher,
7171
);
72-
registry.register(|_| Ok(true), default::matcher);
7372
registry
7473
}
7574
}
@@ -102,7 +101,6 @@ pub fn get<S: AsRef<str>>(url: S) -> Result<MatcherFn> {
102101
#[cfg(test)]
103102
mod tests {
104103
use super::*;
105-
use std::env;
106104

107105
#[test]
108106
fn test_register() -> Result<()> {
@@ -119,14 +117,13 @@ mod tests {
119117
}
120118

121119
#[test]
122-
fn test_default_matcher() -> Result<()> {
123-
let matcher = get("https://foo.com")?;
124-
let version = Version::new(16, 3, 0);
125-
let os = env::consts::OS;
126-
let arch = env::consts::ARCH;
127-
let name = format!("plugin_csv.pg16-{os}_{arch}.tar.gz");
120+
fn test_get_error() {
121+
let result = get("foo").unwrap_err();
122+
assert_eq!("unsupported matcher for 'foo'", result.to_string());
123+
}
128124

129-
assert!(matcher(name.as_str(), &version)?, "{}", name);
130-
Ok(())
125+
#[test]
126+
fn test_get_theseus_postgresql_binaries() {
127+
assert!(get(THESEUS_POSTGRESQL_BINARIES_URL).is_ok());
131128
}
132129
}

‎postgresql_archive/src/repository/github/repository.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/repository/github/repository.rs
+6-50Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,6 @@ impl GitHub {
8080
}))
8181
}
8282

83-
/// Determines if the specified URL is supported by the GitHub repository.
84-
///
85-
/// # Errors
86-
/// * If the URL cannot be parsed.
87-
pub fn supports(url: &str) -> bool {
88-
let Ok(parsed_url) = Url::parse(url) else {
89-
return false;
90-
};
91-
let host = parsed_url.host_str().unwrap_or_default();
92-
host.contains("github.com")
93-
}
94-
9583
/// Gets the version from the specified tag name.
9684
///
9785
/// # Errors
@@ -334,22 +322,11 @@ fn reqwest_client() -> ClientWithMiddleware {
334322
#[cfg(test)]
335323
mod tests {
336324
use super::*;
337-
338-
const URL: &str = "https://github.com/theseus-rs/postgresql-binaries";
339-
340-
#[test]
341-
fn test_supports() {
342-
assert!(GitHub::supports(URL));
343-
}
344-
345-
#[test]
346-
fn test_supports_error() {
347-
assert!(!GitHub::supports("https://foo.com"));
348-
}
325+
use crate::THESEUS_POSTGRESQL_BINARIES_URL;
349326

350327
#[test]
351328
fn test_name() {
352-
let github = GitHub::new(URL).unwrap();
329+
let github = GitHub::new(THESEUS_POSTGRESQL_BINARIES_URL).unwrap();
353330
assert_eq!("GitHub", github.name());
354331
}
355332

@@ -379,7 +356,7 @@ mod tests {
379356

380357
#[tokio::test]
381358
async fn test_get_version() -> Result<()> {
382-
let github = GitHub::new(URL)?;
359+
let github = GitHub::new(THESEUS_POSTGRESQL_BINARIES_URL)?;
383360
let version_req = VersionReq::STAR;
384361
let version = github.get_version(&version_req).await?;
385362
assert!(version > Version::new(0, 0, 0));
@@ -388,7 +365,7 @@ mod tests {
388365

389366
#[tokio::test]
390367
async fn test_get_specific_version() -> Result<()> {
391-
let github = GitHub::new(URL)?;
368+
let github = GitHub::new(THESEUS_POSTGRESQL_BINARIES_URL)?;
392369
let version_req = VersionReq::parse("=16.3.0")?;
393370
let version = github.get_version(&version_req).await?;
394371
assert_eq!(Version::new(16, 3, 0), version);
@@ -397,7 +374,7 @@ mod tests {
397374

398375
#[tokio::test]
399376
async fn test_get_specific_not_found() -> Result<()> {
400-
let github = GitHub::new(URL)?;
377+
let github = GitHub::new(THESEUS_POSTGRESQL_BINARIES_URL)?;
401378
let version_req = VersionReq::parse("=0.0.0")?;
402379
let error = github.get_version(&version_req).await.unwrap_err();
403380
assert_eq!("version not found for '=0.0.0'", error.to_string());
@@ -410,7 +387,7 @@ mod tests {
410387

411388
#[tokio::test]
412389
async fn test_get_archive() -> Result<()> {
413-
let github = GitHub::new(URL)?;
390+
let github = GitHub::new(THESEUS_POSTGRESQL_BINARIES_URL)?;
414391
let version_req = VersionReq::parse("=16.3.0")?;
415392
let archive = github.get_archive(&version_req).await?;
416393
assert_eq!(
@@ -436,25 +413,4 @@ mod tests {
436413
assert_eq!(Version::new(0, 12, 0), version);
437414
Ok(())
438415
}
439-
440-
/// Test that a version with a 'v' prefix is correctly parsed; this is a common convention
441-
/// for GitHub releases. Use a known PostgreSQL plugin repository for the test.
442-
#[tokio::test]
443-
async fn test_get_archive_with_v_prefix() -> Result<()> {
444-
let github = GitHub::new("https://github.com/turbot/steampipe-plugin-csv")?;
445-
let version_req = VersionReq::parse("=0.12.0")?;
446-
let archive = github.get_archive(&version_req).await?;
447-
let name = archive.name();
448-
// Note: this plugin repository has 3 artifacts that can match:
449-
// steampipe_export...
450-
// steampipe_postgres...
451-
// steampipe_sqlite...
452-
// custom matchers will be needed to disambiguate plugins
453-
assert!(name.starts_with("steampipe_"));
454-
assert!(name.contains("csv"));
455-
assert!(name.ends_with(".tar.gz"));
456-
assert_eq!(&Version::new(0, 12, 0), archive.version());
457-
assert!(!archive.bytes().is_empty());
458-
Ok(())
459-
}
460416
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.