From 9dfa0f4329895ac8e6e3174bed3ace391415ef06 Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Fri, 2 Feb 2024 20:30:38 -0600 Subject: [PATCH] test: Add tests for Nextflow release version resolver --- test/functions.ts | 95 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 test/functions.ts diff --git a/test/functions.ts b/test/functions.ts new file mode 100644 index 0000000..fa9aaf7 --- /dev/null +++ b/test/functions.ts @@ -0,0 +1,95 @@ +import test from "ava" + +import { get_nextflow_release } from "../src/functions" +import { NextflowRelease } from "../src/nextflow-release" + +// The Nextflow releases we are going to use for testing follow a regular +// pattern: create a mock function to bootstrap some test data without repeating +// ourselves +function nf_release_gen(version_number: string): NextflowRelease { + const is_edge = version_number.endsWith("-edge") + const release: NextflowRelease = { + version: version_number, + isEdge: is_edge, + downloadUrl: `https://github.com/nextflow-io/nextflow/releases/download/${version_number}/nextflow`, + downloadUrlAll: `https://github.com/nextflow-io/nextflow/releases/download/${version_number}/nextflow-${version_number.replace( + "v", + "" + )}-all` + } + return release +} + +const release_test_macro = test.macro( + async ( + t, + input_version: string, + expected_version: string, + is_edge_older: Boolean + ) => { + const releases_set = [ + nf_release_gen("v21.05.1-edge"), + nf_release_gen("v21.05.0-edge"), + nf_release_gen("v21.04.2"), + nf_release_gen("v21.04.1"), + nf_release_gen("v21.04.0"), + nf_release_gen("v21.03.0-edge") + ] + const release_filtered = releases_set.splice(is_edge_older ? 2 : 0) + const matched_release = await get_nextflow_release( + input_version, + release_filtered + ) + t.is(matched_release.version, expected_version) + } +) + +test( + "Major and minor version only (edge newer)", + release_test_macro, + "v21.04", + "v21.04.2", + false +) +test( + "Major and minor version only (edge older)", + release_test_macro, + "v21.04", + "v21.04.2", + true +) +test( + "Major, minor, and patch version: latest patch (edge newer)", + release_test_macro, + "v21.04.2", + "v21.04.2", + false +) +test( + "Major, minor, and patch version: latest patch (edge older)", + release_test_macro, + "v21.04.2", + "v21.04.2", + true +) +test( + "Major, minor, and patch version: older patch (edge newer)", + release_test_macro, + "v21.04.1", + "v21.04.1", + false +) +test( + "Major, minor, and patch version: older patch (edge older)", + release_test_macro, + "v21.04.1", + "v21.04.1", + true +) +test( + "Edge release", + release_test_macro, + "v21.03.0-edge", + "v21.03.0-edge", + false +)