-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix [Vcpkg] version service for different version fields (#8945)
* Fix [Vcpkg] version service for different version fields * Use match one to enforce a single alternative * Mock different version field test cases * Extract version field parsing as separate helper --------- Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
- Loading branch information
1 parent
f55a655
commit 4a5bf53
Showing
4 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { InvalidResponse } from '../index.js' | ||
|
||
export function parseVersionFromVcpkgManifest(manifest) { | ||
if (manifest['version-date']) { | ||
return manifest['version-date'] | ||
} | ||
if (manifest['version-semver']) { | ||
return manifest['version-semver'] | ||
} | ||
if (manifest['version-string']) { | ||
return manifest['version-string'] | ||
} | ||
if (manifest.version) { | ||
return manifest.version | ||
} | ||
throw new InvalidResponse({ prettyMessage: 'missing version' }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { expect } from 'chai' | ||
import { InvalidResponse } from '../index.js' | ||
import { parseVersionFromVcpkgManifest } from './vcpkg-version-helpers.js' | ||
|
||
describe('parseVersionFromVcpkgManifest', function () { | ||
it('returns a version when `version` field is detected', function () { | ||
expect( | ||
parseVersionFromVcpkgManifest({ | ||
version: '2.12.1', | ||
}) | ||
).to.equal('2.12.1') | ||
}) | ||
|
||
it('returns a version when `version-date` field is detected', function () { | ||
expect( | ||
parseVersionFromVcpkgManifest({ | ||
'version-date': '2022-12-04', | ||
}) | ||
).to.equal('2022-12-04') | ||
}) | ||
|
||
it('returns a version when `version-semver` field is detected', function () { | ||
expect( | ||
parseVersionFromVcpkgManifest({ | ||
'version-semver': '3.11.2', | ||
}) | ||
).to.equal('3.11.2') | ||
}) | ||
|
||
it('returns a version when `version-date` field is detected', function () { | ||
expect( | ||
parseVersionFromVcpkgManifest({ | ||
'version-string': '22.01', | ||
}) | ||
).to.equal('22.01') | ||
}) | ||
|
||
it('rejects when no version field variant is detected', function () { | ||
expect(() => parseVersionFromVcpkgManifest('{}')).to.throw(InvalidResponse) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters