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

GODRIVER-2724 Move internal-only packages to "internal/" directories #1486

Merged
merged 16 commits into from
Dec 11, 2023

Conversation

prestonvasquez
Copy link
Collaborator

@prestonvasquez prestonvasquez commented Dec 2, 2023

GODRIVER-2724

Summary

Limit the surface area of the stable API by moving packages to the internal directory.

Background & Motivation

From the ticket description:

Currently, we have a lot of exported experimental APIs in the x/ directory and in some integration-test-only packages. Only a few of the APIs are used by internal teams (e.g. Atlas Proxy, ADL, etc) and none of them are intended for use by external users. However, because so many experimental APIs are exported, it’s difficult to understand the impact of changing some of those APIs. A better approach is to export the minimum possible surface area that still allows supporting internal Go driver users while minimizing confusion to external users and improving the Go Driver Team’s developer efficiency.

Copy link
Contributor

mongodb-drivers-pr-bot bot commented Dec 2, 2023

API Change Report

./benchmark

incompatible changes

package removed

./cmd/build-oss-fuzz-corpus

incompatible changes

package removed

./cmd/godriver-benchmark

incompatible changes

package removed

./cmd/parse-api-report

incompatible changes

package removed

./cmd/testatlas

incompatible changes

package removed

./cmd/testaws

incompatible changes

package removed

./cmd/testentauth

incompatible changes

package removed

./cmd/testkms

incompatible changes

package removed

./examples/documentation_examples

incompatible changes

package removed

./mongo/integration

incompatible changes

package removed

@prestonvasquez prestonvasquez changed the base branch from v1 to master December 4, 2023 16:40
@prestonvasquez prestonvasquez marked this pull request as ready for review December 4, 2023 19:02
@prestonvasquez prestonvasquez requested a review from a team as a code owner December 4, 2023 19:02
@prestonvasquez prestonvasquez requested review from matthewdale and removed request for a team December 4, 2023 19:02
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to update the oss-fuzz integration when we make this change?

Copy link
Collaborator Author

@prestonvasquez prestonvasquez Dec 6, 2023

Choose a reason for hiding this comment

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

We will need to create a mongo-v2 project on the oss-fuzz repo, the ticket for this is here: https://jira.mongodb.org/browse/GODRIVER-3064

I don't think we need to make a change in our repository. This line should change on the oss-fuzz repo to

go run internal/test/build-oss-fuzz-corpus/main.go $OUT/fuzz_decode_seed_corpus.zip

Copy link
Collaborator

Choose a reason for hiding this comment

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

The directory organization is inconsistent between main packages. For example, this package is in internal/test, but other main packages are in internal/test/cmd.

Conventionally, main package Go files are in a path like cmd/[binary name]/[Go files]. In this case, we're putting these in an internal directory, so the directory structure should be internal/cmd/[binary name]/[Go files].

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I agree with this. I originally separated it because we don't actually compile a usable binary from godriver-benchmark, as we do with all of the other package in cmd. We compile and execute it using go run, here.

What are your thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

go run is just a shortcut for "compile a binary and then run it", so it is fundamentally the same thing. A main package is always built and run as an executable binary, so main packages should always be in an internal/cmd directory.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional: The test directory seems redundant here. Consider moving it to internal/integration or the existing internal/integtest package.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am fine with either solution, but it is kind of nice to seperate code that is intended to test the driver against logic depended on by the driver.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional: The integration package really has two kinds of code:

  1. Integration tests for the driver in the _test.go files.
  2. Integration test logic, including the unified spec test runner, in the non-_test.go files.

One option is to move all of the _test.go files into the mongo directory and change the package declaration to package mongo_test (instead of package mongo) so that they don't have access to unexported logic. You can optionally rename them to _integ_test.go or something similar to indicate they are integration tests. That would localize all tests to the same directory so they're not as scattered around.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've create GODRIVER-3066 to followup on this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Moving the unified spec test runner logic into an internal directory will break the integration in drivers-atlas-testing. We'll need a follow-up change to fix that integration once this is merged.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh interesting, good catch. I've created GODRIVER-3065 to address this.

Copy link
Collaborator

@matthewdale matthewdale left a comment

Choose a reason for hiding this comment

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

Looks good! 👍

@prestonvasquez prestonvasquez merged commit b15aa4c into mongodb:master Dec 11, 2023
35 of 37 checks passed
@prestonvasquez prestonvasquez deleted the GODRIVER-2724 branch December 11, 2023 22:53
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.

2 participants