Skip to content

Commit 969720f

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

File tree

2 files changed

+103
-31
lines changed

2 files changed

+103
-31
lines changed

tests/integration.rs

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,22 @@ mod integration_tests {
459459
http_smoke_test_template(
460460
"http-rust",
461461
None,
462-
None,
463462
&[],
464463
|_| Ok(()),
465464
HashMap::default(),
466465
"Hello World!",
467466
)
467+
.context("template on main")?;
468+
http_smoke_test_template(
469+
"http-rust",
470+
Some(crate::testcases::TemplateSource::Local),
471+
&[],
472+
|_| Ok(()),
473+
HashMap::default(),
474+
"Hello World!",
475+
)
476+
.context("local template")?;
477+
Ok(())
468478
}
469479

470480
#[test]
@@ -603,8 +613,10 @@ mod integration_tests {
603613
]);
604614
http_smoke_test_template(
605615
"http-py",
606-
Some("https://github.com/spinframework/spin-python-sdk"),
607-
Some("v2.0"),
616+
Some(crate::testcases::TemplateSource::Url {
617+
repo: "https://github.com/spinframework/spin-python-sdk",
618+
branch: Some("v2.0"),
619+
}),
608620
&[],
609621
prebuild,
610622
env_vars,
@@ -618,7 +630,6 @@ mod integration_tests {
618630
http_smoke_test_template(
619631
"http-c",
620632
None,
621-
None,
622633
&[],
623634
|_| Ok(()),
624635
HashMap::default(),
@@ -638,12 +649,22 @@ mod integration_tests {
638649
http_smoke_test_template(
639650
"http-go",
640651
None,
641-
None,
642652
&[],
643653
prebuild,
644654
HashMap::default(),
645655
"Hello World!\n",
646656
)
657+
.context("template on main")?;
658+
http_smoke_test_template(
659+
"http-go",
660+
Some(crate::testcases::TemplateSource::Local),
661+
&[],
662+
prebuild,
663+
HashMap::default(),
664+
"Hello World!\n",
665+
)
666+
.context("local template")?;
667+
Ok(())
647668
}
648669

649670
#[test]
@@ -657,8 +678,10 @@ mod integration_tests {
657678
};
658679
http_smoke_test_template(
659680
"http-js",
660-
Some("https://github.com/spinframework/spin-js-sdk"),
661-
None,
681+
Some(crate::testcases::TemplateSource::Url {
682+
repo: "https://github.com/spinframework/spin-js-sdk",
683+
branch: None,
684+
}),
662685
&[],
663686
prebuild,
664687
HashMap::default(),
@@ -677,8 +700,10 @@ mod integration_tests {
677700
};
678701
http_smoke_test_template(
679702
"http-ts",
680-
Some("https://github.com/spinframework/spin-js-sdk"),
681-
None,
703+
Some(crate::testcases::TemplateSource::Url {
704+
repo: "https://github.com/spinframework/spin-js-sdk",
705+
branch: None,
706+
}),
682707
&[],
683708
prebuild,
684709
HashMap::default(),
@@ -693,7 +718,6 @@ mod integration_tests {
693718
http_smoke_test_template(
694719
"http-grain",
695720
None,
696-
None,
697721
&[],
698722
|_| Ok(()),
699723
HashMap::default(),
@@ -707,7 +731,6 @@ mod integration_tests {
707731
http_smoke_test_template(
708732
"http-zig",
709733
None,
710-
None,
711734
&[],
712735
|_| Ok(()),
713736
HashMap::default(),
@@ -721,7 +744,6 @@ mod integration_tests {
721744
super::testcases::http_smoke_test_template_with_route(
722745
"http-php",
723746
None,
724-
None,
725747
&[],
726748
|_| Ok(()),
727749
HashMap::default(),
@@ -736,7 +758,6 @@ mod integration_tests {
736758
super::testcases::redis_smoke_test_template(
737759
"redis-go",
738760
None,
739-
None,
740761
&[],
741762
|port| {
742763
vec![
@@ -753,6 +774,28 @@ mod integration_tests {
753774
Ok(())
754775
},
755776
)
777+
.context("template on main")?;
778+
super::testcases::redis_smoke_test_template(
779+
"redis-go",
780+
Some(crate::testcases::TemplateSource::Local),
781+
&[],
782+
|port| {
783+
vec![
784+
"--value".into(),
785+
"redis-channel=redis-channel".into(),
786+
"--value".into(),
787+
format!("redis-address=redis://localhost:{port}"),
788+
]
789+
},
790+
|env| {
791+
let mut tidy = std::process::Command::new("go");
792+
tidy.args(["mod", "tidy"]);
793+
env.run_in(&mut tidy)?;
794+
Ok(())
795+
},
796+
)
797+
.context("local template")?;
798+
Ok(())
756799
}
757800

758801
#[test]
@@ -761,7 +804,6 @@ mod integration_tests {
761804
super::testcases::redis_smoke_test_template(
762805
"redis-rust",
763806
None,
764-
None,
765807
&[],
766808
|port| {
767809
vec![
@@ -773,6 +815,23 @@ mod integration_tests {
773815
},
774816
|_| Ok(()),
775817
)
818+
.context("template on main")?;
819+
super::testcases::redis_smoke_test_template(
820+
"redis-rust",
821+
Some(crate::testcases::TemplateSource::Local),
822+
&[],
823+
|port| {
824+
vec![
825+
"--value".into(),
826+
"redis-channel=redis-channel".into(),
827+
"--value".into(),
828+
format!("redis-address=redis://localhost:{port}"),
829+
]
830+
},
831+
|_| Ok(()),
832+
)
833+
.context("local template")?;
834+
Ok(())
776835
}
777836

778837
#[test]
@@ -797,7 +856,6 @@ mod integration_tests {
797856
let mut env = super::testcases::bootstrap_smoke_test(
798857
services,
799858
None,
800-
None,
801859
&[],
802860
"http-rust",
803861
|_| 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)