Skip to content

Commit a1c2c98

Browse files
committed
Integration test local templates as well as remote ones
Signed-off-by: itowlson <[email protected]>
1 parent c1011ac commit a1c2c98

File tree

2 files changed

+52
-32
lines changed

2 files changed

+52
-32
lines changed

tests/integration.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,20 @@ mod integration_tests {
459459
http_smoke_test_template(
460460
"http-rust",
461461
None,
462-
None,
463462
&[],
464463
|_| Ok(()),
465464
HashMap::default(),
466465
"Hello World!",
467-
)
466+
)?;
467+
http_smoke_test_template(
468+
"http-rust",
469+
Some(crate::testcases::TemplateSource::Local),
470+
&[],
471+
|_| Ok(()),
472+
HashMap::default(),
473+
"Hello World!",
474+
)?;
475+
Ok(())
468476
}
469477

470478
#[test]
@@ -603,8 +611,10 @@ mod integration_tests {
603611
]);
604612
http_smoke_test_template(
605613
"http-py",
606-
Some("https://github.com/spinframework/spin-python-sdk"),
607-
Some("v2.0"),
614+
Some(crate::testcases::TemplateSource::Url {
615+
repo: "https://github.com/spinframework/spin-python-sdk",
616+
branch: Some("v2.0"),
617+
}),
608618
&[],
609619
prebuild,
610620
env_vars,
@@ -618,7 +628,6 @@ mod integration_tests {
618628
http_smoke_test_template(
619629
"http-c",
620630
None,
621-
None,
622631
&[],
623632
|_| Ok(()),
624633
HashMap::default(),
@@ -638,7 +647,6 @@ mod integration_tests {
638647
http_smoke_test_template(
639648
"http-go",
640649
None,
641-
None,
642650
&[],
643651
prebuild,
644652
HashMap::default(),
@@ -657,8 +665,10 @@ mod integration_tests {
657665
};
658666
http_smoke_test_template(
659667
"http-js",
660-
Some("https://github.com/spinframework/spin-js-sdk"),
661-
None,
668+
Some(crate::testcases::TemplateSource::Url {
669+
repo: "https://github.com/spinframework/spin-js-sdk",
670+
branch: None,
671+
}),
662672
&[],
663673
prebuild,
664674
HashMap::default(),
@@ -677,8 +687,10 @@ mod integration_tests {
677687
};
678688
http_smoke_test_template(
679689
"http-ts",
680-
Some("https://github.com/spinframework/spin-js-sdk"),
681-
None,
690+
Some(crate::testcases::TemplateSource::Url {
691+
repo: "https://github.com/spinframework/spin-js-sdk",
692+
branch: None,
693+
}),
682694
&[],
683695
prebuild,
684696
HashMap::default(),
@@ -693,7 +705,6 @@ mod integration_tests {
693705
http_smoke_test_template(
694706
"http-grain",
695707
None,
696-
None,
697708
&[],
698709
|_| Ok(()),
699710
HashMap::default(),
@@ -707,7 +718,6 @@ mod integration_tests {
707718
http_smoke_test_template(
708719
"http-zig",
709720
None,
710-
None,
711721
&[],
712722
|_| Ok(()),
713723
HashMap::default(),
@@ -721,7 +731,6 @@ mod integration_tests {
721731
super::testcases::http_smoke_test_template_with_route(
722732
"http-php",
723733
None,
724-
None,
725734
&[],
726735
|_| Ok(()),
727736
HashMap::default(),
@@ -736,7 +745,6 @@ mod integration_tests {
736745
super::testcases::redis_smoke_test_template(
737746
"redis-go",
738747
None,
739-
None,
740748
&[],
741749
|port| {
742750
vec![
@@ -761,7 +769,6 @@ mod integration_tests {
761769
super::testcases::redis_smoke_test_template(
762770
"redis-rust",
763771
None,
764-
None,
765772
&[],
766773
|port| {
767774
vec![
@@ -797,7 +804,6 @@ mod integration_tests {
797804
let mut env = super::testcases::bootstrap_smoke_test(
798805
services,
799806
None,
800-
None,
801807
&[],
802808
"http-rust",
803809
|_| Ok(Vec::new()),

tests/testcases/mod.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ fn preboot(
148148
/// Run a smoke test against a `spin new` http template
149149
pub fn http_smoke_test_template(
150150
template_name: &str,
151-
template_url: Option<&str>,
152-
template_branch: Option<&str>,
151+
template_url: Option<TemplateSource>,
153152
plugins: &[&str],
154153
prebuild_hook: impl FnOnce(&mut TestEnvironment<()>) -> anyhow::Result<()>,
155154
build_env_vars: HashMap<String, String>,
@@ -158,7 +157,6 @@ pub fn http_smoke_test_template(
158157
http_smoke_test_template_with_route(
159158
template_name,
160159
template_url,
161-
template_branch,
162160
plugins,
163161
prebuild_hook,
164162
build_env_vars,
@@ -172,8 +170,7 @@ pub fn http_smoke_test_template(
172170
#[allow(clippy::too_many_arguments)]
173171
pub fn http_smoke_test_template_with_route(
174172
template_name: &str,
175-
template_url: Option<&str>,
176-
template_branch: Option<&str>,
173+
template_url: Option<TemplateSource>,
177174
plugins: &[&str],
178175
prebuild_hook: impl FnOnce(&mut TestEnvironment<()>) -> anyhow::Result<()>,
179176
build_env_vars: HashMap<String, String>,
@@ -183,7 +180,6 @@ pub fn http_smoke_test_template_with_route(
183180
let mut env = bootstrap_smoke_test(
184181
ServicesConfig::none(),
185182
template_url,
186-
template_branch,
187183
plugins,
188184
template_name,
189185
|_| Ok(Vec::new()),
@@ -207,8 +203,7 @@ pub fn http_smoke_test_template_with_route(
207203
#[allow(dependency_on_unit_never_type_fallback)]
208204
pub fn redis_smoke_test_template(
209205
template_name: &str,
210-
template_url: Option<&str>,
211-
template_branch: Option<&str>,
206+
template_url: Option<TemplateSource>,
212207
plugins: &[&str],
213208
new_app_args: impl FnOnce(u16) -> Vec<String>,
214209
prebuild_hook: impl FnOnce(&mut TestEnvironment<()>) -> anyhow::Result<()>,
@@ -217,7 +212,6 @@ pub fn redis_smoke_test_template(
217212
let mut env = bootstrap_smoke_test(
218213
test_environment::services::ServicesConfig::new(vec!["redis"])?,
219214
template_url,
220-
template_branch,
221215
plugins,
222216
template_name,
223217
|env| {
@@ -254,13 +248,20 @@ pub fn redis_smoke_test_template(
254248

255249
static TEMPLATE_MUTEX: std::sync::Mutex<()> = std::sync::Mutex::new(());
256250

251+
pub enum TemplateSource {
252+
Url {
253+
repo: &'static str,
254+
branch: Option<&'static str>,
255+
},
256+
Local,
257+
}
258+
257259
/// Bootstrap a test environment for a smoke test
258260
// TODO: refactor this function to not take so many arguments
259261
#[allow(clippy::too_many_arguments)]
260262
pub fn bootstrap_smoke_test(
261263
services: ServicesConfig,
262-
template_url: Option<&str>,
263-
template_branch: Option<&str>,
264+
template_url: Option<TemplateSource>,
264265
plugins: &[&str],
265266
template_name: &str,
266267
new_app_args: impl FnOnce(&mut TestEnvironment<()>) -> anyhow::Result<Vec<String>>,
@@ -271,12 +272,25 @@ pub fn bootstrap_smoke_test(
271272
) -> anyhow::Result<TestEnvironment<testing_framework::runtimes::spin_cli::SpinCli>> {
272273
let mut env: TestEnvironment<()> = TestEnvironment::boot(services)?;
273274

274-
let template_url = template_url.unwrap_or("https://github.com/spinframework/spin");
275+
let this_dir = std::env::current_dir()?.display().to_string();
276+
277+
let template_source = template_url.unwrap_or(TemplateSource::Url {
278+
repo: "https://github.com/spinframework/spin",
279+
branch: None,
280+
});
281+
let install_loc_args = match template_source {
282+
TemplateSource::Url { repo, branch: None } => &["--git", repo],
283+
TemplateSource::Url {
284+
repo,
285+
branch: Some(br),
286+
} => &["--git", repo, "--branch", br][..],
287+
TemplateSource::Local => &["--dir", &this_dir],
288+
};
289+
275290
let mut template_install = std::process::Command::new(spin_binary());
276-
template_install.args(["templates", "install", "--git", template_url, "--update"]);
277-
if let Some(branch) = template_branch {
278-
template_install.args(["--branch", branch]);
279-
}
291+
template_install.args(["templates", "install", "--update"]);
292+
template_install.args(install_loc_args);
293+
280294
// We need to serialize template installs since they can't be run in parallel
281295
{
282296
let _guard = TEMPLATE_MUTEX.lock().unwrap();

0 commit comments

Comments
 (0)