Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace tempdir with tempfile #2760

Merged
merged 3 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 14 additions & 66 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/factor-key-value/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spin-factors-test = { path = "../factors-test" }
tokio = { version = "1", features = ["macros", "rt"] }
spin-factor-key-value-spin = { path = "../factor-key-value-spin" }
spin-factor-key-value-redis = { path = "../factor-key-value-redis" }
tempdir = "0.3"
tempfile = "3.12.0"


[lints]
Expand Down
8 changes: 4 additions & 4 deletions crates/factor-key-value/tests/factor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async fn custom_spin_key_value_works() -> anyhow::Result<()> {

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn custom_spin_key_value_works_with_absolute_path() -> anyhow::Result<()> {
let tmp_dir = tempdir::TempDir::new("example")?;
let tmp_dir = tempfile::TempDir::with_prefix("example")?;
let db_path = tmp_dir.path().join("foo/custom.db");
// Check that the db does not exist yet - it will exist by the end of the test
assert!(!db_path.exists());
Expand Down Expand Up @@ -132,7 +132,7 @@ async fn custom_spin_key_value_works_with_absolute_path() -> anyhow::Result<()>

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn custom_spin_key_value_works_with_relative_path() -> anyhow::Result<()> {
let tmp_dir = tempdir::TempDir::new("example")?;
let tmp_dir = tempfile::TempDir::with_prefix("example")?;
let db_path = tmp_dir.path().join("custom.db");
// Check that the db does not exist yet - it will exist by the end of the test
assert!(!db_path.exists());
Expand Down Expand Up @@ -176,7 +176,7 @@ async fn custom_redis_key_value_works() -> anyhow::Result<()> {

#[tokio::test]
async fn misconfigured_spin_key_value_fails() -> anyhow::Result<()> {
let tmp_dir = tempdir::TempDir::new("example")?;
let tmp_dir = tempfile::TempDir::with_prefix("example")?;
let runtime_config = toml::toml! {
[key_value_store.custom]
type = "spin"
Expand All @@ -198,7 +198,7 @@ async fn misconfigured_spin_key_value_fails() -> anyhow::Result<()> {
// TODO(rylev): consider removing this test as it is really only a consequence of
// toml deserialization and not a feature of the key-value store.
async fn multiple_custom_key_value_uses_second_store() -> anyhow::Result<()> {
let tmp_dir = tempdir::TempDir::new("example")?;
let tmp_dir = tempfile::TempDir::with_prefix("example")?;
let db_path = tmp_dir.path().join("custom.db");
// Check that the db does not exist yet - it will exist by the end of the test
assert!(!db_path.exists());
Expand Down
2 changes: 1 addition & 1 deletion crates/trigger/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl<T: Trigger> TriggerAppBuilder<T> {
let use_gpu = true;
let state_dir = match options.state_dir {
// Make sure `--state-dir=""` unsets the state dir
Some(s) if s.trim().is_empty() => None,
Some("") => None,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sneaky lint fix...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't equivalent, no? Some(" ") would match the first but not the second.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry I blindly obeyed clippy. That said, --state-dir " " seems more likely to be an accident...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though it now occurs to me that its perfectly valid to create a directory named " "...

Some(s) => Some(PathBuf::from(s)),
// Default to `.spin/` in the local app dir
None => options.local_app_dir.map(|d| Path::new(d).join(".spin")),
Expand Down
5 changes: 1 addition & 4 deletions crates/trigger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ pub trait Trigger: Sized + Send {
}

/// Run this trigger.
fn run(
self,
trigger_app: TriggerApp<Self>,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn run(self, trigger_app: TriggerApp<Self>) -> impl Future<Output = anyhow::Result<()>> + Send;
Copy link
Collaborator Author

@lann lann Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sneaky unrelated rustfmts 🕵️


/// Returns a list of host requirements supported by this trigger specifically.
///
Expand Down
9 changes: 0 additions & 9 deletions examples/spin-timer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,7 @@ Caused by:
)
};
ensure_success("/hello", 200, "I'm a teapot")?;
ensure_success(
"/hello/wildcards/should/be/handled",
200,
"I'm a teapot",
)?;
ensure_success("/hello/wildcards/should/be/handled", 200, "I'm a teapot")?;
ensure_success("/thisshouldfail", 404, "")?;
ensure_success("/hello/test-placement", 200, "text for test")?;
Ok(())
Expand Down