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

fix: static folder local run clearing file contents, add missing tests in cargo-shuttle #717

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
59 changes: 59 additions & 0 deletions cargo-shuttle/tests/integration/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,65 @@ async fn rocket_postgres() {
assert_eq!(request_text, "{\"id\":1,\"note\":\"Deploy to shuttle\"}");
}

#[tokio::test(flavor = "multi_thread")]
async fn axum_static_files() {
let url = cargo_shuttle_run("../examples/axum/static-files", false).await;
let client = reqwest::Client::new();

let request_text = client
.get(format!("{url}/hello"))
.send()
.await
.unwrap()
.text()
.await
.unwrap();

assert_eq!(request_text, "Hello, world!");

let request_text = client
.get(format!("{url}"))
.send()
.await
.unwrap()
.text()
.await
.unwrap();

assert!(
request_text.contains("This is an example of serving static files with axum and shuttle.")
);
}

#[tokio::test(flavor = "multi_thread")]
async fn shuttle_next() {
let url = cargo_shuttle_run("../examples/next/hello-world", false).await;
let client = reqwest::Client::new();

let request_text = client
.get(format!("{url}/hello"))
.send()
.await
.unwrap()
.text()
.await
.unwrap();

assert_eq!(request_text, "Hello, World!");

let post_text = client
.post(format!("{url}/uppercase"))
.body("uppercase this")
.send()
.await
.unwrap()
.text()
.await
.unwrap();

assert_eq!(post_text, "UPPERCASE THIS");
oddgrd marked this conversation as resolved.
Show resolved Hide resolved
}

#[tokio::test(flavor = "multi_thread")]
#[ignore]
async fn rocket_authentication() {
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/shuttle_main/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl ToTokens for Loader {
None
} else {
Some(parse_quote!(
use shuttle_runtime::ResourceBuilder;
use shuttle_runtime::{Factory, ResourceBuilder};
))
};

Expand Down
4 changes: 4 additions & 0 deletions resources/static-folder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ impl<'a> ResourceBuilder<PathBuf> for StaticFolder<'a> {

trace!(output_directory = ?output_dir, "got output directory");

if output_dir.join(self.folder) == input_dir {
return Ok(output_dir.join(self.folder));
}

let copy_options = CopyOptions::new().overwrite(true);
match copy(&input_dir, &output_dir, &copy_options) {
Ok(_) => Ok(output_dir.join(self.folder)),
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub use logger::Logger;
pub use next::{AxumWasm, NextArgs};
pub use provisioner_factory::ProvisionerFactory;
pub use shuttle_common::storage_manager::StorageManager;
pub use shuttle_service::{main, CustomError, Error, ResourceBuilder, Service};
pub use shuttle_service::{main, CustomError, Error, Factory, ResourceBuilder, Service};

// Dependencies required by the codegen
pub use anyhow::Context;
Expand Down