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

Provide an artifact for unit tests #140

Open
ShreyashKore opened this issue Feb 15, 2025 · 2 comments
Open

Provide an artifact for unit tests #140

ShreyashKore opened this issue Feb 15, 2025 · 2 comments

Comments

@ShreyashKore
Copy link

ShreyashKore commented Feb 15, 2025

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) }
    }
}
@ShreyashKore
Copy link
Author

If you're interested in adding this feature, I’d love to contribute!

@xxfast
Copy link
Owner

xxfast commented Feb 19, 2025

Hi! Yes that would be a great addition :) Feel free to PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants