Skip to content

Conversation

elevran
Copy link
Contributor

@elevran elevran commented Jul 21, 2025

Add base unit tests to all files under the datalayer.

Copy link

netlify bot commented Jul 21, 2025

Deploy Preview for gateway-api-inference-extension ready!

Name Link
🔨 Latest commit 5bc90f5
🔍 Latest deploy log https://app.netlify.com/projects/gateway-api-inference-extension/deploys/6885df8cf7cd660008846c43
😎 Deploy Preview https://deploy-preview-1195--gateway-api-inference-extension.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 21, 2025
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 21, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @elevran. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jul 21, 2025
@nirrozenbaum
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 21, 2025
Put(string, Cloneable)
Get(string) (Cloneable, bool)
Keys() []string
Clone() *Attributes
Copy link
Contributor

Choose a reason for hiding this comment

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

not related to this PR -
do we want to support in the future also Delete operation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could, mostly for completeness, but I don't currently see a use case to remove an attribute from an endpoint.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 21, 2025
Copy link
Contributor

@nirrozenbaum nirrozenbaum left a comment

Choose a reason for hiding this comment

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

overall LGTM.
I left few minor comments.

Comment on lines +44 to +45
dv, ok := got.(*dummy)
assert.True(t, ok, "expected value to be of type *dummy")
assert.Equal(t, "foo", dv.Text)
Copy link
Contributor

Choose a reason for hiding this comment

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

use cmp.diff?

Copy link
Contributor Author

@elevran elevran Jul 27, 2025

Choose a reason for hiding this comment

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

Prefer to use assert.Equal for basic types and leave cmp.Diff for slices, maps and complex structs.
Changed to cmp.Diff throughout

Comment on lines 55 to 63
assert.Len(t, keys, 2)

found := map[string]bool{}
for _, k := range keys {
found[k] = true
}

assert.True(t, found["x"])
assert.True(t, found["y"])
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of these lines, use:
expected:= []string{"x", "y"} and cmp.Diff?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this would need to assume that order is fixed and matches or that we sort the keys. Not sure about sync,Map but map.Keys() order is intentionally randomized.
I think it is more work for this use.
Changed to use assert.ElementsMatch which seems more aligned.

Comment on lines +52 to 57
var defaultDataSources = DataSourceRegistry{}

// DataSourceRegistry stores named data sources and makes them
// accessible to other subsystems in the inference gateway.
// DataSourceRegistry stores named data sources.
type DataSourceRegistry struct {
sources sync.Map
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we actually need DataSourceRegistry struct?

what would be different if we define defaultDataSources = sync.Map and move logic from the struct functions to the public functions?

Copy link
Contributor Author

@elevran elevran Jul 27, 2025

Choose a reason for hiding this comment

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

it makes testing (and especially parallel tests) much easier since there's no global state that needs to be synchronized between tests as each can use its own registry struct if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nirrozenbaum since tests moved to the datalayer package, I could make DataSourceRegistry private if you think that would make it clearer.

assert.Equal(t, podinfo, clone)
assert.NotSame(t, podinfo, clone)
assert.Equal(t, podinfo.Labels, clone.Labels)
clone.Labels["env"] = "staging"
Copy link
Contributor

Choose a reason for hiding this comment

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

testing that field change in clone doesn't change the original item was already tested in a different place. do you expect every clonable to test it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in principle, that would be the prudent thing to do as long as implementation of Clone() is not automated.
Need to ensure that slices, maps, pointers are not copied as-is to the clone but their values are.

elevran added 4 commits July 27, 2025 10:22
Signed-off-by: Etai Lev Ran <elevran@gmail.com>
Signed-off-by: Etai Lev Ran <elevran@gmail.com>
Signed-off-by: Etai Lev Ran <elevran@gmail.com>
Signed-off-by: Etai Lev Ran <elevran@gmail.com>
@elevran elevran force-pushed the datalayer_unit_test branch from 34dc3db to 5bc90f5 Compare July 27, 2025 08:12
@elevran elevran requested a review from nirrozenbaum July 27, 2025 08:14
@nirrozenbaum
Copy link
Contributor

/lgtm
/approve

Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 28, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: elevran, nirrozenbaum

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 28, 2025
@k8s-ci-robot k8s-ci-robot merged commit b3af7a3 into kubernetes-sigs:main Jul 28, 2025
9 checks passed
@elevran elevran deleted the datalayer_unit_test branch July 29, 2025 09:14
kfswain pushed a commit to kfswain/llm-instance-gateway that referenced this pull request Jul 31, 2025
* added unit tests

Signed-off-by: Etai Lev Ran <elevran@gmail.com>

* lint fix

Signed-off-by: Etai Lev Ran <elevran@gmail.com>

* simplify tests by removing redundant and using

Signed-off-by: Etai Lev Ran <elevran@gmail.com>

* changed to use cmp.Diff where appropriate

Signed-off-by: Etai Lev Ran <elevran@gmail.com>

---------

Signed-off-by: Etai Lev Ran <elevran@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants