Skip to content

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

Merged
merged 10 commits into from
Apr 14, 2023

Conversation

rbnayax
Copy link
Contributor

@rbnayax rbnayax commented Mar 31, 2023

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

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 31, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Mar 31, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @rbnayax!

It looks like this is your first PR to kubernetes-client/javascript 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/javascript has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 31, 2023
@rbnayax rbnayax marked this pull request as draft March 31, 2023 08:15
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 31, 2023
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 31, 2023
@rbnayax rbnayax marked this pull request as ready for review March 31, 2023 16:56
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 31, 2023
@rbnayax rbnayax changed the title fix: remove unused request dependency fix: remove final refrences to request + fix tests Mar 31, 2023

describe('Watch', () => {
describe('DefaultRequest', () => {
Copy link
Contributor

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?

Copy link
Contributor Author

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 () => {
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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}`);
Copy link
Contributor

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?

Copy link
Contributor Author

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

@brendandburns
Copy link
Contributor

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?

@rbnayax
Copy link
Contributor Author

rbnayax commented Apr 3, 2023

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> {
Copy link
Contributor

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()?

Copy link
Contributor Author

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'));
Copy link
Contributor

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?

Copy link
Contributor Author

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) => {
Copy link
Contributor

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

Copy link
Contributor Author

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

Disabling certificate validation is strongly discouraged.
Copy link
Contributor Author

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

@rbnayax
Copy link
Contributor Author

rbnayax commented Apr 9, 2023

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 managed to find a way to maintain all existing tests so coverage is the same!

@brendandburns
Copy link
Contributor

/lgtm
/approve

Thanks for the patience!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 14, 2023
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 14, 2023
@k8s-ci-robot k8s-ci-robot merged commit 305c307 into kubernetes-client:release-1.x Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants