Skip to content

KEP-4222: Add tests for CBOR encoder handling of duplicate field names/tags. #123626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

benluddy
Copy link
Contributor

@benluddy benluddy commented Mar 1, 2024

What type of PR is this?

/kind cleanup
/sig api-machinery

What this PR does / why we need it:

Add tests for CBOR encoder handling of duplicate field names/tags.

Specifically, these cases provide coverage for unusual struct types that could conceivably be encoded to CBOR maps containing duplicate keys (which would be invalid).

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

- [KEP]: https://kep.k8s.io/4222

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Mar 1, 2024
@k8s-ci-robot k8s-ci-robot requested review from sttts and wojtek-t March 1, 2024 22:32
@benluddy benluddy force-pushed the cbor-test-encode-no-duplicate-map-key branch from b958283 to f7567fc Compare March 5, 2024 19:50
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 5, 2024
@benluddy
Copy link
Contributor Author

benluddy commented Mar 5, 2024

Added parallel test cases for the JSON serializer as the CBOR behavior is also based on the behavior of encoding/json:

The Go visibility rules for struct fields are amended for JSON when deciding which field to marshal or unmarshal. If there are multiple fields at the same level, and that level is the least nested (and would therefore be the nesting level selected by the usual Go rules), the following extra rules apply:

  1. Of those fields, if any are JSON-tagged, only tagged fields are considered, even if there are multiple untagged fields that would otherwise conflict.

  2. If there is exactly one field (tagged or not according to the first rule), that is selected.

  3. Otherwise there are multiple fields, and all are ignored; no error occurs.

@deads2k
Copy link
Contributor

deads2k commented Mar 5, 2024

🤯

@benluddy
Copy link
Contributor Author

benluddy commented Mar 5, 2024

/retest-required

@jiahuif
Copy link
Member

jiahuif commented Mar 12, 2024

/assign @deads2k
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Mar 12, 2024
@deads2k
Copy link
Contributor

deads2k commented Mar 13, 2024

/lgtm
/approve

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

LGTM label has been added.

Git tree hash: 9229a4db4496fae369c46604eecfda4734204c80

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: benluddy, deads2k

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 Mar 13, 2024
@benluddy benluddy force-pushed the cbor-test-encode-no-duplicate-map-key branch from f7567fc to 592043c Compare April 3, 2024 22:02
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 3, 2024
@k8s-ci-robot k8s-ci-robot requested a review from deads2k April 3, 2024 22:02
@benluddy benluddy force-pushed the cbor-test-encode-no-duplicate-map-key branch from 592043c to e8c0c24 Compare April 4, 2024 15:45
@benluddy benluddy force-pushed the cbor-test-encode-no-duplicate-map-key branch from e8c0c24 to 8df914a Compare April 4, 2024 15:55
@deads2k
Copy link
Contributor

deads2k commented Apr 22, 2024

/lgtm

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

LGTM label has been added.

Git tree hash: 20a30ecf6866c2d2126fcbc81f8ba1f11a185c8c

@k8s-ci-robot k8s-ci-robot merged commit e2bd80a into kubernetes:master Apr 22, 2024
14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.31 milestone Apr 22, 2024
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. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants