Skip to content

Commit

Permalink
Run docker integration tests using testcontainers
Browse files Browse the repository at this point in the history
  • Loading branch information
hgeraldino committed Nov 10, 2021
1 parent 21cbd99 commit 886f612
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ on: pull_request_target
jobs:
test:
runs-on: ubuntu-latest
services:
mongodb:
image: mongo:3.2
ports:
- 27017:27017
steps:
- name: Checkout source code
uses: actions/checkout@v2
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ jobs:
name: "Stable Release"
runs-on: ubuntu-latest
environment: production
services:
mongodb:
image: mongo:3.2
ports:
- 27017:27017
steps:
- uses: actions/checkout@v2
with:
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies {

testCompile "org.codehaus.groovy:groovy-all:2.4.19"
testCompile "org.spockframework:spock-core:1.1-groovy-2.4"
testCompile "org.testcontainers:mongodb:1.16.0"
testRuntime "cglib:cglib-nodep:3.1"
testRuntime "org.objenesis:objenesis:2.1"

Expand Down
8 changes: 7 additions & 1 deletion src/funtest/groovy/support/MongoHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.mongodb.MongoClient
import com.mongodb.WriteConcern
import com.mongodb.client.MongoDatabase
import org.bson.types.ObjectId
import org.testcontainers.containers.MongoDBContainer
import org.testcontainers.utility.DockerImageName

import java.util.concurrent.atomic.AtomicLong

Expand All @@ -16,7 +18,11 @@ class MongoHelper {
static id = new AtomicLong()

static prepareDB(){
def mongo = new MongoClient()
def mongoDBContainer = new MongoDBContainer(DockerImageName.parse("mongo:3.2"))
mongoDBContainer.setPortBindings(["27017:27017"])

mongoDBContainer.start()
def mongo = new MongoClient(mongoDBContainer.getHost(), mongoDBContainer.getFirstMappedPort())
mongo.writeConcern = WriteConcern.UNACKNOWLEDGED
mongo.getDatabase("sdkman")
}
Expand Down

0 comments on commit 886f612

Please sign in to comment.