Skip to content

Commit 38df8e3

Browse files
committed
Respect CARGO_TARGET_DIR in integration tests
Signed-off-by: Ryan Levick <[email protected]>
1 parent 12becdc commit 38df8e3

File tree

1 file changed

+45
-18
lines changed

1 file changed

+45
-18
lines changed

tests/integration.rs

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,19 @@ mod integration_tests {
2828

2929
const DEFAULT_MANIFEST_LOCATION: &str = "spin.toml";
3030

31-
const SPIN_BINARY: &str = "./target/debug/spin";
31+
fn spin_binary() -> String {
32+
format!("{}/debug/spin", target_dir())
33+
}
34+
35+
fn target_dir() -> String {
36+
match std::env::var_os("CARGO_TARGET_DIR") {
37+
Some(d) => d
38+
.to_str()
39+
.expect("CARGO_TARGET_DIR is not utf-8")
40+
.to_owned(),
41+
None => "./target".into(),
42+
}
43+
}
3244

3345
#[cfg(feature = "outbound-redis-tests")]
3446
mod outbound_redis_tests {
@@ -87,7 +99,10 @@ mod integration_tests {
8799
assert!(Command::new("cargo")
88100
.arg("build")
89101
.arg("--release")
90-
.current_dir(trigger_dir)
102+
.arg("--target-dir")
103+
.arg(trigger_dir.join("target"))
104+
.arg("--manifest-path")
105+
.arg(trigger_dir.join("Cargo.toml"))
91106
.status()?
92107
.success());
93108

@@ -100,27 +115,33 @@ mod integration_tests {
100115
fs::copy(
101116
trigger_dir.join("target/release/trigger-timer"),
102117
plugin_dir.join("trigger-timer"),
103-
)?;
118+
)
119+
.context("could not copy plugin binary into plugin directory")?;
104120

105121
let manifests_dir = plugins_dir.join("manifests");
106122
fs::create_dir_all(&manifests_dir)?;
107123
// Note that the hash and path in the manifest aren't accurate, but they won't be used anyway for this
108-
// test. We just need something that parses without throwing errors here.
124+
// test. We just need something that parses without throwing errors here.
109125
fs::copy(
110126
Path::new(TIMER_TRIGGER_DIRECTORY).join("trigger-timer.json"),
111127
manifests_dir.join("trigger-timer.json"),
112-
)?;
128+
)
129+
.context("could not copy plugin manifest into manifests directory")?;
113130

114-
assert!(Command::new(get_process(SPIN_BINARY))
131+
let out = Command::new(get_process(&spin_binary()))
115132
.args([
116133
"up",
117134
"--file",
118135
&format!("{TIMER_TRIGGER_INTEGRATION_TEST}/{DEFAULT_MANIFEST_LOCATION}"),
119136
"--test",
120137
])
121138
.env("TEST_PLUGINS_DIRECTORY", plugin_store_dir)
122-
.status()?
123-
.success());
139+
.output()?;
140+
assert!(
141+
out.status.success(),
142+
"Running `spin up` returned error: {}",
143+
String::from_utf8_lossy(&out.stderr)
144+
);
124145

125146
Ok(())
126147
}
@@ -279,7 +300,7 @@ mod integration_tests {
279300
args.push(v);
280301
}
281302

282-
let mut spin_handle = Command::new(get_process(SPIN_BINARY))
303+
let mut spin_handle = Command::new(get_process(&spin_binary()))
283304
.args(args)
284305
.env(
285306
"RUST_LOG",
@@ -289,7 +310,7 @@ mod integration_tests {
289310
.with_context(|| "executing Spin")?;
290311

291312
// ensure the server is accepting requests before continuing.
292-
wait_tcp(&url, &mut spin_handle, SPIN_BINARY).await?;
313+
wait_tcp(&url, &mut spin_handle, &spin_binary()).await?;
293314

294315
Ok(SpinTestController { url, spin_handle })
295316
}
@@ -351,7 +372,7 @@ mod integration_tests {
351372
if cfg!(target_os = "windows") {
352373
format!("{}.exe", binary)
353374
} else {
354-
binary.to_string()
375+
binary.to_owned()
355376
}
356377
}
357378

@@ -432,7 +453,7 @@ mod integration_tests {
432453

433454
run(
434455
vec![
435-
SPIN_BINARY,
456+
spin_binary().as_str(),
436457
"build",
437458
"--file",
438459
manifest_file.to_str().unwrap(),
@@ -479,8 +500,9 @@ route = "/..."
479500
std::fs::write(&manifest_file, toml_text)?;
480501
std::fs::write(dir.join("fake.wasm"), "")?;
481502

503+
let binary = spin_binary();
482504
let up_help_args = vec![
483-
SPIN_BINARY,
505+
&binary,
484506
"up",
485507
"--file",
486508
manifest_file.to_str().unwrap(),
@@ -553,8 +575,9 @@ route = "/..."
553575
)?;
554576

555577
// Install plugin
578+
let binary = spin_binary();
556579
let install_args = vec![
557-
SPIN_BINARY,
580+
&binary,
558581
"plugins",
559582
"install",
560583
"--file",
@@ -564,7 +587,8 @@ route = "/..."
564587
run(install_args, None, Some(env_map.clone()))?;
565588

566589
// Execute example plugin which writes "This is an example Spin plugin!" to a specified file
567-
let execute_args = vec![SPIN_BINARY, "example"];
590+
let binary = spin_binary();
591+
let execute_args = vec![&binary, "example"];
568592
let output = run(execute_args, None, Some(env_map.clone()))?;
569593

570594
// Verify plugin successfully wrote to output file
@@ -579,8 +603,9 @@ route = "/..."
579603
dir.join("example-plugin-manifest.json"),
580604
serde_json::to_string(&plugin_manifest_json).unwrap(),
581605
)?;
606+
let binary = spin_binary();
582607
let upgrade_args = vec![
583-
SPIN_BINARY,
608+
&binary,
584609
"plugins",
585610
"upgrade",
586611
"example",
@@ -602,7 +627,8 @@ route = "/..."
602627
assert!(manifest.contains("0.2.1"));
603628

604629
// Uninstall plugin
605-
let uninstall_args = vec![SPIN_BINARY, "plugins", "uninstall", "example"];
630+
let binary = spin_binary();
631+
let uninstall_args = vec![&binary, "plugins", "uninstall", "example"];
606632
run(uninstall_args, None, None)?;
607633
Ok(())
608634
}
@@ -624,7 +650,8 @@ route = "/..."
624650
);
625651

626652
// `spin login --help` should cause the `cloud` plugin to be installed
627-
let args = vec![SPIN_BINARY, "login", "--help"];
653+
let spin_binary = spin_binary();
654+
let args = vec![&spin_binary, "login", "--help"];
628655

629656
// Execute example plugin which writes "This is an example Spin plugin!" to a specified file
630657
let output = run(args, None, Some(env_map.clone()))?;

0 commit comments

Comments
 (0)