github-releases-bot/app/src/test/kotlin/de/rpr/githubreleases/ConfigTest.kt

50 lines
1.7 KiB
Kotlin
Raw Normal View History

2024-02-12 15:14:59 +01:00
package de.rpr.githubreleases
import assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.containsOnly
2024-02-13 09:17:34 +01:00
import de.rpr.githubreleases.model.GithubRepo
2024-02-12 15:14:59 +01:00
import io.kotest.core.spec.style.DescribeSpec
import io.kotest.extensions.system.withEnvironment
import org.junit.jupiter.api.assertThrows
class ConfigTest : DescribeSpec({
describe("instantiation") {
withEnvironment(
mapOf(
"GITHUB_REPOS" to "https://github.com/navidrome/navidrome/",
"NAVIDROME_MASTODON_INSTANCE_URL" to "example.com",
"NAVIDROME_MASTODON_ACCESS_TOKEN" to "token"
)
) {
it("should populate instances from config") {
val config = Config()
assertThat(config.githubRepos).containsExactly(
2024-02-13 09:17:34 +01:00
GithubRepo("https://github.com/navidrome/navidrome/")
2024-02-12 15:14:59 +01:00
)
assertThat(config.mastodonCredentials).containsOnly(
"navidrome" to Config.PublishingCredentials(
instanceUrl = "example.com",
accessToken = "token",
instanceUrlEnvName = "NAVIDROME_MASTODON_INSTANCE_URL",
accessTokenEnvName = "NAVIDROME_MASTODON_ACCESS_TOKEN"
)
)
}
}
withEnvironment(
mapOf("GITHUB_REPOS" to "https://github.com/navidrome/navidrome/")
) {
it("should throw error if env variables for repo are not present") {
assertThrows<IllegalStateException> {
Config()
}
}
}
}
})