Skip to content

Commit

Permalink
Add passing test
Browse files Browse the repository at this point in the history
  • Loading branch information
solonovamax committed Jul 27, 2024
1 parent 9e32e44 commit df02314
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions reposilite-plugins/prometheus-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ dependencies {
implementation("io.prometheus:prometheus-metrics-core:$prometheus")
implementation("io.prometheus:prometheus-metrics-instrumentation-jvm:$prometheus")
implementation("io.prometheus:prometheus-metrics-exporter-common:$prometheus")

testImplementation(project(":reposilite-backend"))
}

tasks.withType<ShadowJar> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import kotlin.time.DurationUnit
@Plugin(name = "prometheus", dependencies = ["failure", "statistics", "status"])
class PrometheusPlugin : ReposilitePlugin() {

override fun initialize(): Facade {
override fun initialize(): PrometheusFacade {
logger.info("")
logger.info("--- Prometheus")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.reposilite.plugin.prometheus

import com.reposilite.plugin.prometheus.specification.PrometheusPluginSpecification
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertDoesNotThrow

internal class PrometheusPluginTest : PrometheusPluginSpecification() {

@Test
fun `should fetch metrics without failing`() {
System.setProperty("reposilite.prometheus.user", "user")
System.setProperty("reposilite.prometheus.password", "password")

assertDoesNotThrow {
val facade = prometheusPlugin.initialize()
val result = facade.getMetrics(null, setOf())
assert(result.isOk)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.reposilite.plugin.prometheus.specification

import com.reposilite.journalist.backend.AggregatedLogger
import com.reposilite.journalist.backend.InMemoryLogger
import com.reposilite.journalist.backend.PrintStreamLogger
import com.reposilite.plugin.Extensions
import com.reposilite.plugin.api.ReposilitePlugin.ReposilitePluginAccessor
import com.reposilite.plugin.prometheus.PrometheusPlugin
import com.reposilite.status.application.FailureComponents
import com.reposilite.status.application.StatusComponents
import panda.std.reactive.Reference

internal open class PrometheusPluginSpecification {
private val logger = InMemoryLogger()
private val extensions = Extensions(AggregatedLogger(logger, PrintStreamLogger(System.out, System.err)))
protected val prometheusPlugin = PrometheusPlugin()

init {
extensions.registerFacade(FailureComponents(logger).failureFacade())
extensions.registerFacade(StatusComponents(true, extensions.facade(), "", { true }, Reference(1)).statusFacade())
ReposilitePluginAccessor.injectExtension(prometheusPlugin, extensions)
}
}

0 comments on commit df02314

Please sign in to comment.