|
| 1 | +#!/usr/bin/env npx tsx |
| 2 | + |
| 3 | +/* |
| 4 | +Tests for the release-branches.ts script |
| 5 | +*/ |
| 6 | + |
| 7 | +import * as assert from "node:assert/strict"; |
| 8 | +import { describe, it } from "node:test"; |
| 9 | + |
| 10 | +import { computeBackportBranches } from "./release-branches"; |
| 11 | + |
| 12 | +describe("computeBackportBranches", async () => { |
| 13 | + await it("rejects invalid major versions", () => { |
| 14 | + // The majorVersion is expected to be in vN format. |
| 15 | + assert.throws(() => computeBackportBranches("3", "v4.28.0", 3)); |
| 16 | + assert.throws(() => computeBackportBranches("v3.1", "v4.28.0", 3)); |
| 17 | + }); |
| 18 | + |
| 19 | + await it("rejects invalid latest tags", () => { |
| 20 | + // The latestTag is expected to be in vN.M.P format. |
| 21 | + assert.throws(() => computeBackportBranches("v3", "v4", 3)); |
| 22 | + assert.throws(() => computeBackportBranches("v3", "4", 3)); |
| 23 | + assert.throws(() => computeBackportBranches("v3", "v4.28", 3)); |
| 24 | + assert.throws(() => computeBackportBranches("v3", "4.28", 3)); |
| 25 | + assert.throws(() => computeBackportBranches("v3", "4.28.0", 3)); |
| 26 | + }); |
| 27 | + |
| 28 | + await it("sets backport source branch based on major version", () => { |
| 29 | + // Test that the backport source branch is releases/v{majorVersion} |
| 30 | + const result = computeBackportBranches("v3", "v4.28.0", 3); |
| 31 | + assert.equal(result.backportSourceBranch, "releases/v3"); |
| 32 | + }); |
| 33 | + |
| 34 | + await it("no backport targets when major version is the oldest supported", () => { |
| 35 | + // When majorVersion equals the major version of latestTag and we do not support older major versions, |
| 36 | + // then there are no older supported branches to backport to. |
| 37 | + const result = computeBackportBranches("v3", "v3.28.0", 3); |
| 38 | + assert.deepEqual(result.backportTargetBranches, []); |
| 39 | + }); |
| 40 | + |
| 41 | + await it("backports to older supported major versions", () => { |
| 42 | + const result = computeBackportBranches("v4", "v4.1.0", 3); |
| 43 | + assert.equal(result.backportSourceBranch, "releases/v4"); |
| 44 | + assert.deepEqual(result.backportTargetBranches, ["releases/v3"]); |
| 45 | + }); |
| 46 | + |
| 47 | + await it("backports to multiple older supported branches", () => { |
| 48 | + const result = computeBackportBranches("v5", "v5.0.0", 3); |
| 49 | + assert.equal(result.backportSourceBranch, "releases/v5"); |
| 50 | + assert.deepEqual(result.backportTargetBranches, [ |
| 51 | + "releases/v4", |
| 52 | + "releases/v3", |
| 53 | + ]); |
| 54 | + }); |
| 55 | + |
| 56 | + await it("does not backport when major version is older than latest tag", () => { |
| 57 | + const result = computeBackportBranches("v2", "v3.28.0", 2); |
| 58 | + assert.equal(result.backportSourceBranch, "releases/v2"); |
| 59 | + assert.deepEqual(result.backportTargetBranches, []); |
| 60 | + }); |
| 61 | +}); |
0 commit comments