ResponseRecordingContext

class ResponseRecordingContext(responseBodyRef: AtomicReference<String?> = AtomicReference(null)) : AbstractCoroutineContextElement(source)

HTTP 응답 레코딩을 위한 Coroutine Context Element

API 응답을 자동으로 캡처하여 테스트 목적으로 저장할 수 있게 해주는 컨텍스트입니다. 주로 API 호출의 실제 응답을 기록하여 테스트 fixture로 활용하거나, 디버깅 시 실제 응답 데이터를 확인하는 용도로 사용됩니다.

단일 응답 body만 저장하며, 각 API 호출 시 덮어쓰기됩니다. Thread-safe한 AtomicReference를 사용하여 동시성 문제를 방지합니다.

사용 예시:

val recordingContext = ResponseRecordingContext()
withContext(recordingContext) {
kfcClient.funds.getList()
val capturedResponse = recordingContext.getResponseBody()
// capturedResponse를 테스트 fixture로 저장
}

Constructors

Link copied to clipboard
constructor(responseBodyRef: AtomicReference<String?> = AtomicReference(null))

Types

Link copied to clipboard

Properties

Link copied to clipboard
open override val key: CoroutineContext.Key<*>

Functions

Link copied to clipboard
fun clear()

저장된 응답 body를 초기화합니다. 여러 API 호출을 순차적으로 기록할 때, 각 호출 전에 clear()를 호출하면 이전 응답과 혼동되지 않습니다.

Link copied to clipboard
open override fun <R> fold(initial: R, operation: (R, CoroutineContext.Element) -> R): R
Link copied to clipboard
open operator override fun <E : CoroutineContext.Element> get(key: CoroutineContext.Key<E>): E?
Link copied to clipboard

저장된 마지막 응답 body를 가져옵니다.

Link copied to clipboard
open override fun minusKey(key: CoroutineContext.Key<*>): CoroutineContext
Link copied to clipboard
open operator fun plus(context: CoroutineContext): CoroutineContext
Link copied to clipboard

마지막 응답 body를 저장합니다. 이전 응답은 자동으로 덮어씌워집니다.