Skip to content

test(core): add fake kube dynamic client; add Core resources testing …#1042

Open
difrost wants to merge 2 commits into
containers:mainfrom
difrost:test-core-fake-client
Open

test(core): add fake kube dynamic client; add Core resources testing …#1042
difrost wants to merge 2 commits into
containers:mainfrom
difrost:test-core-fake-client

Conversation

@difrost
Copy link
Copy Markdown
Contributor

@difrost difrost commented Apr 14, 2026

This PR adds:

  • a fake dynamic client build on top of k8s.io/client-go/dynamic/fake.FakeDynamicClient;
  • kubernetes.Interface that embeds the k8s.io/client-go/kubernetes/fake.Clientset;
  • no-op Reset() RESTMapper() pre-configured with GVR->GVK mappings;
  • DiscoveryClient() - fake clientset's discovery wrapped in memory.NewMemCacheClient, with APIResources populated to match registered GVRs;
  • tests using fake client to exercise ResourcesGet, ResourcesList, ResourcesDelete, ResourcesScale and ResourcesCreateOrUpdate.

The dryRun feature that is proposed under #1026 can't be tested as fake client - currently - ignores opts.

Note: To avoid importing type packages (and use an empty scheme) this is using fake.NewSimpleDynamicClientWithCustomListKinds instead of fake.NewSimpleDynamicClient.

…using fake client

Signed-off-by: Jacek Luczak <difrost.kernel@gmail.com>

result, err := core.ResourcesScale(ctx(), &schema.GroupVersionKind{
Group: "apps", Version: "v1", Kind: "Deployment",
}, "default", "my-deploy", 0, false)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

desiredScale=0 and shouldScale=false means that update/write is not tested

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test was correct - intended check with shouldScale=false. Updated with missing parts: 1e9551c

…ath test

Signed-off-by: Jacek Luczak <difrost.kernel@gmail.com>
@difrost difrost requested a review from matzew April 21, 2026 11:46
@difrost
Copy link
Copy Markdown
Contributor Author

difrost commented May 4, 2026

@Cali0707 / @manusa / @matzew - does this makes any sense or should I close that one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants