Skip to content

Provide an artifact for unit tests #140

@ShreyashKore

Description

@ShreyashKore

Should the library provide artifacts for easier testing in unit tests? Something like an in-memory store would similar to JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY) could be provided. It could have simple implementation like this:

class KStoreInMemoryCodec<T : @Serializable Any>(
    private val json: Json,
    private val serializer: KSerializer<T>
) : Codec<T> {

    private var storedData: String? = null

    override suspend fun decode(): T? =
        storedData?.let {
            try {
                json.decodeFromString(serializer, it)
            } catch (e: SerializationException) {
                null
            }
        }

    override suspend fun encode(value: T?) {
        storedData = value?.let { json.encodeToString(serializer, it) }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions