Skip to content

Commit e1b54bb

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

File tree

2 files changed

+99
-35
lines changed

2 files changed

+99
-35
lines changed

tests/integration.rs

Lines changed: 69 additions & 19 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,12 +647,20 @@ mod integration_tests {
638647
http_smoke_test_template(
639648
"http-go",
640649
None,
641-
None,
642650
&[],
643651
prebuild,
644652
HashMap::default(),
645653
"Hello World!\n",
646-
)
654+
)?;
655+
http_smoke_test_template(
656+
"http-go",
657+
Some(crate::testcases::TemplateSource::Local),
658+
&[],
659+
prebuild,
660+
HashMap::default(),
661+
"Hello World!\n",
662+
)?;
663+
Ok(())
647664
}
648665

649666
#[test]
@@ -657,8 +674,10 @@ mod integration_tests {
657674
};
658675
http_smoke_test_template(
659676
"http-js",
660-
Some("https://github.com/spinframework/spin-js-sdk"),
661-
None,
677+
Some(crate::testcases::TemplateSource::Url {
678+
repo: "https://github.com/spinframework/spin-js-sdk",
679+
branch: None,
680+
}),
662681
&[],
663682
prebuild,
664683
HashMap::default(),
@@ -677,8 +696,10 @@ mod integration_tests {
677696
};
678697
http_smoke_test_template(
679698
"http-ts",
680-
Some("https://github.com/spinframework/spin-js-sdk"),
681-
None,
699+
Some(crate::testcases::TemplateSource::Url {
700+
repo: "https://github.com/spinframework/spin-js-sdk",
701+
branch: None,
702+
}),
682703
&[],
683704
prebuild,
684705
HashMap::default(),
@@ -693,7 +714,6 @@ mod integration_tests {
693714
http_smoke_test_template(
694715
"http-grain",
695716
None,
696-
None,
697717
&[],
698718
|_| Ok(()),
699719
HashMap::default(),
@@ -707,7 +727,6 @@ mod integration_tests {
707727
http_smoke_test_template(
708728
"http-zig",
709729
None,
710-
None,
711730
&[],
712731
|_| Ok(()),
713732
HashMap::default(),
@@ -721,7 +740,6 @@ mod integration_tests {
721740
super::testcases::http_smoke_test_template_with_route(
722741
"http-php",
723742
None,
724-
None,
725743
&[],
726744
|_| Ok(()),
727745
HashMap::default(),
@@ -736,7 +754,6 @@ mod integration_tests {
736754
super::testcases::redis_smoke_test_template(
737755
"redis-go",
738756
None,
739-
None,
740757
&[],
741758
|port| {
742759
vec![
@@ -752,7 +769,27 @@ mod integration_tests {
752769
env.run_in(&mut tidy)?;
753770
Ok(())
754771
},
755-
)
772+
)?;
773+
super::testcases::redis_smoke_test_template(
774+
"redis-go",
775+
Some(crate::testcases::TemplateSource::Local),
776+
&[],
777+
|port| {
778+
vec![
779+
"--value".into(),
780+
"redis-channel=redis-channel".into(),
781+
"--value".into(),
782+
format!("redis-address=redis://localhost:{port}"),
783+
]
784+
},
785+
|env| {
786+
let mut tidy = std::process::Command::new("go");
787+
tidy.args(["mod", "tidy"]);
788+
env.run_in(&mut tidy)?;
789+
Ok(())
790+
},
791+
)?;
792+
Ok(())
756793
}
757794

758795
#[test]
@@ -761,7 +798,6 @@ mod integration_tests {
761798
super::testcases::redis_smoke_test_template(
762799
"redis-rust",
763800
None,
764-
None,
765801
&[],
766802
|port| {
767803
vec![
@@ -772,7 +808,22 @@ mod integration_tests {
772808
]
773809
},
774810
|_| Ok(()),
775-
)
811+
)?;
812+
super::testcases::redis_smoke_test_template(
813+
"redis-rust",
814+
Some(crate::testcases::TemplateSource::Local),
815+
&[],
816+
|port| {
817+
vec![
818+
"--value".into(),
819+
"redis-channel=redis-channel".into(),
820+
"--value".into(),
821+
format!("redis-address=redis://localhost:{port}"),
822+
]
823+
},
824+
|_| Ok(()),
825+
)?;
826+
Ok(())
776827
}
777828

778829
#[test]
@@ -797,7 +848,6 @@ mod integration_tests {
797848
let mut env = super::testcases::bootstrap_smoke_test(
798849
services,
799850
None,
800-
None,
801851
&[],
802852
"http-rust",
803853
|_| 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)