-
-
Notifications
You must be signed in to change notification settings - Fork 20
fix(maven): Snapshot gradle props instead of deleting #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bb1c5b1
0c9b0cb
b94ad6b
c94f6de
1a61c96
a200997
91a334a
0201b53
f4aa902
68e78bd
951a2ad
fe10600
39bedb4
8cba87a
2997c86
00c99ef
0803fd5
d38322d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,15 @@ import { homedir } from 'os'; | |
| import { join } from 'path'; | ||
| import { NoneArtifactProvider } from '../../artifact_providers/none'; | ||
| import { | ||
| GRADLE_PROPERTIES_FILENAME, | ||
| MavenTarget, | ||
| POM_DEFAULT_FILENAME, | ||
| targetOptions, | ||
| targetSecrets, | ||
| } from '../maven'; | ||
| import { retrySpawnProcess } from '../../utils/async'; | ||
| import { withTempDir } from '../../utils/files'; | ||
| import { promises as fsPromises } from 'fs'; | ||
|
|
||
| jest.mock('../../utils/files'); | ||
|
|
||
|
|
@@ -19,6 +21,8 @@ jest.mock('fs', () => ({ | |
| readFile: jest.fn((file: string) => file), | ||
| readdir: async () => Promise.resolve([]), // empty dir | ||
| unlink: jest.fn(), | ||
| access: jest.fn(), | ||
| copyFile: jest.fn(), | ||
| }, | ||
| })); | ||
|
|
||
|
|
@@ -188,16 +192,22 @@ describe('publish', () => { | |
| beforeEach(() => jest.resetAllMocks()); | ||
|
|
||
| test('main flow', async () => { | ||
| (withTempDir as jest.MockedFunction< | ||
| typeof withTempDir | ||
| >).mockImplementationOnce(async cb => { | ||
| return await cb(tmpDirName); | ||
| }); | ||
|
|
||
| const callOrder: string[] = []; | ||
| const mvnTarget = createMavenTarget(); | ||
| const createGradlePropsMock = jest.fn( | ||
| async () => void callOrder.push('createGradleProps') | ||
| const makeSnapshotMock = jest.fn( | ||
| async () => void callOrder.push('makeSnapshot') | ||
| ); | ||
| mvnTarget.createUserGradlePropsFile = createGradlePropsMock; | ||
| const deleteGradlePropsMock = jest.fn( | ||
| async () => void callOrder.push('deleteGradleProps') | ||
| mvnTarget.createUserGradlePropsFile = makeSnapshotMock; | ||
| const restoreGradleProps = jest.fn( | ||
| async () => void callOrder.push('restoreSnapshot') | ||
| ); | ||
| mvnTarget.deleteUserGradlePropsFile = deleteGradlePropsMock; | ||
| mvnTarget.restoreGradleProps = restoreGradleProps; | ||
| const uploadMock = jest.fn(async () => void callOrder.push('upload')); | ||
| mvnTarget.upload = uploadMock; | ||
| (retrySpawnProcess as jest.MockedFunction< | ||
|
|
@@ -208,30 +218,30 @@ describe('publish', () => { | |
|
|
||
| const revision = 'r3v1s10n'; | ||
| await mvnTarget.publish('1.0.0', revision); | ||
| expect(createGradlePropsMock).toHaveBeenCalledTimes(1); | ||
| expect(makeSnapshotMock).toHaveBeenCalledTimes(1); | ||
| expect(uploadMock).toHaveBeenCalledTimes(1); | ||
| expect(uploadMock).toHaveBeenLastCalledWith(revision); | ||
| expect(deleteGradlePropsMock).toHaveBeenCalledTimes(1); | ||
| expect(restoreGradleProps).toHaveBeenCalledTimes(1); | ||
| expect(retrySpawnProcess).toHaveBeenCalledTimes(1); | ||
| expect(retrySpawnProcess).toHaveBeenCalledWith(DEFAULT_OPTION_VALUE, [ | ||
| 'closeAndReleaseRepository', | ||
| ]); | ||
| expect(callOrder).toStrictEqual([ | ||
| 'createGradleProps', | ||
| 'makeSnapshot', | ||
| 'upload', | ||
| 'closeAndRelease', | ||
| 'deleteGradleProps', | ||
| 'restoreSnapshot', | ||
| ]); | ||
| }); | ||
|
|
||
| test('upload POM', async () => { | ||
| // simple mock to always use the same temporary directory, | ||
| // instead of creating a new one | ||
| (withTempDir as jest.MockedFunction<typeof withTempDir>).mockImplementation( | ||
| async cb => { | ||
| return await cb(tmpDirName); | ||
| } | ||
| ); | ||
| (withTempDir as jest.MockedFunction< | ||
| typeof withTempDir | ||
| >).mockImplementationOnce(async cb => { | ||
| return await cb(tmpDirName); | ||
| }); | ||
|
|
||
| const mvnTarget = createMavenTarget(); | ||
| mvnTarget.getArtifactsForRevision = jest | ||
|
|
@@ -275,11 +285,11 @@ describe('publish', () => { | |
| test('upload BOM', async () => { | ||
| // simple mock to always use the same temporary directory, | ||
| // instead of creating a new one | ||
| (withTempDir as jest.MockedFunction<typeof withTempDir>).mockImplementation( | ||
| async cb => { | ||
| return await cb(tmpDirName); | ||
| } | ||
| ); | ||
| (withTempDir as jest.MockedFunction< | ||
| typeof withTempDir | ||
| >).mockImplementationOnce(async cb => { | ||
| return await cb(tmpDirName); | ||
| }); | ||
|
|
||
| const mvnTarget = createMavenTarget(); | ||
| mvnTarget.getArtifactsForRevision = jest | ||
|
|
@@ -338,3 +348,88 @@ describe('get gradle home directory', () => { | |
| expect(actual).toEqual(expected); | ||
| }); | ||
| }); | ||
|
|
||
| describe('withGradleProps', () => { | ||
| beforeAll(() => { | ||
| setTargetSecretsInEnv(); | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| removeTargetSecretsFromEnv(); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| delete process.env.GRADLE_USER_HOME; | ||
| }); | ||
|
|
||
| /** | ||
| * Checks whether the properties file is correct. | ||
| * @param path Path to the properties file. | ||
| */ | ||
| async function testCorrectPropsFile(path: string): Promise<void> { | ||
| try { | ||
| const content = (await fsPromises.readFile(path)).toString(); | ||
| expect(content).toMatch(`mavenCentralUsername=${DEFAULT_OPTION_VALUE}`); | ||
|
iker-barriocanal marked this conversation as resolved.
|
||
| expect(content).toMatch(`mavenCentralPassword=${DEFAULT_OPTION_VALUE}`); | ||
| } catch (error) { | ||
| throw new Error(`Cannot read the contents of the props file: ${error}`); | ||
| } | ||
| } | ||
|
|
||
| test('non-existent props file', async () => { | ||
| await withTempDir(async dir => { | ||
| process.env.GRADLE_USER_HOME = dir; | ||
| const expectedPropsPath = `${dir}/${GRADLE_PROPERTIES_FILENAME}`; | ||
|
|
||
| /** | ||
| * Expect 3 assertions: | ||
| * 2 testing whether the correct file in execution is created. | ||
| * 1 testing whether the user's file has been deleted. | ||
| */ | ||
| expect.assertions(3); | ||
|
|
||
| const mvnTarget = createMavenTarget(getRequiredTargetConfig()); | ||
| mvnTarget.upload = jest | ||
| .fn() | ||
| .mockImplementationOnce( | ||
| async () => await testCorrectPropsFile(expectedPropsPath) | ||
| ); | ||
|
|
||
| await mvnTarget.publish('v3rs10n', 'r3v1s10n'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I expected you to test |
||
| await expect(fsPromises.access(expectedPropsPath)).rejects.toThrowError( | ||
| /ENOENT: no such file/ | ||
|
Comment on lines
+399
to
+400
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because |
||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| test('existent props file', async () => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are missing some test cases:
|
||
| await withTempDir(async dir => { | ||
| process.env.GRADLE_USER_HOME = dir; | ||
| const expectedPropsPath = `${dir}/${GRADLE_PROPERTIES_FILENAME}`; | ||
| const testProps = 'some random data to test prop snapshotting'; | ||
|
|
||
| /** | ||
| * Expect 3 assertions: | ||
| * 2 testing whether the correct file in execution is created. | ||
| * 1 testing whether the file user's props file has correctly been restored. | ||
| */ | ||
| expect.assertions(3); | ||
|
|
||
| // If we can't create the props file this test doesn't test anything | ||
| // new, so stop it (don't catch the error). | ||
| await fsPromises.writeFile(expectedPropsPath, testProps); | ||
|
|
||
| const mvnTarget = createMavenTarget(getRequiredTargetConfig()); | ||
| mvnTarget.upload = jest | ||
| .fn() | ||
| .mockImplementationOnce( | ||
| async () => await testCorrectPropsFile(expectedPropsPath) | ||
| ); | ||
| await mvnTarget.publish('v3rs10n', 'r3v1s10n'); | ||
|
|
||
| expect( | ||
| (await fsPromises.readFile(expectedPropsPath)).toString() | ||
| ).toStrictEqual(testProps); | ||
| }); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.