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

Remove duplicated code in ie_value.go #254

Merged
merged 1 commit into from
Sep 13, 2021

Conversation

srikartati
Copy link
Contributor

There is lot of repeated code. Base structure
can help in removing that.

@codecov
Copy link

codecov bot commented Sep 10, 2021

Codecov Report

Merging #254 (514b71f) into main (312d1b1) will increase coverage by 12.77%.
The diff coverage is 63.66%.

Impacted file tree graph

@@             Coverage Diff             @@
##             main     #254       +/-   ##
===========================================
+ Coverage   60.82%   73.60%   +12.77%     
===========================================
  Files          18       18               
  Lines        3158     2580      -578     
===========================================
- Hits         1921     1899       -22     
+ Misses       1037      532      -505     
+ Partials      200      149       -51     
Flag Coverage Δ
integration-tests 52.55% <53.33%> (+3.92%) ⬆️
unit-tests 72.13% <63.32%> (+12.50%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/exporter/process.go 54.47% <0.00%> (+3.19%) ⬆️
pkg/entities/ie_value.go 46.62% <47.40%> (+32.22%) ⬆️
pkg/entities/ie.go 52.91% <63.15%> (+3.24%) ⬆️
pkg/intermediate/aggregate.go 74.23% <97.72%> (+12.27%) ⬆️
pkg/kafka/producer/convertor/test/flowtype1.go 85.86% <100.00%> (+1.33%) ⬆️
pkg/kafka/producer/convertor/test/flowtype2.go 85.86% <100.00%> (+1.33%) ⬆️

antoninbas
antoninbas previously approved these changes Sep 10, 2021
Comment on lines +179 to +183
infoElem := &Unsigned8InfoElement{
value: val,
}
infoElem.element = element
return infoElem
Copy link
Contributor

Choose a reason for hiding this comment

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

How about writing it in this way:

return &Unsigned8InfoElement{
	value: val,
        element: element,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Embedded element cannot be accessed like that.

Comment on lines 216 to 217
func (u16 *Unsigned16InfoElement) GetUnsigned16Value() (uint16, error) {
return u16.value, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need to return error here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Not needed. The rest of the code that uses these get and set functions becomes simpler.

return false, fmt.Errorf("accessing value of wrong data type")
func (u16 *Unsigned16InfoElement) SetUnsigned16Value(val uint16) error {
u16.value = val
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

zyiou
zyiou previously approved these changes Sep 13, 2021
Copy link
Contributor

@zyiou zyiou 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. only one nit.

IsValueEmpty() bool
GetLength() int
ResetValue()
}

type Unsigned8InfoElement struct {
value uint8
type BaseInfoElement struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to make this type public? I didn't see it is used outside this package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not needed. Modified.

There is lot of repeated code. Base structure
can help in removing that.
Copy link
Contributor

@zyiou zyiou left a comment

Choose a reason for hiding this comment

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

LGTM

@srikartati srikartati merged commit 732060c into vmware:main Sep 13, 2021
@srikartati srikartati deleted the remove_code_duplication branch September 13, 2021 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants