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

MongoDB example #723

Merged
merged 3 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/mongodb-example.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Mongodb example pipeline
name: MongoDB example pipeline
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a good point, as the generator does not distinguish this notation including initials. I'll take a note to include a way to provide a variant that overrides the titled names

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, anyway, great work on the generator. It saves a lot of time 💪


on: [push, pull_request]

Expand Down
6 changes: 3 additions & 3 deletions docs/examples/mongodb.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Mongodb
# MongoDB

<!--codeinclude-->
[Creating a Mongodb container](../../examples/mongodb/mongodb.go)
[Creating a MongoDB container](../../examples/mongodb/mongodb.go)
<!--/codeinclude-->

<!--codeinclude-->
[Test for a Mongodb container](../../examples/mongodb/mongodb_test.go)
[Test for a MongoDB container](../../examples/mongodb/mongodb_test.go)
<!--/codeinclude-->
4 changes: 2 additions & 2 deletions examples/mongodb/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ type mongodbContainer struct {
testcontainers.Container
}

// setupMongodb creates an instance of the mongodb container type
func setupMongodb(ctx context.Context) (*mongodbContainer, error) {
// setupMongoDB creates an instance of the mongodb container type
func setupMongoDB(ctx context.Context) (*mongodbContainer, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Were you able to take a look at the Java implementation, or do you think this simple example is enough?

Copy link
Collaborator

Choose a reason for hiding this comment

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

In any case, this LGTM. I'll merge it as is and we can iterate and evolve the example in follow ups, if you are interested

Copy link
Contributor Author

@ravilushqa ravilushqa Jan 4, 2023

Choose a reason for hiding this comment

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

I have a look into Java implementation, looks like it's supports replica set that looks like for me as an option. I doesn't need it, and I believe if someone will need it, it could be added as an option, as container option.
From my perspective it is good enough, as it just works and doesn't require overcomplicating it at this stage.

If we will add these rows below test, it will work, and this is most common usecase for tests, just perform operations

res, err := mongoClient.Database("test").Collection("test").InsertOne(ctx, bson.M{"test": "test"})
if err != nil {
	t.Fatal(fmt.Errorf("error inserting document into mongo: %w", err))
}

if res.InsertedID == nil {
	t.Fatal("expected InsertedID to not be nil")
}

wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good to me 👏

req := testcontainers.ContainerRequest{
Image: "mongo:6",
ExposedPorts: []string{"27017/tcp"},
Expand Down
4 changes: 2 additions & 2 deletions examples/mongodb/mongodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"go.mongodb.org/mongo-driver/mongo/options"
)

func TestMongodb(t *testing.T) {
func TestMongoDB(t *testing.T) {
ctx := context.Background()

container, err := setupMongodb(ctx)
container, err := setupMongoDB(ctx)
if err != nil {
t.Fatal(err)
}
Expand Down