Skip to content

fix(maven): Snapshot gradle props instead of deleting - #278

Closed
iker-barriocanal wants to merge 18 commits into
masterfrom
iker/fix/gradle-props
Closed

fix(maven): Snapshot gradle props instead of deleting#278
iker-barriocanal wants to merge 18 commits into
masterfrom
iker/fix/gradle-props

Conversation

@iker-barriocanal

Copy link
Copy Markdown
Contributor

From #276 the gradle properties file was removed, causing the loss of any user config that may exist in that file. This PR makes a snapshot of the file at the beginning of the maven target execution and restores it at the end, so the user config shouldn't be affected.

@iker-barriocanal
iker-barriocanal requested a review from BYK August 24, 2021 08:02
@iker-barriocanal iker-barriocanal self-assigned this Aug 24, 2021
Comment thread src/targets/maven.ts Outdated
Comment thread src/targets/maven.ts Outdated
Comment thread src/targets/maven.ts Outdated
Comment thread src/targets/maven.ts Outdated
@iker-barriocanal
iker-barriocanal requested a review from BYK August 26, 2021 10:37

@BYK BYK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushing back for the following reasons:

  1. fs.acccess check
  2. Converting this into a wrapper function like withTempDir()
  3. Converting the tests into "real world" tests instead of implementation checks:
    Actually have a file on the file system and instead of mocking these functions, make sure we get back the original states: non-existent gradle file, gradle file with user info. It should also ensure the proper file is created during the process.

@BYK BYK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context manager looks great and see how much it simplifies the code!

Comment thread src/targets/maven.ts Outdated
Comment thread src/targets/maven.ts Outdated
Comment thread src/targets/maven.ts Outdated
Comment thread src/targets/maven.ts Outdated
Comment thread src/targets/maven.ts
Comment thread src/targets/maven.ts
Comment thread src/targets/maven.ts Outdated
Comment thread src/targets/maven.ts
Comment thread src/targets/__tests__/maven.test.ts
Comment on lines +399 to +400
await expect(fsPromises.access(expectedPropsPath)).rejects.toThrowError(
/ENOENT: no such file/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just expect(fs.exists(expectedPropsPath)).to.not.be.true()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because to and be don't exist. Moving to accessSync since it's cleaner, but if you know an even cleaner way I can update it.

async () => await testCorrectPropsFile(expectedPropsPath)
);

await mvnTarget.publish('v3rs10n', 'r3v1s10n');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expected you to test withGradleProps directly here, instead of mocking upload with your test method and then invoking publish. This would be the correct way to write a unit test for your helper.

Comment thread src/targets/__tests__/maven.test.ts Outdated
});
});

test('existent props file', async () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are missing some test cases:

  1. What if the callback function throws an error? You should test that we still restore the snapshot/delete our own props file
  2. What if we simply cannot backup an existing snapshot file? Where's the test case for that?
  3. What if we cannot restore a snapshot file for some reason?

@BYK BYK added this to the Maven Support milestone Sep 14, 2021
@kamilogorek

Copy link
Copy Markdown
Contributor

Superseded by #351

@iker-barriocanal
iker-barriocanal deleted the iker/fix/gradle-props branch February 14, 2022 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants