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

pdatagen - Add MoveTo method for struct types #4240

Merged
merged 6 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions model/internal/cmd/pdatagen/internal/base_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ func new${structName}(orig *${originName}) ${structName} {
// This must be used only in testing code since no "Set" method available.
func New${structName}() ${structName} {
return new${structName}(&${originName}{})
}

// MoveTo moves all properties from the current struct to dest
// reseting the current instance to its zero value
func (ms ${structName}) MoveTo(dest ${structName}) {
*dest.orig = *ms.orig
*ms.orig = ${originName}{}
}`

const messageValueCopyToHeaderTemplate = `// CopyTo copies all properties from the current struct to the dest.
Expand All @@ -48,6 +55,14 @@ func (ms ${structName}) CopyTo(dest ${structName}) {`
const messageValueCopyToFooterTemplate = `}`

const messageValueTestTemplate = `
func Test${structName}_MoveTo(t *testing.T) {
ms := generateTest${structName}()
dest := New${structName}()
ms.MoveTo(dest)
assert.EqualValues(t, New${structName}(), ms)
assert.EqualValues(t, generateTest${structName}(), dest)
}

func Test${structName}_CopyTo(t *testing.T) {
ms := New${structName}()
generateTest${structName}().CopyTo(ms)
Expand Down
7 changes: 7 additions & 0 deletions model/pdata/generated_common.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions model/pdata/generated_common_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions model/pdata/generated_log.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions model/pdata/generated_log_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 105 additions & 0 deletions model/pdata/generated_metrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading