Skip to content
Snippets Groups Projects
Commit 07e840f3 authored by William Walker's avatar William Walker
Browse files

Remove logger dependency injection from JVM tests

-Stop injecting logger from global DI instance in tests and instead use factory utility function
-Convert version field from func to constant property
parent bd134ae7
No related branches found
No related tags found
No related merge requests found
......@@ -47,6 +47,13 @@ public interface TemerityApi {
// User API public library functions
/**
* Fetches the version of the Temerity client library.
* @return The version of the client library as a semantic versioning formatted string.
*/
@Suppress("PropertyName")
public val VERSION: String
/**
* Fetches the list of users from the platform.
* @return A list of User objects
......@@ -230,8 +237,6 @@ public interface TemerityApi {
* @param refresh Whether to fetch the roles if not present locally.
*/
public suspend fun getCachedUserRoles(refresh: Boolean = true): List<String>
public fun version(): String
}
// Objects used by library consumers and re-implementations of the Temerity API spec
......
......@@ -83,7 +83,6 @@ import org.koin.core.Koin
import org.koin.core.KoinApplication
import org.koin.core.component.KoinComponent
import org.koin.core.component.get
import org.koin.core.context.GlobalContext.get
import org.koin.core.logger.Level
import org.koin.core.logger.Level.DEBUG
import org.koin.core.logger.Level.ERROR
......@@ -142,7 +141,7 @@ public class Temerity internal constructor(
)
}
factory { (config: TemClientConfig) ->
val client: HttpClient = get { parametersOf(config) }
val client: HttpClient = get { parametersOf(config, createLogger("Temerity Library Web Request engine")) }
val ktorfit = ktorfit {
config.serviceUrl?.let { baseUrl(it) }
httpClient(client)
......@@ -185,7 +184,8 @@ public class Temerity internal constructor(
abstract val koin: Koin
}
override fun version(): String = BuildConfig.LIB_VERSION
@Suppress("PropertyName")
override val VERSION: String = BuildConfig.LIB_VERSION
private val json: Json = buildJson()
internal val koinContext = createKoinApp()
......@@ -193,7 +193,7 @@ public class Temerity internal constructor(
private var platformApi: PlatformApi
private var cachedUserRoleList: ConcurrentMutableMap<Int, String>
private var clientCoroutineScope: CoroutineScope
private var libraryCoroutineScope: CoroutineScope
init {
check(!config.serviceToken.isNullOrBlank()) {
......@@ -204,7 +204,7 @@ public class Temerity internal constructor(
"Service url must be provided. Set it using TemClientConfig.serviceUrl(url)"
}
clientCoroutineScope = get<CoroutineScope> {
libraryCoroutineScope = get<CoroutineScope> {
when (val optThreadCount = config.threadCount) {
null -> parametersOf(DispatcherFactory.calculateMaxThreads(DEFAULT_MINIMUM_THREAD_COUNT))
else -> parametersOf(DispatcherFactory.setThreadCount(optThreadCount))
......@@ -400,7 +400,7 @@ public class Temerity internal constructor(
): List<AuditLogEntry> {
// TODO: Error out if user inputs time window > 1 month, since the platform API doesn't support
val returnedEntries = ArrayList<AuditLogEntry>()
val jobScope = createJobScope(clientCoroutineScope.coroutineContext)
val jobScope = createJobScope(libraryCoroutineScope.coroutineContext)
val requestJobs = with(eventTypeList ?: EventType.entries) {
map { eventType ->
jobScope.async {
......
......@@ -21,7 +21,6 @@ import co.touchlab.kermit.Logger
import com.skydoves.sandwich.StatusCode
import com.skydoves.sandwich.ktor.getStatusCode
import edu.ucsc.its.temerity.AuditLogSortOrder.NEW_FIRST
import edu.ucsc.its.temerity.core.TemClientConfig
import edu.ucsc.its.temerity.core.Temerity
import edu.ucsc.its.temerity.currentDate
import edu.ucsc.its.temerity.model.EventType.NEW_LOG_IN
......@@ -38,17 +37,13 @@ import kotlinx.datetime.plus
import org.dotenv.vault.dotenvVault
import org.jetbrains.kotlinx.dataframe.api.toDataFrame
import org.jetbrains.kotlinx.dataframe.io.writeCSV
import org.koin.core.parameter.parametersOf
import org.koin.test.KoinTest
import java.io.File
import kotlin.test.assertNotEquals
import kotlin.uuid.ExperimentalUuidApi
import kotlin.uuid.Uuid
@OptIn(ExperimentalUuidApi::class)
class TemerityDevTest :
FunSpec(),
KoinTest {
class TemerityDevTest : FunSpec() {
private lateinit var kermit: Logger
......@@ -61,13 +56,13 @@ class TemerityDevTest :
testTemerity = Temerity {
configureDevEnvironment(dotenv)
}
kermit = getKoin().get { parametersOf("TemerityDevTest", TemClientConfig { supportKtxNotebook = false }) }
kermit = Temerity.createLogger("TemerityDevTest")
}
test("Temerity client returns a correctly-formatted version String") {
val returnedVersion = testTemerity.version().toVersion()
val returnedVersion = testTemerity.VERSION.toVersion()
kermit.d { "Returned client version: $returnedVersion" }
assert(testTemerity.version().isNotEmpty())
assert(testTemerity.VERSION.isNotEmpty())
assert(returnedVersion < Version(0, 1, 0))
assert(returnedVersion.isPreRelease)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment