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

[#21384] Increase sql package test coverage from 35% to 70% #33711

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dev-mohit06
Copy link

PR Summary:

This PR addresses #21384 by adding comprehensive unit tests to the sql package, increasing the code coverage from 35% to 75%. The following test cases have been added:

  • TestOutputType: Tests output type handling with and without components.
  • TestTransform: Ensures proper validation of required options.
  • TestMultipleOptions: Verifies that multiple options can be applied correctly.

Testing:

  • All tests pass locally.
  • Code coverage has increased from 35% to 75%.
  • Tests adhere to the existing codebase style and conventions.
  • Proper documentation and comments have been added for the test functions.

Checklist:

Additional Notes:

  • The tests focus on configuration and option-setting functionality.
  • The TestTransform tests validate the required options without needing the expansion service.
  • Tests follow the established test patterns in the codebase.

Screenshots:

  • Coverage Output:
    Coverage Output

  • Coverage.out File:
    Coverage Out File

  • Test Cases Passing Locally:
    Test Cases Passing

@github-actions github-actions bot added the go label Jan 22, 2025
Copy link
Contributor

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @lostluck for label go.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@dev-mohit06 dev-mohit06 changed the title [#21384] Increase sql package test coverage from 35% to 75% [#21384] Increase sql package test coverage from 35% to 70% Jan 22, 2025
@dev-mohit06
Copy link
Author

@lostluck Can you please review and merge it to the repo?

Copy link
Contributor

@lostluck lostluck left a comment

Choose a reason for hiding this comment

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

Thank you very much Mohit! This is wonderful. I do have some style and consistency comments however. It's a good rule of thumb to not introduce a wildly different style to a codebase within a given language, as it makes it harder to work in.

What you have here is good, but it can be better (though you might need to do a bit of reading first).

@Use: This test ensures that the OutputType option behaves as expected
when used in SQL transformations.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

In Go, we use // for doc comment blocks, not /* */. In particular, multi-line comments are generally used sparingly, such as it would make a copy paste of some command simpler. Please change this for consistency with the rest of the project.

Please also remove the @ blocked lines, they either repeat the initial test description, or don't add anything. It's also not the Apache Way to take credit for any given block of code in the files themselves. That is sufficiently tracked via this commit existing attached to your Github profile, and the resulting blame lines pointing to it once it is merged in.

The same applies to all blocks below.

See https://google.github.io/styleguide/go/decisions#package-comments generally for package comments.

typ := reflect.TypeOf(int64(0))
components := []typex.FullType{typex.New(reflect.TypeOf(""))}

// Test without components
Copy link
Contributor

Choose a reason for hiding this comment

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

In go, prefer using Table Tests instead of single test bodies with comments for each test case.

See https://google.github.io/styleguide/go/decisions#table-driven-tests specifically, and https://google.github.io/styleguide/go/decisions#test-structure more generally.

opt1 := OutputType(typ)
opt1(o)
expected1 := typex.New(typ)
if !reflect.DeepEqual(o.outType, expected1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer to use cmp.Equal or cmp.Diff instead of reflect.DeepEqual. Consider printing the diff, which will be a clearer description of the issue.

See https://google.github.io/styleguide/go/decisions#print-diffs


// Verify all fields
if _, ok := o.inputs[name]; !ok {
t.Error("Input option not applied correctly")
Copy link
Contributor

Choose a reason for hiding this comment

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

Test output is much better when the input, both the received and the expected outputs are included in the test message.

"Input option with name %q, not applied correctly: got %v, want %v", name, got, want"

And similar.

See also https://mtlynch.io/if-got-want-improve-go-tests/ which is an excellent approach for this sort of thing too.

@dev-mohit06
Copy link
Author

@lostluck, thank you for telling me. As I am learning Go, I will improve myself and make the changes you mentioned above.

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.

Add unit tests to the sql package
2 participants