Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move tests from Environment to ServeConfig #34

Merged
merged 9 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ tab_width = 2
indent_size = 4
tab_width = 4
ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_argument-list-wrapping = disabled
ktlint_standard_max-line-length = disabled

[Makefile]
indent_style = tab
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ dev-spring-boot:
gradle inngest-spring-boot-demo:bootRun

.PHONY: test
test: test-core test-springboot-demo
test: test-core test-ktor test-springboot-demo

.PHONY: test-core
test-core:
gradle test $(TEST_ARGS) -p inngest-core

.PHONY: test-ktor
test-ktor:
gradle test $(TEST_ARGS) -p inngest-test-server

.PHONY: test-springboot-demo
test-springboot-demo:
gradle test $(TEST_ARGS) -p inngest-spring-boot-demo
Expand Down
51 changes: 48 additions & 3 deletions inngest-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent

description = "Inngest SDK"
version = "0.0.1-SNAPSHOT"

plugins {
id("org.jetbrains.kotlin.jvm") version "1.9.10"
// NOTE: should make this only apply for tests
id("com.adarshr.test-logger") version "4.0.0"
}

repositories {
Expand Down Expand Up @@ -39,7 +40,51 @@ tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()

// testlogger {}
testLogging {
events =
setOf(
TestLogEvent.STARTED,
TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_ERROR,
TestLogEvent.STANDARD_OUT,
)

exceptionFormat = TestExceptionFormat.FULL
showStandardStreams = true
showExceptions = true
showCauses = true
showStackTraces = true

// set options for log level DEBUG and INFO
debug {
events =
setOf(
TestLogEvent.STARTED,
TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_ERROR,
TestLogEvent.STANDARD_OUT,
)

exceptionFormat = TestExceptionFormat.FULL
}

info.events = debug.events
info.exceptionFormat = debug.exceptionFormat

afterSuite(
KotlinClosure2({ desc: TestDescriptor, result: TestResult ->
if (desc.parent == null) { // will match the outermost suite
println(
"Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)",
)
}
}),
)
}
}

// TODO - Move this to share conventions gradle file
Expand Down
58 changes: 0 additions & 58 deletions inngest-core/src/main/kotlin/com/inngest/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,11 @@ object Environment {
).filterValues { (it is String) }.entries.associate { (k, v) -> k to v!! }
}

fun inngestAppId(
clientId: String,
serveId: String? = null,
): String {
if (serveId != null) return serveId
return clientId
}

fun inngestEventKey(key: String? = null): String {
if (key != null) return key
return System.getenv(InngestSystem.EventKey.value) ?: "NO_EVENT_KEY_SET"
}

fun inngestSigningKey(
env: InngestEnv,
key: String? = null,
): String {
if (key != null) return key

return when (env) {
InngestEnv.Dev -> "test"
else -> {
val signingKey = System.getenv(InngestSystem.SigningKey.value)
if (signingKey == null) {
throw Exception("signing key is required")
}
signingKey
}
}
}

fun inngestEventApiBaseUrl(
env: InngestEnv,
url: String? = null,
Expand All @@ -60,33 +34,6 @@ object Environment {
}
}

fun inngestApiBaseUrl(
env: InngestEnv,
url: String? = null,
): String {
if (url != null) return url

val baseUrl = System.getenv(InngestSystem.ApiBaseUrl.value)
if (baseUrl != null) {
return baseUrl
}

return when (env) {
InngestEnv.Dev -> "http://127.0.0.1:8288"
else -> "https://api.inngest.com"
}
}

fun inngestServeOrigin(origin: String? = null): String? {
if (origin != null) return origin
return System.getenv(InngestSystem.ServeOrigin.value)
}

fun inngestServePath(path: String? = null): String? {
if (path != null) return path
return System.getenv(InngestSystem.ServePath.value)
}

fun inngestEnv(
env: String? = null,
isDev: Boolean? = null,
Expand Down Expand Up @@ -140,9 +87,4 @@ object Environment {
}
}
}

fun inngestLogLevel(level: String? = null): String {
if (level != null) return level
return System.getenv(InngestSystem.LogLevel.value) ?: "info"
}
}
27 changes: 18 additions & 9 deletions inngest-core/src/main/kotlin/com/inngest/ServeConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package com.inngest

class ServeConfig(
val client: Inngest,
internal val id: String? = null,
internal val signingKey: String? = null,
internal val serveOrigin: String? = null,
internal val servePath: String? = null,
private val id: String? = null,
private val signingKey: String? = null,
private val serveOrigin: String? = null,
private val servePath: String? = null,
// streaming: String = "false" // probably can't stream yet
internal val logLevel: String? = null,
internal val baseUrl: String? = null,
private val logLevel: String? = null,
private val baseUrl: String? = null,
) {
fun appId(): String {
if (id != null) return id
Expand All @@ -17,7 +17,17 @@ class ServeConfig(

fun signingKey(): String {
if (signingKey != null) return signingKey
return System.getenv(InngestSystem.EventKey.value) ?: ""

return when (client.env) {
InngestEnv.Dev -> "test"
else -> {
val signingKey = System.getenv(InngestSystem.SigningKey.value)
if (signingKey == null) {
throw Exception("signing key is required")
}
signingKey
}
}
}

fun baseUrl(): String {
Expand All @@ -30,8 +40,7 @@ class ServeConfig(

return when (client.env) {
InngestEnv.Dev -> "http://127.0.0.1:8288"
InngestEnv.Prod -> "https://inn.gs"
InngestEnv.Other -> "https://inn.gs"
else -> "https://api.inngest.com"
}
}

Expand Down
101 changes: 0 additions & 101 deletions inngest-core/src/test/kotlin/com/inngest/EnvironmentTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@ import kotlin.test.*

// NOTE: not sure how to test values using environment variables
internal class EnvironmentTest {
// AppId
@Test
fun `test inngestAppId`() {
val clientId = "hello"
assertEquals(clientId, Environment.inngestAppId(clientId))
}

@Test
fun `test inngestAppId with serveId`() {
val clientId = "hello"
val serveId = "world"
assertEquals(serveId, Environment.inngestAppId(clientId, serveId))
}

// EventKey
@Test
fun `test inngestEventKey`() {
Expand All @@ -33,29 +19,6 @@ internal class EnvironmentTest {
// @Test
// fun `test inngestEventKey with INNGEST_EVENT_KEY value`() {}

// Signing key
@Test
fun `test inngestSigningKey - dev`() {
assertEquals("test", Environment.inngestSigningKey(InngestEnv.Dev))
}

@Test
fun `test inngestSigningKey with key value`() {
val key = "signing key"
assertEquals(key, Environment.inngestSigningKey(InngestEnv.Dev, key))
}

@Test
fun `test inngestSigningKey - prod`() {
assertFails(
"signing key is required",
{ Environment.inngestSigningKey(InngestEnv.Prod) },
)
}

// @Test
// fun `test inngestSigningKey with INNGEST_SIGNING_KEY value - prod`() {}

// EventAPI URL
@Test
fun `test inngestEventApiBaseUrl - dev`() {
Expand All @@ -77,59 +40,6 @@ internal class EnvironmentTest {
// @Test
// fun `test inngestEventApiBaseUrl with INNGEST_BASE_URL value`() { }

// API URL
@Test
fun `test inngestApiBaseUrl - dev`() {
assertEquals("http://127.0.0.1:8288", Environment.inngestApiBaseUrl(InngestEnv.Dev))
}

@Test
fun `test inngestApiBaseUrl - prod`() {
assertEquals("https://api.inngest.com", Environment.inngestApiBaseUrl(env = InngestEnv.Prod))
}

@Test
fun `test inngestApiBaseUrl with url value`() {
assertEquals(
"https://api.yolo.com",
Environment.inngestApiBaseUrl(env = InngestEnv.Prod, url = "https://api.yolo.com"),
)
}

// TODO: Test with env `INNGEST_API_BASE_URL`
// @Test
// fun `test inngestApiBaseUrl with INNGEST_API_BASE_URL value - prod`() { }

// Serve Origin
@Test
fun `test inngestServeOrigin`() {
assertNull(Environment.inngestServeOrigin())
}

@Test
fun `test inngestServeOrigin with origin value`() {
val origin = "yolo.com"
assertEquals(origin, Environment.inngestServeOrigin(origin))
}

// @Test
// fun `test inngestServeOrigin with INNGEST_SERVE_ORIGIN value`() {}

// Serve Path
@Test
fun `test inngestServePath`() {
assertNull(Environment.inngestServePath())
}

@Test
fun `test inngestServePath with path value`() {
val path = "/api/inngest"
assertEquals(path, Environment.inngestServePath(path))
}

// @Test
// fun `test inngestServePath with INNGEST_SERVE_PATH value`() {}

// Env
@Test
fun `test inngestEnv with no params`() {
Expand All @@ -153,15 +63,4 @@ internal class EnvironmentTest {

// @Test
// fun `test inngestEnv with INNGEST_DEV value`() { }

// Log Level
@Test
fun `test inngestLogLevel default value`() {
assertEquals("info", Environment.inngestLogLevel())
}

@Test
fun `test inngestLogLevel with level value`() {
assertEquals("error", Environment.inngestLogLevel("error"))
}
}
Loading
Loading