Skip to content

Commit 596aedf

Browse files
Merge pull request #2798 from kubernetes-client/copilot/sub-pr-2770-another-one
fix: correct incorrectly nested tests in object_test.ts
2 parents 53db566 + 4ac029a commit 596aedf

1 file changed

Lines changed: 134 additions & 134 deletions

File tree

‎src/object_test.ts‎

Lines changed: 134 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,148 +2012,148 @@ describe('KubernetesObject', () => {
20122012
await mockAgent.close();
20132013
setGlobalDispatcher(origDispatcher);
20142014
}
2015+
});
20152016

2016-
it('should read a custom resource', async () => {
2017-
interface CustomTestResource extends KubernetesObject {
2018-
spec: {
2019-
key: string;
2020-
};
2021-
}
2022-
(client as any).apiVersionResourceCache['example.com/v1'] = {
2023-
groupVersion: 'example.com/v1',
2024-
kind: 'APIResourceList',
2025-
resources: [
2026-
{
2027-
kind: 'CustomTestResource',
2028-
name: 'customtestresources',
2029-
namespaced: true,
2030-
},
2031-
],
2017+
it('should read a custom resource', async () => {
2018+
interface CustomTestResource extends KubernetesObject {
2019+
spec: {
2020+
key: string;
20322021
};
2033-
const origDispatcher = getGlobalDispatcher();
2034-
const mockAgent = new MockAgent();
2035-
setGlobalDispatcher(mockAgent);
2036-
mockAgent.disableNetConnect();
2037-
const pool = mockAgent.get('https://d.i.y');
2038-
try {
2039-
pool.intercept({
2040-
path: '/apis/example.com/v1/namespaces/default/customtestresources/test-1',
2041-
method: 'GET',
2042-
}).reply(
2043-
200,
2044-
JSON.stringify({
2045-
apiVersion: 'example.com/v1',
2046-
kind: 'CustomTestResource',
2047-
metadata: {
2048-
name: 'test-1',
2049-
namespace: 'default',
2050-
uid: 'a4fd7a65-2af5-4ef1-a0bc-cb34a308b821',
2051-
creationTimestamp: '2022-01-01T00:00:00.000Z',
2052-
},
2053-
spec: { key: 'value' },
2054-
}),
2055-
{ headers: { 'content-type': 'application/json' } },
2056-
);
2057-
const custom = await client.read<CustomTestResource>({
2022+
}
2023+
(client as any).apiVersionResourceCache['example.com/v1'] = {
2024+
groupVersion: 'example.com/v1',
2025+
kind: 'APIResourceList',
2026+
resources: [
2027+
{
2028+
kind: 'CustomTestResource',
2029+
name: 'customtestresources',
2030+
namespaced: true,
2031+
},
2032+
],
2033+
};
2034+
const origDispatcher = getGlobalDispatcher();
2035+
const mockAgent = new MockAgent();
2036+
setGlobalDispatcher(mockAgent);
2037+
mockAgent.disableNetConnect();
2038+
const pool = mockAgent.get('https://d.i.y');
2039+
try {
2040+
pool.intercept({
2041+
path: '/apis/example.com/v1/namespaces/default/customtestresources/test-1',
2042+
method: 'GET',
2043+
}).reply(
2044+
200,
2045+
JSON.stringify({
20582046
apiVersion: 'example.com/v1',
20592047
kind: 'CustomTestResource',
2060-
metadata: { name: 'test-1', namespace: 'default' },
2061-
});
2062-
deepStrictEqual(custom.spec, { key: 'value' });
2063-
ok(custom.metadata);
2064-
deepStrictEqual(custom.metadata!.creationTimestamp, new Date('2022-01-01T00:00:00.000Z'));
2065-
} finally {
2066-
mockAgent.assertNoPendingInterceptors();
2067-
await mockAgent.close();
2068-
setGlobalDispatcher(origDispatcher);
2069-
}
2070-
});
2048+
metadata: {
2049+
name: 'test-1',
2050+
namespace: 'default',
2051+
uid: 'a4fd7a65-2af5-4ef1-a0bc-cb34a308b821',
2052+
creationTimestamp: '2022-01-01T00:00:00.000Z',
2053+
},
2054+
spec: { key: 'value' },
2055+
}),
2056+
{ headers: { 'content-type': 'application/json' } },
2057+
);
2058+
const custom = await client.read<CustomTestResource>({
2059+
apiVersion: 'example.com/v1',
2060+
kind: 'CustomTestResource',
2061+
metadata: { name: 'test-1', namespace: 'default' },
2062+
});
2063+
deepStrictEqual(custom.spec, { key: 'value' });
2064+
ok(custom.metadata);
2065+
deepStrictEqual(custom.metadata!.creationTimestamp, new Date('2022-01-01T00:00:00.000Z'));
2066+
} finally {
2067+
mockAgent.assertNoPendingInterceptors();
2068+
await mockAgent.close();
2069+
setGlobalDispatcher(origDispatcher);
2070+
}
2071+
});
20712072

2072-
it('should list resources in a namespace', async () => {
2073-
const origDispatcher = getGlobalDispatcher();
2074-
const mockAgent = new MockAgent();
2075-
setGlobalDispatcher(mockAgent);
2076-
mockAgent.disableNetConnect();
2077-
const pool = mockAgent.get('https://d.i.y');
2078-
try {
2079-
pool.intercept({ path: '/api/v1/namespaces/default/secrets', method: 'GET' }).reply(
2080-
200,
2081-
JSON.stringify({
2082-
apiVersion: 'v1',
2083-
kind: 'SecretList',
2084-
items: [
2085-
{
2086-
apiVersion: 'v1',
2087-
kind: 'Secret',
2088-
metadata: {
2089-
name: 'test-secret-1',
2090-
uid: 'a4fd7a65-2af5-4ef1-a0bc-cb34a308b821',
2091-
},
2073+
it('should list resources in a namespace', async () => {
2074+
const origDispatcher = getGlobalDispatcher();
2075+
const mockAgent = new MockAgent();
2076+
setGlobalDispatcher(mockAgent);
2077+
mockAgent.disableNetConnect();
2078+
const pool = mockAgent.get('https://d.i.y');
2079+
try {
2080+
pool.intercept({ path: '/api/v1/namespaces/default/secrets', method: 'GET' }).reply(
2081+
200,
2082+
JSON.stringify({
2083+
apiVersion: 'v1',
2084+
kind: 'SecretList',
2085+
items: [
2086+
{
2087+
apiVersion: 'v1',
2088+
kind: 'Secret',
2089+
metadata: {
2090+
name: 'test-secret-1',
2091+
uid: 'a4fd7a65-2af5-4ef1-a0bc-cb34a308b821',
20922092
},
2093-
],
2094-
metadata: { resourceVersion: '216532459', continue: 'abc' },
2095-
}),
2096-
{ headers: { 'content-type': 'application/json' } },
2097-
);
2098-
const lr = await client.list<V1Secret>('v1', 'Secret', 'default');
2099-
const items = lr.items;
2100-
strictEqual(items.length, 1);
2101-
strictEqual(items[0] instanceof V1Secret, true);
2102-
} finally {
2103-
mockAgent.assertNoPendingInterceptors();
2104-
await mockAgent.close();
2105-
setGlobalDispatcher(origDispatcher);
2106-
}
2107-
});
2093+
},
2094+
],
2095+
metadata: { resourceVersion: '216532459', continue: 'abc' },
2096+
}),
2097+
{ headers: { 'content-type': 'application/json' } },
2098+
);
2099+
const lr = await client.list<V1Secret>('v1', 'Secret', 'default');
2100+
const items = lr.items;
2101+
strictEqual(items.length, 1);
2102+
strictEqual(items[0] instanceof V1Secret, true);
2103+
} finally {
2104+
mockAgent.assertNoPendingInterceptors();
2105+
await mockAgent.close();
2106+
setGlobalDispatcher(origDispatcher);
2107+
}
2108+
});
21082109

2109-
it('should list resources in all namespaces', async () => {
2110-
const origDispatcher = getGlobalDispatcher();
2111-
const mockAgent = new MockAgent();
2112-
setGlobalDispatcher(mockAgent);
2113-
mockAgent.disableNetConnect();
2114-
const pool = mockAgent.get('https://d.i.y');
2115-
try {
2116-
pool.intercept({
2117-
path: '/api/v1/secrets?fieldSelector=metadata.name%3Dtest-secret1&labelSelector=app%3Dmy-app&limit=5',
2118-
method: 'GET',
2119-
}).reply(
2120-
200,
2121-
JSON.stringify({
2122-
apiVersion: 'v1',
2123-
kind: 'SecretList',
2124-
items: [
2125-
{
2126-
apiVersion: 'v1',
2127-
kind: 'Secret',
2128-
metadata: {
2129-
name: 'test-secret-1',
2130-
uid: 'a4fd7a65-2af5-4ef1-a0bc-cb34a308b821',
2131-
},
2110+
it('should list resources in all namespaces', async () => {
2111+
const origDispatcher = getGlobalDispatcher();
2112+
const mockAgent = new MockAgent();
2113+
setGlobalDispatcher(mockAgent);
2114+
mockAgent.disableNetConnect();
2115+
const pool = mockAgent.get('https://d.i.y');
2116+
try {
2117+
pool.intercept({
2118+
path: '/api/v1/secrets?fieldSelector=metadata.name%3Dtest-secret1&labelSelector=app%3Dmy-app&limit=5',
2119+
method: 'GET',
2120+
}).reply(
2121+
200,
2122+
JSON.stringify({
2123+
apiVersion: 'v1',
2124+
kind: 'SecretList',
2125+
items: [
2126+
{
2127+
apiVersion: 'v1',
2128+
kind: 'Secret',
2129+
metadata: {
2130+
name: 'test-secret-1',
2131+
uid: 'a4fd7a65-2af5-4ef1-a0bc-cb34a308b821',
21322132
},
2133-
],
2134-
metadata: { resourceVersion: '216532459', continue: 'abc' },
2135-
}),
2136-
{ headers: { 'content-type': 'application/json' } },
2137-
);
2138-
const lr = await client.list(
2139-
'v1',
2140-
'Secret',
2141-
undefined,
2142-
undefined,
2143-
undefined,
2144-
undefined,
2145-
'metadata.name=test-secret1',
2146-
'app=my-app',
2147-
5,
2148-
);
2149-
const items = lr.items;
2150-
strictEqual(items.length, 1);
2151-
} finally {
2152-
mockAgent.assertNoPendingInterceptors();
2153-
await mockAgent.close();
2154-
setGlobalDispatcher(origDispatcher);
2155-
}
2156-
});
2133+
},
2134+
],
2135+
metadata: { resourceVersion: '216532459', continue: 'abc' },
2136+
}),
2137+
{ headers: { 'content-type': 'application/json' } },
2138+
);
2139+
const lr = await client.list(
2140+
'v1',
2141+
'Secret',
2142+
undefined,
2143+
undefined,
2144+
undefined,
2145+
undefined,
2146+
'metadata.name=test-secret1',
2147+
'app=my-app',
2148+
5,
2149+
);
2150+
const items = lr.items;
2151+
strictEqual(items.length, 1);
2152+
} finally {
2153+
mockAgent.assertNoPendingInterceptors();
2154+
await mockAgent.close();
2155+
setGlobalDispatcher(origDispatcher);
2156+
}
21572157
});
21582158

21592159
describe('errors', () => {

0 commit comments

Comments
 (0)