Skip to content

Commit 6d7b07d

Browse files
ref(tests): Removes network calls from unit tests
We've had several tests for a while that were in unit tests doing things like network calls. All network call tests have been moved to integration tests and some cleanup and refactoring was done as well. I also changed the plugin test to just use a committed wash plugin binary. The code is still in the repo (and updated to use the new wkg fetching), but it added a significant delay because it compiled both `wash` and the plugin. With a committed binary, it becomes much faster Signed-off-by: Taylor Thomas <taylor@cosmonic.com>
1 parent 24789df commit 6d7b07d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1493
-3272
lines changed

.github/workflows/wash.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ concurrency:
2020
env:
2121
CARGO_TERM_COLOR: always
2222
GO_VERSION: '1.23'
23-
TINYGO_VERSION: '0.33.0'
23+
TINYGO_VERSION: '0.34.0'
2424

2525
permissions:
2626
contents: read

crates/wash-cli/tests/wash_build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ async fn integration_build_rust_component_signed_with_signing_keys_directory_con
423423
name = "Hello World"
424424
language = "rust"
425425
type = "component"
426-
426+
427427
[component]
428428
claims = ["wasmcloud:httpserver"]
429429
key_directory = "./haljordankeys"
@@ -576,12 +576,12 @@ async fn integration_build_tinygo_component_unsigned() -> Result<()> {
576576
.context("Failed to build project")?;
577577

578578
assert!(status.success());
579-
let unsigned_file = project_dir.join("build/http-hello-world.wasm");
579+
let unsigned_file = project_dir.join("build/hello-world-tinygo.wasm");
580580
assert!(
581581
tokio::fs::try_exists(unsigned_file).await.unwrap(),
582582
"unsigned file not found!"
583583
);
584-
let signed_file = project_dir.join("build/http_hello_world_s.wasm");
584+
let signed_file = project_dir.join("build/hello_world_tinygo_s.wasm");
585585
assert!(
586586
!tokio::fs::try_exists(signed_file).await.unwrap(),
587587
"signed file should not exist when using --build-only!"
@@ -743,7 +743,7 @@ async fn integration_build_tinygo_component_separate_paths() -> Result<()> {
743743
path = "../"
744744
wit = "../wow"
745745
build = "artifacts"
746-
746+
747747
[component]
748748
wit_world = "hello"
749749
wasm_target = "wasm32-wasip2"

crates/wash-lib/src/app.rs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -513,10 +513,6 @@ mod test {
513513
use anyhow::Result;
514514

515515
#[test]
516-
#[cfg_attr(
517-
not(can_reach_raw_githubusercontent_com),
518-
ignore = "raw.githubusercontent.com is not reachable"
519-
)]
520516
fn test_app_manifest_source_from_str() -> Result<(), Box<dyn std::error::Error>> {
521517
// test stdin
522518
let stdin = AppManifestSource::from_str("-")?;
@@ -595,57 +591,6 @@ mod test {
595591
Ok(())
596592
}
597593

598-
#[tokio::test]
599-
#[cfg_attr(
600-
not(can_reach_raw_githubusercontent_com),
601-
ignore = "raw.githubusercontent.com is not reachable"
602-
)]
603-
async fn test_load_app_manifest() -> Result<()> {
604-
// test stdin
605-
let stdin = AppManifestSource::AsyncReadSource(Box::new(std::io::Cursor::new(
606-
"iam batman!".as_bytes(),
607-
)));
608-
609-
let manifest = load_app_manifest(stdin).await?;
610-
assert!(
611-
matches!(manifest, AppManifest::SerializedModel(manifest) if manifest == "iam batman!"),
612-
"expected AppManifest::SerializedModel('iam batman!')"
613-
);
614-
615-
// create temporary file for this test
616-
let tmp_dir = tempdir()?;
617-
std::fs::write(tmp_dir.path().join("foo.yaml"), "foo")?;
618-
619-
// test file
620-
let file = AppManifestSource::from_str(tmp_dir.path().join("foo.yaml").to_str().unwrap())?;
621-
let manifest = load_app_manifest(file).await?;
622-
assert!(
623-
matches!(manifest, AppManifest::SerializedModel(manifest) if manifest == "foo"),
624-
"expected AppManifest::SerializedModel('foo')"
625-
);
626-
627-
// test url
628-
let url = AppManifestSource::from_str(
629-
"https://raw.githubusercontent.com/wasmCloud/wasmCloud/main/examples/rust/components/http-hello-world/wadm.yaml",
630-
)?;
631-
632-
let manifest = load_app_manifest(url).await?;
633-
assert!(
634-
matches!(manifest, AppManifest::SerializedModel(_)),
635-
"expected AppManifest::SerializedModel(_)"
636-
);
637-
638-
// test model
639-
let model = AppManifestSource::from_str("foo")?;
640-
let manifest = load_app_manifest(model).await?;
641-
assert!(
642-
matches!(manifest, AppManifest::ModelName(name) if name == "foo"),
643-
"expected AppManifest::ModelName('foo')"
644-
);
645-
646-
Ok(())
647-
}
648-
649594
#[tokio::test]
650595
async fn test_resolve_relative_manifest() -> Result<()> {
651596
let tmp_dir = tempdir()?;

crates/wash-lib/src/start/github/api.rs

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ async fn get_chronologically_sorted_releases(
3131
Ok(releases_of_repo)
3232
}
3333

34-
async fn new_patch_releases_of_after(
34+
/// Get a full list of github patch releases that exist after the provided version.
35+
pub async fn new_patch_releases_after(
3536
owner: &str,
3637
repo: &str,
3738
after_version: &Version,
@@ -49,6 +50,7 @@ async fn new_patch_releases_of_after(
4950
Ok(main_releases)
5051
}
5152

53+
/// Returns the latest patch version of the provided version.
5254
pub async fn new_patch_version_of_after_string(
5355
owner: &str,
5456
repo: &str,
@@ -59,7 +61,7 @@ pub async fn new_patch_version_of_after_string(
5961
Ok(v) => v,
6062
Err(_) => return Ok(None),
6163
};
62-
match new_patch_releases_of_after(owner, repo, &after_version).await {
64+
match new_patch_releases_after(owner, repo, &after_version).await {
6365
Ok(patches) => match patches.first() {
6466
Some(patch) => Ok(patch.get_main_artifact_release()),
6567
None => Ok(None),
@@ -297,36 +299,4 @@ mod tests {
297299
let version = release_with_prefix.get_main_artifact_release();
298300
assert!(version.is_none());
299301
}
300-
301-
/// Test if the GitHubRelease struct is parsed correctly from the raw string.
302-
/// Using an already "outdated" patch version to test if the sorting works correctly and comparable to the current version.
303-
#[tokio::test]
304-
#[cfg_attr(not(can_reach_github_com), ignore = "github.com is not reachable")]
305-
async fn test_fetching_wasm_cloud_patch_versions_after_v_1_0_3() {
306-
let owner = &"wasmCloud";
307-
let repo = &"wasmCloud";
308-
let latest_version = semver::Version::new(1, 0, 3);
309-
// Use 1.0.3 as the latest version, since there is a newer version
310-
let releases = get_chronologically_sorted_releases(owner, repo, &latest_version).await;
311-
assert!(releases.is_ok());
312-
let patch_releases = new_patch_releases_of_after(owner, repo, &latest_version).await;
313-
assert!(patch_releases.is_ok());
314-
let patch_releases = patch_releases.unwrap();
315-
for new_path_release in patch_releases {
316-
let version_of_new_release = new_path_release.get_main_artifact_release();
317-
assert!(
318-
version_of_new_release.is_some(),
319-
"new patch version is semver conventional versions"
320-
);
321-
let semver::Version {
322-
major,
323-
minor,
324-
patch,
325-
..
326-
} = version_of_new_release.unwrap();
327-
assert_eq!(latest_version.major, major, "major version is not changed");
328-
assert_eq!(latest_version.minor, minor, "minor version is not changed");
329-
assert!(latest_version.patch < patch, "patch version is bigger");
330-
}
331-
}
332302
}

0 commit comments

Comments
 (0)