Skip to content

Commit 20ff54c

Browse files
committed
Add test for typed objects from generic client
1 parent 3af4d70 commit 20ff54c

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/object_test.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai';
22
import nock = require('nock');
3-
import { V1APIResource, V1APIResourceList } from './api';
3+
import { V1APIResource, V1APIResourceList, V1Secret } from './api';
44
import { KubeConfig } from './config';
55
import { KubernetesObjectApi } from './object';
66
import { KubernetesObject } from './types';
@@ -1748,6 +1748,42 @@ describe('KubernetesObject', () => {
17481748
scope.done();
17491749
});
17501750

1751+
it('should read a resource', async () => {
1752+
const scope = nock('https://d.i.y')
1753+
.get(
1754+
'/api/v1/namespaces/default/secrets/test-secret-1',
1755+
)
1756+
.reply(200, {
1757+
apiVersion: 'v1',
1758+
kind: 'Secret',
1759+
metadata: {
1760+
name: 'test-secret-1',
1761+
namespace: 'default',
1762+
uid: 'a4fd7a65-2af5-4ef1-a0bc-cb34a308b821',
1763+
creationTimestamp: '2022-01-01T00:00:00.000Z',
1764+
},
1765+
data: {
1766+
key: 'value',
1767+
},
1768+
});
1769+
const res = await client.read(
1770+
{
1771+
apiVersion: 'v1',
1772+
kind: 'Secret',
1773+
metadata: {
1774+
name: 'test-secret-1',
1775+
namespace: 'default',
1776+
},
1777+
},
1778+
);
1779+
const secret = res.body as V1Secret;
1780+
expect(secret.data).to.contain({
1781+
key: 'value',
1782+
});
1783+
expect(secret.metadata?.creationTimestamp).to.equal(new Date('2022-01-01T00:00:00.000Z'));
1784+
scope.done();
1785+
});
1786+
17511787
it('should list resources in a namespace', async () => {
17521788
const scope = nock('https://d.i.y')
17531789
.get(

0 commit comments

Comments
 (0)