Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions test/strategies/java-yoshi-mono-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import * as sinon from 'sinon';
import {
buildGitHubFileContent,
buildGitHubFileRaw,
assertHasUpdate,
assertNoHasUpdate,
} from '../helpers';
Expand Down Expand Up @@ -291,6 +292,60 @@
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

Check failure on line 305 in test/strategies/java-yoshi-mono-repo.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎········.withArgs('pom.xml',·'main',·'.')⏎········` with `.withArgs('pom.xml',·'main',·'.')`
.withArgs('pom.xml', 'main', '.')
.resolves([]);
findFilesStub

Check failure on line 308 in test/strategies/java-yoshi-mono-repo.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎········.withArgs('build.gradle',·'main',·'.')⏎········` with `.withArgs('build.gradle',·'main',·'.')`
.withArgs('build.gradle', 'main', '.')
.resolves([]);
findFilesStub
.withArgs('dependencies.properties', 'main', '.')
.resolves([]);
findFilesStub

Check failure on line 314 in test/strategies/java-yoshi-mono-repo.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎········.withArgs('README.md',·'main',·'.')⏎········` with `.withArgs('README.md',·'main',·'.')`
.withArgs('README.md', 'main', '.')
.resolves([]);

Check failure on line 317 in test/strategies/java-yoshi-mono-repo.ts

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed

Check failure on line 317 in test/strategies/java-yoshi-mono-repo.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `······`
const getFileContentsStub = sandbox.stub(
github,
'getFileContentsOnBranch'
);
getFileContentsStub
.withArgs('versions.txt', 'main')
.resolves(buildGitHubFileRaw('google-cloud-automl:1.0.0:1.0.1-SNAPSHOT'));

Check failure on line 324 in test/strategies/java-yoshi-mono-repo.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `buildGitHubFileRaw('google-cloud-automl:1.0.0:1.0.1-SNAPSHOT'));` with `⏎··········buildGitHubFileRaw('google-cloud-automl:1.0.0:1.0.1-SNAPSHOT')`

Check failure on line 325 in test/strategies/java-yoshi-mono-repo.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··);⏎`

Check failure on line 325 in test/strategies/java-yoshi-mono-repo.ts

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
COMMITS,
latestRelease
);

Check failure on line 331 in test/strategies/java-yoshi-mono-repo.ts

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed

Check failure on line 331 in test/strategies/java-yoshi-mono-repo.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `······`
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',
Expand Down
21 changes: 21 additions & 0 deletions test/updaters/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<string, Version>();
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);
});
});
});
Loading