-
Notifications
You must be signed in to change notification settings - Fork 551
fix: remove final refrences to request + fix tests #1033
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
Conversation
|
Welcome @rbnayax! |
|
||
describe('Watch', () => { | ||
describe('DefaultRequest', () => { |
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 a little worried that we're deleting these two tests, are they really not needed?
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.
those 2 are not relevant anymore as we don't use the DefaultRequest class anymore
expect(doneErr.length).to.equal(1); | ||
expect(doneErr[0]).to.deep.equal(errIn); | ||
}); | ||
|
||
it.skip('should handle server side close correctly', async () => { |
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.
Worried that we're removing this test too.
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.
my bad, I readded but it is now skipped due to the node-fetch bug I mentioned (at least I think). To properly close a stream, one needs to call destroy
which other tests are already performing and it works
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.
Actually streams can't be closed anymore simply by emitting close
events, to I think that test might be redundant
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 fixed the test
|
||
expect(reqOpts.uri).to.equal(`${server}${path}`); |
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.
Are there equiavelent tests we could do for fetch?
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.
The fact that the test passes, means the correct uri was used, as this is the URL nock will listen on. If you change the URL for some reason, you will get an error from nock
Generally this looks ok (and thanks for the PR!) but I'm a little bit worried that the test coverage is being reduced. Is there a way to maintain the test coverage? |
I did everything I can to test what is possible. If you can suggest other tests I will gladly implement |
@@ -146,6 +147,26 @@ export class KubeConfig implements SecurityAuthentication { | |||
this.makePathsAbsolute(rootDirectory); | |||
} | |||
|
|||
public async applytoFetchOptions(opts: https.RequestOptions): Promise<RequestInit> { |
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.
could we just merge this with applyToHTTPSOptions()?
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.
We can not, as applyToHTTPSOptions
is being used by proto-client
done = doneOrOptions; | ||
} else { | ||
): Promise<AbortController> { | ||
const AbortControllerCtor = globalThis.AbortController || (await import('abort-controller')); |
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.
im not familiar with this pattern, why can't we just re-use the AbortController import from above?
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.
AbortController exists natively since node since v15, so we can use it, or the "shim" in previous version
}); | ||
}); | ||
|
||
it('should handle non-200 error codes', (done) => { |
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 think we could convert this test to still validate this chunk of error wrapping by emitting a non-200 code and catching it on the stream?:
await fetch(watchURL, requestInit)
.then((response) => {
if (response.status === 200) {
response.body.on('error', doneCallOnce);
response.body.pipe(stream);
} else {
const error = new Error(response.statusText) as Error & {
statusCode: number | undefined;
};
error.statusCode = response.status;
throw error;
}
})
.catch(doneCallOnce);
i see you have it in other tests, but this one was isolated to just that functionality
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.
test should handle error from request stream
does exactly that, unless I'm missing something here
const expectedCA = Buffer.from('CADATA2', 'utf-8'); | ||
const expectedAgent = new https.Agent({ | ||
ca: expectedCA, | ||
rejectUnauthorized: false, |
Check failure
Code scanning / CodeQL
Disabling certificate validation
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.
this is a test... not sure how to ignore that
I managed to find a way to maintain all existing tests so coverage is the same! |
/lgtm Thanks for the patience! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: brendandburns, rbnayax The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
I removed the request library (had to install form-data instead of it)
I added the node-fetch types
fixed log, watch, catch and metrics
Fixed all tests