com.bybutter.sisyphus.test.Extension.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sisyphus-test Show documentation
Show all versions of sisyphus-test Show documentation
Test framework for testing gRPC apis in Sisyphus Framework
package com.bybutter.sisyphus.test
import com.bybutter.sisyphus.security.base64
import com.bybutter.sisyphus.security.base64Decode
import io.grpc.Metadata
fun Metadata.mergeFrom(data: Map): Metadata {
for ((k, v) in data) {
if (k.endsWith(Metadata.BINARY_HEADER_SUFFIX)) {
put(Metadata.Key.of(k, Metadata.BINARY_BYTE_MARSHALLER), v.base64Decode())
} else {
put(Metadata.Key.of(k, Metadata.ASCII_STRING_MARSHALLER), v)
}
}
return this
}
fun Metadata.toMap(): Map {
val result = mutableMapOf()
for (k in keys()) {
if (k.endsWith(Metadata.BINARY_HEADER_SUFFIX)) {
get(Metadata.Key.of(k, Metadata.BINARY_BYTE_MARSHALLER))?.base64()?.let {
result[k] = it
}
} else {
get(Metadata.Key.of(k, Metadata.ASCII_STRING_MARSHALLER))?.let {
result[k] = it
}
}
}
return result
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy