From ae32047135844759329daa92614f9663889badbd Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 8 Oct 2024 10:25:54 -0400 Subject: [PATCH] add unit test --- __snapshots__/version-manifest.js | 10 ++++++- ....txt => versions-suffix-with-snapshot.txt} | 4 +-- .../versions-suffix-without-snapshot.txt | 5 ++++ test/updaters/version-manifest.ts | 26 ++++++++++++++----- 4 files changed, 36 insertions(+), 9 deletions(-) rename test/updaters/fixtures/{versions-prefix.txt => versions-suffix-with-snapshot.txt} (52%) create mode 100644 test/updaters/fixtures/versions-suffix-without-snapshot.txt diff --git a/__snapshots__/version-manifest.js b/__snapshots__/version-manifest.js index 12e895258..a73465abd 100644 --- a/__snapshots__/version-manifest.js +++ b/__snapshots__/version-manifest.js @@ -1,4 +1,4 @@ -exports['VersionManifest updateContent updates versions.txt with a version prefix 1'] = ` +exports['VersionManifest updateContent updates versions.txt with an artifact id is another ones suffix with snapshot 1'] = ` # Format: # module:released-version:current-version @@ -6,6 +6,14 @@ google-cloud-admin:2.3.4:2.3.4 admin:3.4.5:3.4.5 ` +exports['VersionManifest updateContent updates versions.txt with an artifact id is another ones suffix without snapshot 1'] = ` +# Format: +# module:released-version:current-version + +google-cloud-admin:2.3.6:2.3.6 +admin:3.4.3:3.4.3 +` + exports['VersionManifest updateContent updates versions.txt with snapshot released version 1'] = ` # Format: # module:released-version:current-version diff --git a/test/updaters/fixtures/versions-prefix.txt b/test/updaters/fixtures/versions-suffix-with-snapshot.txt similarity index 52% rename from test/updaters/fixtures/versions-prefix.txt rename to test/updaters/fixtures/versions-suffix-with-snapshot.txt index 2b41d4e44..fbf670fd5 100644 --- a/test/updaters/fixtures/versions-prefix.txt +++ b/test/updaters/fixtures/versions-suffix-with-snapshot.txt @@ -1,5 +1,5 @@ # Format: # module:released-version:current-version -google-cloud-admin:2.3.4:2.3.4 -admin:3.4.5:3.4.5 \ No newline at end of file +google-cloud-admin:2.3.5:2.3.5 +admin:3.4.2:3.4.2 \ No newline at end of file diff --git a/test/updaters/fixtures/versions-suffix-without-snapshot.txt b/test/updaters/fixtures/versions-suffix-without-snapshot.txt new file mode 100644 index 000000000..bff26116d --- /dev/null +++ b/test/updaters/fixtures/versions-suffix-without-snapshot.txt @@ -0,0 +1,5 @@ +# Format: +# module:released-version:current-version + +google-cloud-admin:2.3.0:2.3.1-SNAPSHOT +admin:3.4.0:3.4.1-SNAPSHOT \ No newline at end of file diff --git a/test/updaters/version-manifest.ts b/test/updaters/version-manifest.ts index 659bc0344..7e170f46b 100644 --- a/test/updaters/version-manifest.ts +++ b/test/updaters/version-manifest.ts @@ -82,17 +82,31 @@ describe('VersionManifest', () => { const newContent = javaAuthVersions.updateContent(oldContent); snapshot(newContent); }); - }); - describe('updateContent', () => { - it('updates versions.txt with a version prefix', async () => { + it('updates versions.txt with an artifact id is another ones suffix with snapshot', async () => { + const oldContent = readFileSync( + resolve(fixturesPath, './versions-suffix-with-snapshot.txt'), + 'utf8' + ).replace(/\r\n/g, '\n'); + const versions = new Map(); + versions.set('google-cloud-admin', Version.parse('2.3.4')); + versions.set('admin', Version.parse('3.4.5')); + const javaAuthVersions = new VersionsManifest({ + versionsMap: versions, + version: Version.parse('1.2.3'), + }); + const newContent = javaAuthVersions.updateContent(oldContent); + snapshot(newContent); + }); + + it('updates versions.txt with an artifact id is another ones suffix without snapshot', async () => { const oldContent = readFileSync( - resolve(fixturesPath, './versions-prefix.txt'), + resolve(fixturesPath, './versions-suffix-without-snapshot.txt'), 'utf8' ).replace(/\r\n/g, '\n'); const versions = new Map(); - versions.set('google-cloud-trace', Version.parse('2.3.4')); - versions.set('trace', Version.parse('3.4.5')); + versions.set('google-cloud-admin', Version.parse('2.3.6')); + versions.set('admin', Version.parse('3.4.3')); const javaAuthVersions = new VersionsManifest({ versionsMap: versions, version: Version.parse('1.2.3'),