Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
testcontainers-ci
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Janne Mareike Koschinski
testcontainers-ci
Commits
60452e1a
Verified
Commit
60452e1a
authored
4 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup API and documentation
parent
0b4842e3
No related branches found
No related tags found
No related merge requests found
Pipeline
#619
passed
4 years ago
Stage: build
Stage: test
Stage: release
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+29
-40
29 additions, 40 deletions
README.md
src/main/kotlin/de/justjanne/testcontainersci/api/providedContainer.kt
+5
-3
5 additions, 3 deletions
...in/de/justjanne/testcontainersci/api/providedContainer.kt
with
34 additions
and
43 deletions
README.md
+
29
−
40
View file @
60452e1a
#
Kotlin Bitflags
#
Testcontainers-CI
Kotlin-Bitflags is a utility library to simplify implementing bitflags in Kotlin. It integrates with Kotlin unsigned
types and Java Enumsets. This especially useful when interacting with binary protocols from Kotlin
.
Testcontainers-CI allows you to easily use testcontainers whenever you can, but use containers created through other
means whenever you can’t
.
## Using Kotlin-Bitflags
When running your CI in docker, you can’t launch new containers without DinD, but thanks to Gitlab Ci Services you can
run a docker container with the desired service and use it in your code easily.
After adding this module to your dependenci
es,
you'll have to implement the related interfaces in your classes:
This project simplifies this proc
es
s
,
by providing a façade for both types of containers.
```
kotlin
enum
class
MessageFlag
(
override
val
value
:
UInt
,
)
:
Flag
<
UInt
>
{
Self
(
0x01u
),
Highlight
(
0x02u
),
Redirected
(
0x04u
),
ServerMsg
(
0x08u
),
Backlog
(
0x80u
);
companion
object
:
Flags
<
UInt
,
MessageFlag
>
{
override
val
all
:
Set
<
MessageFlag
>
=
values
().
toEnumSet
()
}
}
```
## Using Testcontainers-CI
This allows you to then use this elsewhere to e.g initialize a field from discrete values
```
kotlin
// Construct from varargs or an array
val
field
=
MessageFlag
.
of
(
MessageFlag
.
Self
,
MessageFlag
.
Highlight
)
val
values
=
listOf
(
MessageFlag
.
Self
,
MessageFlag
.
Highlight
)
// Or from a collection
val
field
=
MessageFlag
.
of
(
values
)
// Or use the to helper
val
field
=
values
.
toEnumSet
()
```
After adding this module to your dependencies, you can just wrap your calls creating testcontainers with the
`providedContainer`
function, and it’ll return either the Testcontainer, or the provided container, whichever is
available in the current environment.
You can also convert such a field into the raw binary value easily
```
kotlin
// Returns in this case UInt
field
.
toBits
()
@CiContainers
class
MyLittleTest
{
private
val
container
=
providedContainer
(
"REDIS_CONTAINER"
)
{
GenericContainer
(
DockerImageName
.
parse
(
"redis:5.0.3-alpine"
))
.
withExposedPorts
(
6379
);
}
@Test
fun
test
()
{
println
(
container
.
address
)
println
(
container
.
getMappedPort
(
6379
))
}
}
```
Additional utility functions are available:
```
kotlin
// Empty field
MessageFlag
.
none
()
// Get all non-null valu
es
MessageFlag
.
validValues
()
```
yaml
services
:
-
name
:
"
redis:5.0.3-alpine"
alias
:
"
test_redis_instance"
variabl
es
:
REDIS_CONTAINER
:
"
test_redis_instance"
```
This diff is collapsed.
Click to expand it.
src/main/kotlin/de/justjanne/testcontainersci/api/providedContainer.kt
+
5
−
3
View file @
60452e1a
...
...
@@ -10,16 +10,18 @@
package
de.justjanne.testcontainersci.api
import
de.justjanne.testcontainersci.implementation.GitlabCiProvidedContainer
import
de.justjanne.testcontainersci.implementation.TestContainersProvidedContainer
import
org.testcontainers.containers.GenericContainer
import
java.net.InetAddress
/**
* Build a provided container from an environment variable and a builder for a local container
*/
fun
providedContainer
(
fun
<
T
:
GenericContainer
<
T
>>
providedContainer
(
envVariable
:
String
,
containerBuilder
:
()
->
ProvidedContainer
containerBuilder
:
()
->
T
)
=
when
{
!
System
.
getenv
(
envVariable
).
isNullOrEmpty
()
->
GitlabCiProvidedContainer
(
InetAddress
.
getByName
(
System
.
getenv
(
envVariable
)))
else
->
containerBuilder
()
else
->
TestContainersProvidedContainer
(
containerBuilder
()
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment