Coverage Summary for Class: RuleAction (dev.skymansandy.wiretap.domain.model)
| Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| RuleAction |
100%
(1/1)
|
|
100%
(1/1)
|
100%
(3/3)
|
| RuleAction$DefaultImpls |
0%
(0/1)
|
|
0%
(0/1)
|
0%
(0/2)
|
| RuleAction$Mock |
100%
(1/1)
|
|
100%
(4/4)
|
100%
(26/26)
|
| RuleAction$MockAndThrottle |
100%
(1/1)
|
|
100%
(6/6)
|
100%
(40/40)
|
| RuleAction$Throttle |
100%
(1/1)
|
|
100%
(3/3)
|
100%
(19/19)
|
| RuleAction$Type |
100%
(2/2)
|
|
100%
(4/4)
|
100%
(36/36)
|
| Total |
85.7%
(6/7)
|
|
94.7%
(18/19)
|
98.4%
(124/126)
|
/*
* Copyright (c) 2026 skymansandy. All rights reserved.
*/
package dev.skymansandy.wiretap.domain.model
/**
* Action to perform when a [WiretapRule][WiretapRule] matches a request.
*
* @see Mock
* @see Throttle
* @see MockAndThrottle
*/
sealed interface RuleAction {
enum class Type(val label: String) {
Mock("Mock"),
Throttle("Throttle"),
MockAndThrottle("Mock + Throttle"),
}
val type: Type
val name: String get() = type.name
/**
* Returns a fake response without hitting the network.
*
* @property responseCode HTTP status code for the mock response (default 200).
* @property responseBody Optional response body string.
* @property responseHeaders Optional response headers.
*/
data class Mock(
val responseCode: Int = 200,
val responseBody: String? = null,
val responseHeaders: Map<String, String>? = null,
) : RuleAction {
override val type: Type = Type.Mock
}
/**
* Delays the request before proceeding to the real network.
*
* @property delayMs Minimum delay in milliseconds.
* @property delayMaxMs If set, delay is randomized between [delayMs] and this value.
*/
data class Throttle(
val delayMs: Long = 0,
val delayMaxMs: Long? = null,
) : RuleAction {
override val type: Type = Type.Throttle
}
/**
* Delays the request, then returns a fake response without hitting the network.
*
* Combines [Mock] and [Throttle] — the throttle delay is required.
*
* @property responseCode HTTP status code for the mock response (default 200).
* @property responseBody Optional response body string.
* @property responseHeaders Optional response headers.
* @property delayMs Minimum delay in milliseconds before returning the mock.
* @property delayMaxMs If set, delay is randomized between [delayMs] and this value.
*/
data class MockAndThrottle(
val responseCode: Int = 200,
val responseBody: String? = null,
val responseHeaders: Map<String, String>? = null,
val delayMs: Long = 1000,
val delayMaxMs: Long? = null,
) : RuleAction {
override val type: Type = Type.MockAndThrottle
}
}