Skip to content

Commit b71e20f

Browse files
committed
add tests
1 parent cf4a11d commit b71e20f

File tree

3 files changed

+359
-66
lines changed

3 files changed

+359
-66
lines changed

src/object.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ export class KubernetesObjectApi extends ApisApi {
546546
*
547547
* @returns WatchResult object that can be used to abort the watch.
548548
*/
549-
public async watch<T>({
549+
public async watch<T extends KubernetesObject | KubernetesObject>({
550550
resource,
551551
options = {},
552552
callback,
@@ -564,8 +564,39 @@ export class KubernetesObjectApi extends ApisApi {
564564
if (!this.watcher) {
565565
throw new Error('Watcher not initialized');
566566
}
567-
const resourcePath = await this.specUriPath(resource, 'list');
568-
const res: RequestResult = await this.watcher.watch(resourcePath, options, callback, done);
567+
const resourcePath = new URL(
568+
await this.specUriPath(
569+
{
570+
apiVersion: resource.apiVersion,
571+
kind: resource.kind,
572+
metadata: {
573+
namespace: resource.namespace,
574+
},
575+
},
576+
'list',
577+
),
578+
).pathname;
579+
const type = await this.getSerializationType(resource.apiVersion, resource.kind);
580+
const cb: WatchCallback<T> = (phase: KubernetesEventType, apiObj: T, watchObj?: WatchObject<T>) => {
581+
const obj = ObjectSerializer.deserialize(apiObj, type);
582+
callback(
583+
phase,
584+
obj,
585+
watchObj
586+
? {
587+
...watchObj,
588+
object: obj,
589+
}
590+
: undefined,
591+
);
592+
};
593+
const res: RequestResult = await this.watcher.watch(
594+
resourcePath,
595+
options,
596+
// required to convert to less strict type.
597+
cb as (phase: string, apiObj: any, watchObj?: any) => void,
598+
done,
599+
);
569600
return {
570601
abort: () => res.abort(),
571602
};

0 commit comments

Comments
 (0)