test: Update version checking tests

This commit is contained in:
Thomas A. Christensen II 2023-12-23 10:49:17 -07:00
parent a0c983c7c0
commit 2920d35b27
Signed by: millironx
GPG key ID: 09335146883990B9

View file

@ -1,37 +1,113 @@
import * as github from "@actions/github"
import { GitHub } from "@actions/github/lib/utils"
import anyTest, { TestFn } from "ava" // eslint-disable-line import/no-unresolved
import test from "ava" // eslint-disable-line import/no-unresolved
import * as functions from "../src/functions"
import { getReleaseTag, getToken } from "./utils"
import { NextflowRelease } from "../src/NextflowRelease"
const test = anyTest as TestFn<{
token: string
octokit: InstanceType<typeof GitHub>
}>
test.before(t => {
const first = true
const current_token = getToken(first)
t.context = {
token: current_token,
octokit: github.getOctokit(current_token)
// 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 = {
versionNumber: version_number,
isEdge: is_edge,
binaryURL: `https://github.com/nextflow-io/nextflow/releases/download/${version_number}/nextflow`,
allBinaryURL: `https://github.com/nextflow-io/nextflow/releases/download/${version_number}/nextflow-${version_number.replace(
"v",
""
)}-all`
}
return release
}
})
test("all_nf_releases", async t => {
const result = await functions.all_nf_releases(t.context["octokit"])
t.is(typeof result, "object")
})
// A mock set of Nextflow releases
const edge_is_newer = [
nf_release_gen("v23.09.1-edge"),
nf_release_gen("v23.04.3"),
nf_release_gen("v23.04.2")
]
const edge_is_older = [
nf_release_gen("v23.04.3"),
nf_release_gen("v23.04.2"),
nf_release_gen("v23.03.0-edge")
]
test("lastest_stable_release_data", async t => {
const result = await functions.latest_stable_release_data(
t.context["octokit"]
/*
The whole reason this action exists is to handle the cases where a final
release is the "bleeding edge" release, rather than the "edge" release, even
though that's what the name would imply. Therefore, we need to test that the
'latest-everything' parameter can find the correct one regardless of whether
an "edge" release or a stable release is the true latest
*/
const release_filter_macro = test.macro(
async (
t,
input_version: string,
expected_version: string,
releases: Array<NextflowRelease>
) => {
const matched_release = await functions.get_nextflow_release(
input_version,
releases
)
t.is(matched_release.versionNumber, expected_version)
}
)
test(
"Latest-everything install with newer edge release",
release_filter_macro,
"latest-everything",
"v23.09.1-edge",
edge_is_newer
)
test(
"Latest-everything install with older edge release",
release_filter_macro,
"latest-everything",
"v23.04.3",
edge_is_older
)
test(
"Latest-edge install with newer edge release",
release_filter_macro,
"latest-edge",
"v23.09.1-edge",
edge_is_newer
)
test(
"Latest-edge install with older edge release",
release_filter_macro,
"latest-edge",
"v23.03.0-edge",
edge_is_older
)
test(
"Latest-stable install with newer edge release",
release_filter_macro,
"latest",
"v23.04.3",
edge_is_newer
)
test(
"Latest-stable install with older edge release",
release_filter_macro,
"latest",
"v23.04.3",
edge_is_older
)
test(
"Fully versioned tag release",
release_filter_macro,
"v23.04.2",
"v23.04.2",
edge_is_newer
)
test(
"Partially versioned tag release",
release_filter_macro,
"v23.04",
"v23.04.3",
edge_is_newer
)
t.is(typeof result, "object")
const expected = await getReleaseTag("nextflow-io/nextflow", false)
t.is(result["tag_name"], expected)
})
test.todo("nextflow_bin_url")
test.todo("install_nextflow")