Skip to content

Commit

Permalink
fix gcs tests (#514)
Browse files Browse the repository at this point in the history
This PR re-enables the GCS tests. By pinning to an older version of the
fsouza/fake-gcs-server, which [stopped
supporting](fsouza/fake-gcs-server#1017) files
ending with / in
[v1.43.0](https://github.com/fsouza/fake-gcs-server/releases/tag/v1.43.0)

We should replace this docker-dependent setup with something more
robust.

Also reintroducing root_dir setting, which serves as a regression test
for #508
  • Loading branch information
robklg authored Dec 16, 2024
1 parent 5a30f84 commit c356cb2
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions crates/unftp-sbe-gcs/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ lazy_static! {

// FIXME: auto-allocate port
const ADDR: &str = "127.0.0.1:1234";
const ADDR_WITHOUT_ROOT: &str = "127.0.0.1:4321";
const GCS_BASE_URL: &str = "http://localhost:9081";
const GCS_BUCKET: &str = "test-bucket";

Expand All @@ -38,7 +39,7 @@ pub fn initialize_docker() -> Mutex<Child> {

Command::new("mkdir")
.arg("-p")
.arg(format!("{}/tests/resources/data/{}", current_dir, GCS_BUCKET))
.arg(format!("{}/tests/resources/data/{}/unftp", current_dir, GCS_BUCKET))
.status()
.unwrap();
Command::new("docker").arg("stop").arg("fake-gcs").status().unwrap();
Expand All @@ -53,7 +54,7 @@ pub fn initialize_docker() -> Mutex<Child> {
.arg(format!("{}/tests/resources/data:/data", current_dir))
.arg("-p")
.arg("9081:9081")
.arg("fsouza/fake-gcs-server")
.arg("fsouza/fake-gcs-server:1.42.2")
.arg("-scheme")
.arg("http")
.arg("-port")
Expand All @@ -69,13 +70,11 @@ pub fn initialize_docker() -> Mutex<Child> {
#[tokio::test(flavor = "current_thread")]
async fn root_dir_regression() {
run_test(async {
let mut ftp_stream = FtpStream::connect(ADDR).await.unwrap();
let mut ftp_stream = FtpStream::connect(ADDR_WITHOUT_ROOT).await.unwrap();
ftp_stream.login("anonymous", "").await.unwrap();
ftp_stream.mkdir("some_directory").await.unwrap();

// fake-gcs-server doesn't respond the same way as actual GCS for "prefix=/"
// So we cannot test this case here
//ftp_stream.cwd("/").await.unwrap();
ftp_stream.cwd("/").await.unwrap();

let content = b"Hello from this test!\n";
let mut reader = Cursor::new(content);
Expand Down Expand Up @@ -279,18 +278,34 @@ async fn run_test(test: impl Future<Output = ()>) {

tokio::spawn(
ServerBuilder::new(Box::new(move || {
CloudStorage::with_api_base(GCS_BASE_URL, GCS_BUCKET, PathBuf::from("/"), AuthMethod::None)
CloudStorage::with_api_base(GCS_BASE_URL, GCS_BUCKET, PathBuf::from("/unftp"), AuthMethod::None)
}))
.logger(Some(Logger::root(drain, o!())))
.build()
.unwrap()
.listen(ADDR),
);

let decorator2 = slog_term::TermDecorator::new().stderr().build();
let drain2 = slog_term::FullFormat::new(decorator2).build().fuse();
let drain2 = slog_async::Async::new(drain2).build().fuse();

tokio::spawn(
ServerBuilder::new(Box::new(move || {
CloudStorage::with_api_base(GCS_BASE_URL, GCS_BUCKET, PathBuf::from("/"), AuthMethod::None)
}))
.logger(Some(Logger::root(drain2, o!())))
.build()
.unwrap()
.listen(ADDR_WITHOUT_ROOT),
);

tokio::time::sleep(Duration::new(1, 0)).await;

test.await;

tokio::time::sleep(Duration::new(1, 0)).await;

let mut stdout = String::new();
let mut stderr = String::new();

Expand Down

0 comments on commit c356cb2

Please sign in to comment.