-
Notifications
You must be signed in to change notification settings - Fork 62
Use latest release from sqlcmd #229
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
base: master
Are you sure you want to change the base?
Conversation
Should we introduce a new |
|
* @returns The version number or undefined if the version could not be parsed or HTTP request failed. | ||
*/ | ||
public static async extractVersionFromLatestRelease(releaseUrl: string): Promise<string | undefined> { | ||
const http = new HttpClient('Azure/sql-action', undefined, { allowRedirects: false }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have access to user token (or some sort of system token) from sql-action here? Since this is unauthenticated, it will be much more rate-limited.
If we do, may be easier just to use octokit library instead of httpclient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately it doesn't appear there's an easy way to get the token, we'd have to introduce a new input so users can pass in GITHUB_TOKEN
to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the rate limiting will be here - since we're not using a REST API necessarily, we're checking the redirect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review of TypeScript Test Code for Setup.ts
Summary:
The code snippet tests the setupSqlcmd
function in TypeScript, ensuring correct setup of SQL command-line tools (sqlcmd
). It utilizes Jest for mocking and spying on methods from HttpClient
and tc
(Tool Cache).
Feedback and Improvements:
-
Test Function Naming:
- Ensure descriptive names for test functions. For example,
it('sets up sqlcmd correctly')
clearly describes the purpose of the test.
- Ensure descriptive names for test functions. For example,
-
Spy Usage:
- Good use of
jest.spyOn
to mockHttpClient.prototype.head
and various methods fromtc
for controlled testing environments.
- Good use of
-
Refactoring Suggestions:
- Consider refactoring to improve test coverage or to handle additional edge cases specific to
setupSqlcmd
. - Use
beforeEach
orbeforeAll
hooks to set up common test conditions, reducing redundancy in test setup.
- Consider refactoring to improve test coverage or to handle additional edge cases specific to
-
Conditional Testing:
- Ensure that conditional testing (
if (process.platform === 'win32')
) is robust and handles all expected scenarios.
- Ensure that conditional testing (
Example Improvements:
describe('Setup.ts tests', () => {
beforeEach(() => {
jest.clearAllMocks(); // Reset all spies before each test
});
it('sets up sqlcmd correctly', async () => {
const extractVersionSpy = jest.spyOn(Setup, 'extractVersionFromLatestRelease').mockResolvedValue('1.1.1');
const cacheLookupSpy = jest.spyOn(tc, 'find').mockReturnValue('');
const downloadToolSpy = jest.spyOn(tc, 'downloadTool').mockResolvedValue('');
const extractTarSpy = jest.spyOn(tc, 'extractTar').mockResolvedValue('');
await Setup.setupSqlcmd();
expect(extractVersionSpy).toHaveBeenCalled();
expect(cacheLookupSpy).toHaveBeenCalled();
expect(downloadToolSpy).toHaveBeenCalled();
if (process.platform === 'win32') {
// Add platform-specific expectations or tests
}
});
});
Conclusion:
The provided test setup effectively verifies the setupSqlcmd
function's behavior, utilizing Jest spies to mock dependencies and assert expected function calls. Consider the outlined improvements to enhance code readability, maintainability, and test coverage.
Uh oh!
There was an error while loading. Please reload this page.