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 using mocks to Go client #62

Conversation

valterfrancisco-dremio
Copy link
Contributor

@valterfrancisco-dremio valterfrancisco-dremio commented Dec 16, 2024

This PR restructures the Go Client code to use interfaces to improve modularity and to allow for more meaningful testing.

Changes:

  • Created GoFlightClient and RecordReader interfaces plus appropriate mock classes
  • Restructure example.go to use interfaces and separated main function into two classes to allow for testing
  • Add unit tests using mocks
  • Renamed original tests to integration tests

@valterfrancisco-dremio valterfrancisco-dremio marked this pull request as ready for review December 17, 2024 16:13
Copy link
Contributor

@howareyouman howareyouman left a comment

Choose a reason for hiding this comment

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

Please remove the generated mock file and verify that all the tests from example_integration_test are transferred to example_test.

go/example.go Outdated Show resolved Hide resolved
go/mock_flightclient.go Outdated Show resolved Hide resolved
go/example_integration_test.go Outdated Show resolved Hide resolved
go/example.go Outdated Show resolved Hide resolved
go/example.go Outdated Show resolved Hide resolved
go/example.go Outdated Show resolved Hide resolved
go/example.go Outdated Show resolved Hide resolved
Copy link

@cultcargo cultcargo left a comment

Choose a reason for hiding this comment

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

lgtm!

Copy link
Contributor

@howareyouman howareyouman left a comment

Choose a reason for hiding this comment

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

I'm ok with all the changes here.
There are some minor clues only, mostly stylistic.

go/interfaces/flight_config.go Outdated Show resolved Hide resolved
set -e

# Define variables
MOCKGEN_CMD="mockgen -destination=mock_flightclient.go -package=main github.com/apache/arrow-go/v18/arrow/flight Client"
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. Thanks for doing this! First step for basic automation in the repo!

go/implementations/mock_record_reader.go Show resolved Hide resolved

assert.Equal(t, tt.expected, strings.TrimSpace(buf.String()))
})
func TestUsernamePassAuth(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The tests are finally great and readable with mocks, thanks!

func run(config interfaces.FlightConfig, client flight.Client,
readerCreator func(flight.FlightService_DoGetClient) (RecordReader, error),
) error {

// Two WLM settings can be provided upon initial authentication with the dremio
// server flight endpoint:
// - routing-tag
// - routing-queue
ctx := metadata.NewOutgoingContext(context.TODO(),
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 have this somewhere in the docs?
In golang in general the context should be passed outside. For now it's fine to keep it here, but it would be great to add docs link where this is described.

@valterfrancisco-dremio valterfrancisco-dremio force-pushed the add-mock-tests-to-go-client branch from 859a810 to fb3fcaa Compare January 3, 2025 12:06
@valterfrancisco-dremio valterfrancisco-dremio merged commit 8ae3d9e into dremio-hub:main Jan 3, 2025
@valterfrancisco-dremio valterfrancisco-dremio deleted the add-mock-tests-to-go-client branch January 3, 2025 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants