-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,479 additions
and
115 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
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
17 changes: 17 additions & 0 deletions
17
core/src/main/scala/com/dimafeng/testcontainers/ContainerDef.scala
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,17 @@ | ||
package com.dimafeng.testcontainers | ||
|
||
import com.dimafeng.testcontainers.lifecycle.Stoppable | ||
import org.testcontainers.lifecycle.Startable | ||
|
||
trait ContainerDef { | ||
|
||
type Container <: Startable with Stoppable | ||
|
||
protected def createContainer(): Container | ||
|
||
def start(): Container = { | ||
val container = createContainer() | ||
container.start() | ||
container | ||
} | ||
} |
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
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
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
46 changes: 46 additions & 0 deletions
46
core/src/main/scala/com/dimafeng/testcontainers/lifecycle/Stoppable.scala
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,46 @@ | ||
package com.dimafeng.testcontainers.lifecycle | ||
|
||
trait Stoppable extends AutoCloseable with Andable { | ||
|
||
def stop(): Unit | ||
|
||
override def close(): Unit = stop() | ||
} | ||
|
||
/** | ||
* Gives you a possibility to write `container1 and container2`. | ||
* | ||
* Used for tests DSL. | ||
*/ | ||
sealed trait Andable { | ||
|
||
def stop(): Unit | ||
|
||
def foreach(f: Stoppable => Unit): Unit = { | ||
this match { | ||
case and(head, tail) => | ||
head.foreach(f) | ||
tail.foreach(f) | ||
|
||
case stoppable: Stoppable => | ||
f(stoppable) | ||
} | ||
} | ||
|
||
} | ||
final case class and[A1 <: Andable, A2 <: Andable](head: A1, tail: A2) extends Andable { | ||
|
||
/** | ||
* Stopping all Andable elements in the reverse order | ||
*/ | ||
override def stop(): Unit = { | ||
tail.stop() | ||
head.stop() | ||
} | ||
} | ||
|
||
object Andable { | ||
implicit class AndableOps[A <: Andable](val self: A) extends AnyVal { | ||
def and[A2 <: Andable](that: A2): A and A2 = com.dimafeng.testcontainers.lifecycle.and(self, that) | ||
} | ||
} |
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
Oops, something went wrong.