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

Increasing test coverage #401

Merged
merged 2 commits into from
Mar 9, 2023
Merged

Increasing test coverage #401

merged 2 commits into from
Mar 9, 2023

Conversation

jotak
Copy link
Member

@jotak jotak commented Mar 7, 2023

  • k8s enrichment
  • convert utils

@openshift-ci
Copy link

openshift-ci bot commented Mar 7, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from jotak. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@codecov
Copy link

codecov bot commented Mar 7, 2023

Codecov Report

Merging #401 (3c29de1) into main (9740aa3) will increase coverage by 2.21%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #401      +/-   ##
==========================================
+ Coverage   61.45%   63.67%   +2.21%     
==========================================
  Files          91       92       +1     
  Lines        6393     6467      +74     
==========================================
+ Hits         3929     4118     +189     
+ Misses       2226     2109     -117     
- Partials      238      240       +2     
Flag Coverage Δ
unittests 63.67% <100.00%> (+2.21%) ⬆️

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

Impacted Files Coverage Δ
...g/pipeline/transform/kubernetes/kubernetes-mock.go 100.00% <100.00%> (ø)
pkg/operational/metrics.go 67.10% <0.00%> (-0.90%) ⬇️
pkg/pipeline/encode/encode_prom.go 77.72% <0.00%> (-0.06%) ⬇️
pkg/config/config.go 63.33% <0.00%> (ø)
pkg/api/encode_prom.go 100.00% <0.00%> (ø)
cmd/flowlogs-pipeline/main.go 0.00% <0.00%> (ø)
pkg/pipeline/utils/prom_server.go 0.00% <0.00%> (ø)
pkg/confgen/flowlogs2metrics_config.go 68.83% <0.00%> (+0.83%) ⬆️
pkg/pipeline/extract/timebased/heap.go 100.00% <0.00%> (+2.17%) ⬆️
pkg/pipeline/transform/kubernetes/kubernetes.go 19.36% <0.00%> (+11.46%) ⬆️
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

- k8s enrichment
- convert utils
Copy link
Collaborator

@ronensc ronensc left a comment

Choose a reason for hiding this comment

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

Thanks for this PR!
And sorry for not adding these tests myself... 😳

Comment on lines 50 to 60
func (indexMock *IndexerMock) GetByKey(key string) (interface{}, bool, error) {
args := indexMock.Called(key)
return args.Get(0), args.Bool(1), args.Error(2)
}

func (informerMock *InformerMock) GetIndexer() cache.Indexer {
args := informerMock.Called()
return args.Get(0).(cache.Indexer)
}

func TestGetInfoPods(t *testing.T) {
kubeData := KubeData{}
// pods informer
pidx := IndexerMock{}
pidx.On("ByIndex", IndexIP, "1.2.3.4").Return([]interface{}{&Info{
func (m *IndexerMock) mockPod(ip, name, namespace, nodeIP string, owner *Owner) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is inconsistency in the receiver variable name of *IndexerMock. Sometimes it's indexMock and sometimes it's m. I think it'll make sense to rename the instances of indexMock to m (or vice versa).

@@ -47,50 +47,161 @@ func (indexMock *IndexerMock) ByIndex(indexName, indexedValue string) ([]interfa
return args.Get(0).([]interface{}), args.Error(1)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see there is a kubernetes-mock.go file. Would it make sense to move the mocks defined in this file to that file?

}}
for _, tc := range cases {
tc := tc
t.Run(fmt.Sprintf("%t", tc.input), func(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

%t prints the word true or false. Perhaps %T was meant here? (%T prints a Go-syntax representation of the type of the value)
Reference:
https://pkg.go.dev/fmt#hdr-Printing

Copy link
Member Author

Choose a reason for hiding this comment

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

oops good catch ... for some reason it wasn't writing true/false, but the some garbage AND the type so I didn't pay much attention

"github.com/stretchr/testify/assert"
)

func TestConvertToFloat64(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this tests other functions besides ConvertToFloat64(), I would rename it to something like TestConvertToNumericTypes()

wanti: 1,
}, {
input: "1",
wantf64: 1,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is wantf64 equal to 1 and not equal to 1.0?

wanti: 42,
}}
for _, tc := range cases {
tc := tc
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this line contribute?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's not really useful unless we make tests run in parallel at some point (it captures the variable in the more narrow scope). I can remove it

@jotak
Copy link
Member Author

jotak commented Mar 8, 2023

thanks @ronensc - feedback should be addressed

@openshift-ci openshift-ci bot added the lgtm label Mar 9, 2023
@jotak jotak added no-qe This PR doesn't necessitate QE approval no-doc This PR doesn't require documentation change on the NetObserv operator labels Mar 9, 2023
@jotak jotak merged commit 0269dcc into netobserv:main Mar 9, 2023
@ronensc ronensc mentioned this pull request Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm no-doc This PR doesn't require documentation change on the NetObserv operator no-qe This PR doesn't necessitate QE approval
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants