Skip to content
Snippets Groups Projects
Verified Commit 4f7d34f7 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Implement utilities to enable end to end testing in gitlab CI as well

parent 842dd088
No related branches found
No related tags found
No related merge requests found
Showing with 210 additions and 33 deletions
......@@ -30,6 +30,11 @@ build:
test:
stage: "test"
services:
- name: "k8r.eu/justjanne/quassel-docker"
alias: "quasselcore"
variables:
QUASSEL_CONTAINER: "quassel:4242"
script:
- "dockerd-rootless.sh"
- "./gradlew check -x connectedCheck coberturaTestReport"
......
......@@ -29,36 +29,20 @@ import de.kuschku.libquassel.protocol.serializers.handshake.ClientInitSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.HandshakeMapSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.IntSerializer
import de.kuschku.libquassel.protocol.variant.into
import de.kuschku.libquassel.testutil.TestX509TrustManager
import de.kuschku.libquassel.testutil.quasselContainer
import de.kuschku.quasseldroid.protocol.io.CoroutineChannel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runBlockingTest
import org.junit.Before
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.slf4j.LoggerFactory
import org.testcontainers.containers.BindMode
import org.testcontainers.containers.output.Slf4jLogConsumer
import org.testcontainers.junit.jupiter.Container
import org.testcontainers.junit.jupiter.Testcontainers
import org.testcontainers.utility.MountableFile
import java.net.InetSocketAddress
import java.nio.ByteBuffer
import javax.net.ssl.SSLContext
@ExperimentalCoroutinesApi
@Testcontainers
class EndToEndTest {
@Container
val quassel = QuasselContainer()
.withExposedPorts(4242)
.withClasspathResourceMapping("/quasseltest.crt", "/quasseltest.crt", BindMode.READ_WRITE)
.withEnv("SSL_CERT_FILE", "/quasseltest.crt")
.withClasspathResourceMapping("/quasseltest.key", "/quasseltest.key", BindMode.READ_WRITE)
.withEnv("SSL_KEY_FILE", "/quasseltest.key")
.withEnv("CONFIG_FROM_ENVIRONMENT", "true")
.withEnv("DB_BACKEND", "SQLite")
.withEnv("AUTH_AUTHENTICATOR", "Database")
private val quassel = quasselContainer()
private val sslContext = SSLContext.getInstance("TLSv1.3").apply {
init(null, arrayOf(TestX509TrustManager), null)
......@@ -70,16 +54,18 @@ class EndToEndTest {
private val channel = CoroutineChannel()
@BeforeEach
fun setUp() {
quassel.followOutput(Slf4jLogConsumer(LoggerFactory.getLogger(EndToEndTest::class.java)))
fun start() {
quassel.start()
}
@AfterEach
fun stop() {
quassel.stop()
}
@Test
fun testConnect() = runBlocking {
channel.connect(InetSocketAddress(
quassel.host,
quassel.getMappedPort(4242)
))
channel.connect(quassel.address)
println("Writing protocol")
write(sizePrefix = false) {
......
......@@ -17,11 +17,13 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel
package de.kuschku.libquassel.testutil
import org.testcontainers.containers.GenericContainer
import org.testcontainers.utility.DockerImageName
import java.net.InetSocketAddress
class QuasselContainer : GenericContainer<QuasselContainer>(
DockerImageName.parse("k8r.eu/justjanne/quassel-docker:latest")
)
class GitlabCiProvidedContainer(
override val address: InetSocketAddress
) : ProvidedContainer {
override fun start() = Unit
override fun stop() = Unit
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.testutil
import java.net.InetSocketAddress
interface ProvidedContainer {
fun start()
fun stop()
val address: InetSocketAddress
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.testutil
import org.slf4j.LoggerFactory
import org.testcontainers.containers.BindMode
import org.testcontainers.containers.GenericContainer
import org.testcontainers.containers.output.Slf4jLogConsumer
import org.testcontainers.utility.DockerImageName
class QuasselCoreContainer : GenericContainer<QuasselCoreContainer>(
DockerImageName.parse("k8r.eu/justjanne/quassel-docker:latest")
) {
init {
withExposedPorts(QUASSEL_PORT)
withClasspathResourceMapping(
"/quasseltest.crt",
"/quasseltest.crt",
BindMode.READ_WRITE)
withEnv("SSL_CERT_FILE", "/quasseltest.crt")
withClasspathResourceMapping(
"/quasseltest.key",
"/quasseltest.key",
BindMode.READ_WRITE)
withEnv("SSL_KEY_FILE", "/quasseltest.key")
withEnv("CONFIG_FROM_ENVIRONMENT", "true")
withEnv("DB_BACKEND", "SQLite")
withEnv("AUTH_AUTHENTICATOR", "Database")
}
override fun start() {
super.start()
followOutput(Slf4jLogConsumer(logger))
}
companion object {
@JvmStatic
private val logger = LoggerFactory.getLogger(QuasselCoreContainer::class.java)
const val QUASSEL_PORT = 4242
}
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.testutil
import org.testcontainers.containers.GenericContainer
import java.net.InetSocketAddress
class TestContainersProvidedContainer<T : GenericContainer<T>>(
private val container: T,
private val port: Int
) : ProvidedContainer {
override fun start() = container.start()
override fun stop() = container.stop()
override val address
get() = InetSocketAddress(
container.containerIpAddress,
container.getMappedPort(port)
)
}
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel
package de.kuschku.libquassel.testutil
import java.security.cert.X509Certificate
import javax.net.ssl.X509TrustManager
......
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.testutil
import java.net.InetSocketAddress
fun providedContainer(
envVariable: String,
f: () -> ProvidedContainer
) = when {
!System.getenv(envVariable).isNullOrEmpty() -> {
val (host, port) = System.getenv(envVariable).split(":")
GitlabCiProvidedContainer(InetSocketAddress(host, port.toInt()))
}
else -> f()
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.testutil
fun quasselContainer() = providedContainer("QUASSEL_CONTAINER") {
TestContainersProvidedContainer(
QuasselCoreContainer(),
QuasselCoreContainer.QUASSEL_PORT
)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment