-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99db6e1
commit 5adff5b
Showing
10 changed files
with
282 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
tracing/src/test/kotlin/kotlet/tracing/DefaultHttpCallSanitizerUnitTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package kotlet.tracing | ||
|
||
import io.mockk.every | ||
import kotlet.HttpMethod | ||
import kotlet.mocks.Mocks | ||
import org.junit.jupiter.api.Assertions.* | ||
import kotlin.test.Test | ||
|
||
class DefaultHttpCallSanitizerUnitTest { | ||
@Test | ||
fun `default sanitizer just return values`() { | ||
val call = Mocks.httpCall( | ||
method = HttpMethod.GET, | ||
headers = mapOf("key" to "value, value2") | ||
) | ||
|
||
call.rawResponse.addHeader("Content-Type", "application/json") | ||
|
||
every { call.rawRequest.requestURI } returns "/" | ||
every { call.rawRequest.queryString } returns "query=1" | ||
|
||
assertEquals(mutableListOf("value", "value2"), DefaultHttpCallSanitizer.getHttpRequestHeader(call, "key")) | ||
assertEquals(mutableListOf("application/json"), DefaultHttpCallSanitizer.getHttpResponseHeader(call.rawResponse, "Content-Type")) | ||
assertEquals("/", DefaultHttpCallSanitizer.getUrlPath(call)) | ||
assertEquals("query=1", DefaultHttpCallSanitizer.getUrlQuery(call)) | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
tracing/src/test/kotlin/kotlet/tracing/ServletHttpServerAttributesGetterUnitTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package kotlet.tracing | ||
|
||
import io.mockk.every | ||
import io.mockk.mockk | ||
import jakarta.servlet.http.HttpServletResponse | ||
import kotlet.HttpMethod | ||
import kotlet.mocks.Mocks | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import kotlin.test.Test | ||
|
||
class ServletHttpServerAttributesGetterUnitTest { | ||
private val sanitizer = mockk<HttpCallSanitizer>() | ||
private val getter = ServletHttpServerAttributesGetter(sanitizer) | ||
|
||
@Test | ||
fun `getHttpRequestMethod returns method`() { | ||
val call = Mocks.httpCall( | ||
method = HttpMethod.GET | ||
) | ||
|
||
assertEquals("GET", getter.getHttpRequestMethod(call)) | ||
} | ||
|
||
@Test | ||
fun `getHttpRoute returns route`() { | ||
val call = Mocks.httpCall( | ||
method = HttpMethod.GET, | ||
routePath = "/test", | ||
) | ||
|
||
assertEquals("/test", getter.getHttpRoute(call)) | ||
} | ||
|
||
@Test | ||
fun `getHttpRequestHeader returns header through sanitizer`() { | ||
val call = Mocks.httpCall( | ||
method = HttpMethod.GET, | ||
headers = mapOf("key" to "value") | ||
) | ||
|
||
every { sanitizer.getHttpRequestHeader(call, "key") } returns mutableListOf("sanitized value") | ||
|
||
assertEquals(mutableListOf("sanitized value"), getter.getHttpRequestHeader(call, "key")) | ||
} | ||
|
||
@Test | ||
fun `getHttpResponseStatusCode returns status code`() { | ||
val call = Mocks.httpCall( | ||
method = HttpMethod.GET | ||
) | ||
|
||
val response = mockk<HttpServletResponse>() | ||
every { response.status } returns 202 | ||
|
||
assertEquals(202, getter.getHttpResponseStatusCode(call, response, null)) | ||
} | ||
|
||
@Test | ||
fun `getHttpResponseHeader returns header through sanitizer`() { | ||
val call = Mocks.httpCall( | ||
method = HttpMethod.GET | ||
) | ||
|
||
val response = mockk<HttpServletResponse>() | ||
every { response.getHeaders("key") } returns listOf("value") | ||
every { sanitizer.getHttpResponseHeader(response, "key") } returns mutableListOf("sanitized value") | ||
|
||
assertEquals(mutableListOf("sanitized value"), getter.getHttpResponseHeader(call, response, "key")) | ||
} | ||
|
||
@Test | ||
fun `getUrlScheme returns scheme`() { | ||
val call = Mocks.httpCall( | ||
method = HttpMethod.GET | ||
) | ||
|
||
every { call.rawRequest.scheme } returns "http" | ||
|
||
assertEquals("http", getter.getUrlScheme(call)) | ||
} | ||
|
||
@Test | ||
fun `getUrlPath returns path through sanitizer`() { | ||
val call = Mocks.httpCall( | ||
method = HttpMethod.GET, | ||
) | ||
|
||
every { sanitizer.getUrlPath(call) } returns "/sanitized_test" | ||
|
||
assertEquals("/sanitized_test", getter.getUrlPath(call)) | ||
} | ||
|
||
@Test | ||
fun `getUrlQuery returns query through sanitizer`() { | ||
val call = Mocks.httpCall( | ||
method = HttpMethod.GET, | ||
) | ||
|
||
every { sanitizer.getUrlQuery(call) } returns "query=sanitized" | ||
|
||
assertEquals("query=sanitized", getter.getUrlQuery(call)) | ||
} | ||
|
||
@Test | ||
fun `getNetworkTransport returns TCP`() { | ||
val call = Mocks.httpCall( | ||
method = HttpMethod.GET, | ||
) | ||
|
||
assertEquals("tcp", getter.getNetworkTransport(call, null)) | ||
} | ||
} |
Oops, something went wrong.