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

CopyTo works incorrectly in some cases #670

Open
cthulhu-rider opened this issue Dec 12, 2024 · 1 comment
Open

CopyTo works incorrectly in some cases #670

cthulhu-rider opened this issue Dec 12, 2024 · 1 comment
Labels
bug Something isn't working I4 No visible changes S4 Routine U3 Regular
Milestone

Comments

@cthulhu-rider
Copy link
Contributor

cthulhu-rider commented Dec 12, 2024

CopyTo is provided by several complex struct types. It allows to deep-copy instance for safety

Current Behavior

Container.CopyTo keeps dst attributes when src has none. If dst already had some attributes, resulting copy is incorrect

this could be missed in 2 reasons:

  • CopyTo is rarely used
  • dst is usually zero: np in this case

Expected Behavior

correct deep copy

Possible Solution

just do it

Steps to Reproduce

func TestCopyReset(t *testing.T) {
	var src, dst Container
	dst.SetAttribute("key", "val")
	src.CopyTo(&dst)
	require.Zero(t, dst.Attribute("key"))
}

Context

maybe there are other cases, review all of them. To force this, i suggest to pre-add corresponding unit tests

Regression

no (at least for noticed case)

Your Environment

  • Version of the product used: 0b9bb74
@cthulhu-rider cthulhu-rider added the bug Something isn't working label Dec 12, 2024
@cthulhu-rider
Copy link
Contributor Author

session.Container/Object have similar error in Unmarshal(JSON: context fields aint reset

func TestResetContext(t *testing.T) {
	var c session.Container
	c.ForVerb(1)
	require.True(t, c.AssertVerb(1))
	
	require.NoError(t, c.Unmarshal(nil))
	require.False(t, c.AssertVerb(1))
}

in total, i suggest to add unit tests for resetting a previously set value for the following methods:

  1. CopyTo
  2. ReadFromV2 (future FromProtoMessage)
  3. Unmarshal
  4. UnmarshalJSON

in particular cases, this can be already covered. Example

once all tests are done, some cases incl. mentioned here will FAIL. And then fix

@roman-khimov roman-khimov added this to the v1.0.0-rc13 milestone Dec 12, 2024
@roman-khimov roman-khimov added U3 Regular S4 Routine I4 No visible changes labels Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working I4 No visible changes S4 Routine U3 Regular
Projects
None yet
Development

No branches or pull requests

2 participants