Skip to content

Commit a39d90d

Browse files
committed
test: added end-to-end test using S3Mock in a container
1 parent 0b162b7 commit a39d90d

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/aws.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ pub(crate) async fn upload_file(archive: Archive, params: &Params) -> Result<()>
3030
env::set_var("AWS_ACCESS_KEY_ID", &params.aws_key_id);
3131
env::set_var("AWS_SECRET_ACCESS_KEY", &params.aws_key);
3232
let mut shared_config_builder = aws_config::from_env().region(params.aws_region.region().await);
33-
if cfg!(test) {
34-
shared_config_builder = shared_config_builder.endpoint_url("http://localhost:9090")
33+
// we set this special environment variable when doing e2e testing
34+
if env::var("AWSBCK_TESTING_E2E").is_ok() {
35+
warn!("Endpoint URL was changed to localhost while in testing environment.");
36+
shared_config_builder = shared_config_builder.endpoint_url("http://127.0.0.1:9090")
3537
}
3638
let shared_config = shared_config_builder.load().await;
3739
let client = Client::new(&shared_config);

tests/e2e_test.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{path::PathBuf, process::Command};
1+
use std::{collections::HashMap, path::PathBuf, process::Command};
22

33
use dockertest::{
44
waitfor::{MessageSource, MessageWait},
@@ -8,25 +8,29 @@ use dockertest::{
88
#[test]
99
fn e2e_test() {
1010
let mut test = DockerTest::new().with_default_source(Source::DockerHub);
11+
let mut container_env = HashMap::new();
12+
container_env.insert("initialBuckets".to_string(), "foo".to_string());
1113
let mut aws = Composition::with_repository("adobe/s3mock")
1214
.with_container_name("aws")
1315
.with_wait_for(Box::new(MessageWait {
1416
message: "Started S3MockApplication".to_string(),
1517
source: MessageSource::Stdout,
1618
timeout: 10,
17-
}));
18-
aws.port_map(9090, 9090);
19+
}))
20+
.with_env(container_env);
21+
aws.port_map(9090, 9090).port_map(9191, 9191);
1922
test.add_composition(aws);
2023

2124
test.run(|ops| async move {
2225
let _container = ops.handle("aws");
2326
let path = PathBuf::from(env!("CARGO_BIN_EXE_awsbck"));
2427
let output = Command::new(path)
28+
.env("AWSBCK_TESTING_E2E", "1")
2529
.args(["-b", "foo", "--id", "bar", "-k", "baz"])
2630
.arg("./src")
2731
.output()
2832
.expect("Failed to execute command");
29-
println!("{}", String::from_utf8_lossy(&output.stderr));
3033
assert!(output.status.success());
34+
assert!(String::from_utf8_lossy(&output.stderr).contains("Backup succeeded"));
3135
});
3236
}

0 commit comments

Comments
 (0)