generated from micronaut-projects/micronaut-project-template
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let the user choose a custom db name (#83)
* Let the user choose a custom db name Fixes #74 * Hardcode MongoDB image version This works around a breaking change in the latest image which isn't compatible with Testcontainers. See testcontainers/testcontainers-java#5774
- Loading branch information
Showing
4 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
MongoDB support will automatically start a https://www.mongodb.com[MongoDB container] and provide the value of the `mongodb.uri` property. | ||
|
||
The default image can be overwritten by setting the `test-resources.containers.mongodb.image-name` property. | ||
|
||
The default database name can be overwritten by setting the `test-resources.containers.mongodb.db-name` property. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...mongodb/src/test/groovy/io/micronaut/testresources/mongodb/CustomDbNameMongoDBTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.micronaut.testresources.mongodb | ||
|
||
import io.micronaut.context.annotation.Value | ||
import io.micronaut.test.extensions.spock.annotation.MicronautTest | ||
import jakarta.inject.Inject | ||
|
||
@MicronautTest(environments = ["test", "custom-db-name"]) | ||
class CustomDbNameMongoDBTest extends AbstractMongoDBSpec { | ||
|
||
@Inject | ||
BookRepository bookRepository | ||
|
||
@Value("\${mongodb.uri}") | ||
String mongodbUri | ||
|
||
def "automatically starts a MongoDB container"() { | ||
given: | ||
def book = new Book(title: "Micronaut for Spring developers") | ||
bookRepository.save(book) | ||
|
||
when: | ||
def books = bookRepository.findAll() | ||
|
||
then: | ||
books.size() == 1 | ||
|
||
and: | ||
mongodbUri.endsWith "/custom-db-name" | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
test-resources-mongodb/src/test/resources/application-custom-db-name.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
test-resources: | ||
containers: | ||
mongodb: | ||
db-name: custom-db-name |