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

Add unit tests in cmd/jaeger/internal #5069

Merged
merged 17 commits into from
Jan 19, 2024

Conversation

akagami-harsh
Copy link
Member

Which problem is this PR solving?

Description of the changes

  • added missing unit test in cmd/jeager/internal and also added a goroutine check for that package

How was this change tested?

  • go test

Checklist

@akagami-harsh akagami-harsh requested a review from a team as a code owner January 3, 2024 07:31
Copy link

github-actions bot commented Jan 3, 2024

Test Results

2 075 tests  +4   2 065 ✅ +4   1m 9s ⏱️ -1s
  216 suites ±0      10 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 00ba765. ± Comparison against base commit 1c0a6ca.

♻️ This comment has been updated with latest results.

Signed-off-by: Harshvir Potpose <[email protected]>
Copy link

codecov bot commented Jan 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (1c0a6ca) 95.58% compared to head (00ba765) 95.59%.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #5069    +/-   ##
========================================
  Coverage   95.58%   95.59%            
========================================
  Files         320      322     +2     
  Lines       18347    18454   +107     
========================================
+ Hits        17537    17641   +104     
- Misses        651      653     +2     
- Partials      159      160     +1     
Flag Coverage Δ
cassandra-3.x 25.58% <ø> (ø)
cassandra-4.x 25.58% <ø> (ø)
elasticsearch-5.x 19.87% <ø> (ø)
elasticsearch-6.x 19.87% <ø> (ø)
elasticsearch-7.x 20.00% <ø> (ø)
elasticsearch-8.x 20.08% <ø> (-0.02%) ⬇️
grpc-badger 19.52% <ø> (+0.01%) ⬆️
kafka 14.09% <ø> (ø)
opensearch-1.x 20.00% <ø> (ø)
opensearch-2.x 20.00% <ø> (ø)
unittests 93.28% <100.00%> (+0.02%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@akagami-harsh
Copy link
Member Author

i tried adding this test in command_test.go

func TestCommandNoConfigFlag(t *testing.T) {
	cmd := Command()

	cmd.SetArgs([]string{})

	err := cmd.Execute()
	require.Error(t, err, "Expected an error when no config flag is provided")
	assert.Contains(t, err.Error(), "some error related to missing config", "Error message should indicate missing configuration")
}

to increase code coverage, but it was failing goleak somehow.

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

to increase code coverage, but it was failing goleak somehow.

you can investigate which ones are leaking. In the current test you don't even run the command, so it's surprising that it leaks, but to actually achieve code coverage you will need to execute the command.

cmd/jaeger/internal/command_test.go Outdated Show resolved Hide resolved
Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

$ go test -cover ./cmd/jaeger/internal/
ok  	github.com/jaegertracing/jaeger/cmd/jaeger/internal	0.434s	coverage: 60.0% of statements

Package coverage needs to be at the level of overall project (95%+).

The code in command.go can be tested if L42 is moved to a function that can be called from a test directly and substitute cmd.RunE

Signed-off-by: Harshvir Potpose <[email protected]>
Signed-off-by: Harshvir Potpose <[email protected]>
Signed-off-by: Harshvir Potpose <[email protected]>
@yurishkuro yurishkuro added the changelog:test Change that's adding missing tests or correcting existing tests label Jan 17, 2024
Signed-off-by: Harshvir Potpose <[email protected]>
Signed-off-by: Harshvir Potpose <[email protected]>
Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

What's remaining is the error paths in the components() function. The way to test them is to add a helper function that takes a bunch of functions that components() currently calls, like extension.MakeFactoryMap, etc., and mock them in the test to return errors one at a time.

cmd/jaeger/internal/command_test.go Outdated Show resolved Hide resolved
cmd/jaeger/internal/command_test.go Show resolved Hide resolved
cmd/jaeger/internal/command_test.go Outdated Show resolved Hide resolved
akagami-harsh and others added 5 commits January 18, 2024 12:26
Co-authored-by: Yuri Shkuro <[email protected]>
Signed-off-by: Harshvir Potpose <[email protected]>
Co-authored-by: Yuri Shkuro <[email protected]>
Signed-off-by: Harshvir Potpose <[email protected]>
Signed-off-by: Harshvir Potpose <[email protected]>
Signed-off-by: Harshvir Potpose <[email protected]>
Signed-off-by: Harshvir Potpose <[email protected]>
return func(factories ...FACTORY) (map[component.Type]FACTORY, error) {
return nil, err
}
}
Copy link
Member

Choose a reason for hiding this comment

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

use template to remove duplication

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

Awesome! I did small refactoring of the components() tests to DRY them

@yurishkuro yurishkuro enabled auto-merge (squash) January 19, 2024 00:26
@yurishkuro yurishkuro merged commit 88efe47 into jaegertracing:main Jan 19, 2024
39 checks passed
@akagami-harsh akagami-harsh deleted the add-tests branch January 19, 2024 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:test Change that's adding missing tests or correcting existing tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants