diff --git a/test/strategies/java-yoshi-mono-repo.ts b/test/strategies/java-yoshi-mono-repo.ts index 98bed4db7..2a426fc33 100644 --- a/test/strategies/java-yoshi-mono-repo.ts +++ b/test/strategies/java-yoshi-mono-repo.ts @@ -19,6 +19,7 @@ import {JavaYoshiMonoRepo} from '../../src/strategies/java-yoshi-mono-repo'; import * as sinon from 'sinon'; import { buildGitHubFileContent, + buildGitHubFileRaw, assertHasUpdate, assertNoHasUpdate, } from '../helpers'; @@ -291,6 +292,60 @@ describe('JavaYoshiMonoRepo', () => { assertHasUpdate(updates, 'path1/Version.java', JavaUpdate); }); + it('updates Version.java file content correctly with typical bump', async () => { + const strategy = new JavaYoshiMonoRepo({ + targetBranch: 'main', + github, + component: 'google-cloud-automl', + }); + const findFilesStub = sandbox.stub(github, 'findFilesByFilenameAndRef'); + findFilesStub + .withArgs('Version.java', 'main', '.') + .resolves(['path1/Version.java']); + findFilesStub + .withArgs('pom.xml', 'main', '.') + .resolves([]); + findFilesStub + .withArgs('build.gradle', 'main', '.') + .resolves([]); + findFilesStub + .withArgs('dependencies.properties', 'main', '.') + .resolves([]); + findFilesStub + .withArgs('README.md', 'main', '.') + .resolves([]); + + const getFileContentsStub = sandbox.stub( + github, + 'getFileContentsOnBranch' + ); + getFileContentsStub + .withArgs('versions.txt', 'main') + .resolves(buildGitHubFileRaw('google-cloud-automl:1.0.0:1.0.1-SNAPSHOT')); + + const latestRelease = undefined; + const release = await strategy.buildReleasePullRequest( + COMMITS, + latestRelease + ); + + const updates = release!.updates; + const update = assertHasUpdate(updates, 'path1/Version.java', JavaUpdate); + + const oldContent = ` + package com.google.cloud.automl.v1.stub; + public class Version { + // {x-version-update-start:google-cloud-automl:current} + public static final String STRING = "1.0.0"; + // {x-version-update-end} + } + `; + + const newContent = update.updater.updateContent(oldContent); + expect(newContent).to.contain('1.0.1'); + expect(newContent).to.not.contain('beta'); + }); + it('finds and updates extra files', async () => { const strategy = new JavaYoshiMonoRepo({ targetBranch: 'main', diff --git a/test/updaters/generic.ts b/test/updaters/generic.ts index 489b7ee38..8fe0a98fc 100644 --- a/test/updaters/generic.ts +++ b/test/updaters/generic.ts @@ -16,6 +16,7 @@ import {readFileSync} from 'fs'; import {resolve} from 'path'; import * as snapshot from 'snap-shot-it'; import {describe, it} from 'mocha'; +import {expect} from 'chai'; import {Version} from '../../src/version'; import {Generic} from '../../src/updaters/generic'; @@ -39,5 +40,25 @@ describe('Generic', () => { const newContent = pom.updateContent(oldContent); snapshot(newContent); }); + + it('does not update Java update markers', async () => { + const oldContent = ` + package com.google.cloud.eventarc.v1.stub; + final class Version { + // {x-version-update-start:google-cloud-eventarc:current} + static final String VERSION = "0.0.0-SNAPSHOT"; + // {x-version-update-end} + } + `; + const versions = new Map(); + versions.set('google-cloud-eventarc', Version.parse('1.0.0')); + const updater = new Generic({ + versionsMap: versions, + version: Version.parse('1.0.0'), + }); + const newContent = updater.updateContent(oldContent); + // Content should remain unchanged because Generic doesn't support these markers + expect(newContent).to.eql(oldContent); + }); }); });