Skip to content

Commit

Permalink
Eliminate '.dev' in version comparison for takeover action
Browse files Browse the repository at this point in the history
This variant may be appended by balena-proxy.

Change-type: patch
Signed-off-by: Ken Bannister <[email protected]>
  • Loading branch information
kb2ma committed Dec 13, 2024
1 parent a496285 commit 8ec3ba5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
5 changes: 4 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,11 @@ export class HUPActionHelper {
}

if (actionName === 'balenahup' && minTakeoverVersion != null) {
const noDevVersion = currentVersion.endsWith('.dev')
? currentVersion.substring(0, currentVersion.length - 4)
: currentVersion;
if (
bSemver.lt(currentVersion, minTakeoverVersion) &&
bSemver.lt(noDevVersion, minTakeoverVersion) &&
bSemver.gte(targetVersion, minTakeoverVersion)
) {
return 'takeover';
Expand Down
44 changes: 27 additions & 17 deletions tests/01-actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,27 +737,37 @@ describe('BalenaHupActionUtils', () => {
before: '6.0.0',
cutoff: '6.0.38',
takeover: '6.0.39',
// pre-unification version for dev mode device when called by balena-proxy
takeoverDev: '6.0.39.dev',
after: '6.1.0',
},
].forEach(({ deviceType, before, cutoff, takeover, after }) => {
it(`should return 'balenahup' if doing HUP for ${deviceType} to a version before ${takeover}`, () => {
expect(
hupActionHelper.getHUPActionType(deviceType, before, cutoff),
).to.equal('balenahup');
});
].forEach(
({ deviceType, before, cutoff, takeover, takeoverDev, after }) => {
it(`should return 'balenahup' if doing HUP for ${deviceType} to a version before ${takeover}`, () => {
expect(
hupActionHelper.getHUPActionType(deviceType, before, cutoff),
).to.equal('balenahup');
});

it(`should return 'takeover' if doing HUP for ${deviceType} to a version after ${takeover}`, () => {
expect(
hupActionHelper.getHUPActionType(deviceType, before, after),
).to.equal('takeover');
});
it(`should return 'takeover' if doing HUP for ${deviceType} to a version after ${takeover}`, () => {
expect(
hupActionHelper.getHUPActionType(deviceType, before, after),
).to.equal('takeover');
});

it(`should return 'balenahup' if doing HUP for ${deviceType} from a version after ${takeover}`, () => {
expect(
hupActionHelper.getHUPActionType(deviceType, takeover, after),
).to.equal('balenahup');
});
});
it(`should return 'balenahup' if doing HUP for ${deviceType} from a version after ${takeover}`, () => {
expect(
hupActionHelper.getHUPActionType(deviceType, takeover, after),
).to.equal('balenahup');
});

it(`should return 'balenahup' if doing HUP for ${deviceType} from a version after ${takeover}, for a device in dev mode`, () => {
expect(
hupActionHelper.getHUPActionType(deviceType, takeoverDev, after),
).to.equal('balenahup');
});
},
);
});
});
});

0 comments on commit 8ec3ba5

Please sign in to comment.