Skip to content
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

fake: fix delete element from map operation. #13

Merged

Conversation

npinaeva
Copy link
Member

@npinaeva npinaeva commented Jul 5, 2024

On delete map element value is not required.
Fix unit test reference to the stale table. fake.Table is a new object after every transaction, so after each Run() it should be re-assigned.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 5, 2024
@k8s-ci-robot k8s-ci-robot requested review from aojea and danwinship July 5, 2024 09:39
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jul 5, 2024
fake.go Outdated
@@ -351,7 +351,7 @@ func (fake *Fake) run(tx *Transaction) (*FakeTable, error) {
return nil, fmt.Errorf("unhandled operation %q", op.verb)
}
case *Element:
if len(obj.Value) == 0 {
if len(obj.Set) != 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd usually say:

Suggested change
if len(obj.Set) != 0 {
if obj.Set != "" {

(because you don't care about the length, you care about whether it's set/unset.)

fake_test.go Outdated
@@ -243,7 +243,7 @@ func TestFakeRun(t *testing.T) {
}

// Neither element should have been added
m = table.Maps["map1"]
m = fake.Table.Maps["map1"]
if m == nil || len(table.Maps) != 1 {
t.Fatalf("unexpected contents of table.Maps: %+v", table.Maps)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We still end up referring to the stale table value in both of the lines above.

You should probably get rid of the table variable altogether.

}
m = fake.Table.Maps["map1"]
if len(m.Elements) != 1 {
t.Errorf("unexpected contents of map1: %+v", m)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If there's not already an Element deletion test then it would be good to check that we actually deleted the right element too (either do a FindElement on the deleted element and ensure it fails or on the remaining element and ensure it doesn't fail).

On delete map element value is not required.
Fix unit test reference to the stale table. fake.Table is a new object
after every transaction, so after each Run() it should be re-assigned.

Signed-off-by: Nadia Pinaeva <n.m.pinaeva@gmail.com>
@npinaeva npinaeva force-pushed the fix-fake-delete-element branch from b6373cf to 8da7cec Compare July 8, 2024 13:36
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 8, 2024
@danwinship
Copy link
Collaborator

/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 Jul 10, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: danwinship, npinaeva

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 10, 2024
@k8s-ci-robot k8s-ci-robot merged commit c2bd3a9 into kubernetes-sigs:master Jul 10, 2024
5 checks passed
@npinaeva npinaeva deleted the fix-fake-delete-element branch July 10, 2024 14:16
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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants