Skip to content
This repository was archived by the owner on Jun 26, 2026. It is now read-only.

Commit 1a69605

Browse files
fix(k8s-client): add optional client prop to K8sProvider for test injection
Backport the client injection escape-hatch from main so the test-utils render helper (renderWithK8sProvider) can pass a mock K8sClient without going through a real K8sClientConfig. Production callers are unaffected — the prop is optional and the existing config-based construction is the fallback. Assisted-By: Claude <noreply@anthropic.com> Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
1 parent 0fddf0f commit 1a69605

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎packages/k8s-client/src/provider.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@ const defaultQueryClient = new QueryClient({
2828

2929
interface K8sProviderProps {
3030
config?: K8sClientConfig
31+
/** Pre-built client instance; when supplied skips construction from config. Primary use case: injecting a mock in tests. */
32+
client?: K8sClient
3133
queryClient?: QueryClient
3234
children: ReactNode
3335
}
3436

35-
export function K8sProvider({ config, queryClient, children }: K8sProviderProps) {
36-
const client = useMemo(() => new K8sClient(config), [config])
37+
export function K8sProvider({ config, client, queryClient, children }: K8sProviderProps) {
38+
const resolved = useMemo(() => client ?? new K8sClient(config), [client, config])
3739
const qc = queryClient ?? defaultQueryClient
3840

3941
return (
4042
<QueryClientProvider client={qc}>
41-
<K8sClientContext.Provider value={client}>{children}</K8sClientContext.Provider>
43+
<K8sClientContext.Provider value={resolved}>{children}</K8sClientContext.Provider>
4244
</QueryClientProvider>
4345
)
4446
}

0 commit comments

Comments
 (0)