javascript icon indicating copy to clipboard operation
javascript copied to clipboard

Jest testing resources?

Open bmoe24x opened this issue 2 years ago • 2 comments

Sorry if this is the wrong place to ask but are there any resources for testing code that utilizes this client? In particular I am using Jest and would like to be able to test code I have built around the k8s client

For example code like this:


    public async getDeployment( deploymentName: string ): Promise<k8s.V1Deployment> {
        const res = await this.k8sApi.readNamespacedDeployment( deploymentName, this.namespace );
        return res.body;
    };

    public async getLoaderPollSizeString( deploymentName: string, deploymentObject?: V1Deployment ): Promise<string> {
        const deployment: V1Deployment = deploymentObject != undefined ? deploymentObject : await this.getDeployment( deploymentName );
    
        const pollSizeValueString: string = deployment.spec.template.spec.containers.find( container => container.name === this.loaderContainerName ).env.find( envvar => envvar.name === this.pollSizeEnvVarName ).value;
    
        return pollSizeValueString ;
    };

Any help is much appreciated as I am finding this rather difficult to test due to k8s setup, underlying http calls, mocking of k8s objects, etc.

Thank you

bmoe24x avatar Jul 13 '22 04:07 bmoe24x

The client code is extensively unit tested, you can look at any of the _test.ts files here:

https://github.com/kubernetes-client/javascript/tree/master/src

There's an example of mocking an HTTP call here:

https://github.com/kubernetes-client/javascript/blob/master/src/top_test.ts#L155

brendandburns avatar Jul 13 '22 21:07 brendandburns

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Oct 11 '22 21:10 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Nov 10 '22 21:11 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar Dec 10 '22 22:12 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Dec 10 '22 22:12 k8s-ci-robot