Skip to content

Commit 7b19ee6

Browse files
committed
update to strictequals, imports, and remove mixed then/await
1 parent 4029d2e commit 7b19ee6

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

examples/typescript/patch/patch-example.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { CoreV1Api, KubeConfig, setHeaderOptions } from '@kubernetes/client-node';
2-
import { PatchStrategy } from '@kubernetes/client-node/patch';
1+
import { CoreV1Api, KubeConfig, setHeaderOptions, PatchStrategy } from '@kubernetes/client-node';
32

43
const kc = new KubeConfig();
54
kc.loadFromDefault();

src/middleware_test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ describe('Middleware', async () => {
88
const reqContext = new RequestContext('http://nowhere.com', HttpMethod.GET);
99
deepStrictEqual(reqContext.getHeaders(), {});
1010
const headerMiddleware = setHeaderMiddleware('test-key', 'test-value');
11-
const postMiddlewareRequest = await headerMiddleware.pre(reqContext);
12-
await postMiddlewareRequest.toPromise().then((request) => {
13-
deepStrictEqual(request.getHeaders(), { 'test-key': 'test-value' });
14-
});
11+
const postMiddlewareRequestObservable = await headerMiddleware.pre(reqContext);
12+
const postMiddlewareRequest = await postMiddlewareRequestObservable.toPromise();
13+
deepStrictEqual(postMiddlewareRequest.getHeaders(), { 'test-key': 'test-value' });
1514
});
1615

1716
it('should replace a header if it is already specified', async () => {

src/test/integration/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import patchNamespace from './patchNamespace.js';
22

33
console.log('Integration testing');
44

5-
patchNamespace();
5+
await patchNamespace();

src/test/integration/name.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* This function is used to generate a random name for the resources created in the tests.
3+
* This is to avoid conflicts with existing resources.
4+
*/
5+
export function generateName(name: string) {
6+
return name + '-' + Math.random().toString(36).substring(7);
7+
}

src/test/integration/patchNamespace.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import assert, { deepEqual } from 'node:assert';
22
import { PatchStrategy, CoreV1Api, KubeConfig, setHeaderOptions, V1Namespace } from '../../index.js';
3+
import { generateName } from './name.js';
34

45
export default async function patchNamespace() {
56
const kc = new KubeConfig();
67
kc.loadFromDefault();
78

89
const coreV1Client = kc.makeApiClient(CoreV1Api);
910
let newNS = new V1Namespace();
10-
const testNSName = 'integration-test-patch-ns';
11+
const testNSName = generateName('patch-ns');
1112
newNS.metadata = {
1213
name: testNSName,
1314
labels: {
@@ -17,8 +18,8 @@ export default async function patchNamespace() {
1718
console.log(`Creating namespace ${testNSName}`);
1819
await coreV1Client.createNamespace({ body: newNS });
1920
newNS = await coreV1Client.readNamespace({ name: testNSName });
20-
assert(newNS.metadata?.name === testNSName);
21-
deepEqual(newNS.metadata?.labels?.initialLabel, 'initialValue');
21+
assert.strictEqual(newNS.metadata?.name, testNSName);
22+
assert.strictEqual(newNS.metadata?.labels?.initialLabel, 'initialValue');
2223
console.log('Namespace created with initial label.');
2324

2425
const patch = [
@@ -41,7 +42,7 @@ export default async function patchNamespace() {
4142
);
4243

4344
const patchedNS = await coreV1Client.readNamespace({ name: testNSName });
44-
deepEqual(patchedNS.metadata?.labels?.foo, 'bar');
45-
deepEqual(patchedNS.metadata?.labels?.initialLabel, undefined);
45+
assert.strictEqual(patchedNS.metadata?.labels?.foo, 'bar');
46+
assert.strictEqual(patchedNS.metadata?.labels?.initialLabel, undefined);
4647
console.log('Namespace patched with new label.');
4748
}

0 commit comments

Comments
 (0)