-
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for url details apply methods
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package io.sentry | ||
|
||
import io.sentry.protocol.Request | ||
import io.sentry.util.UrlUtils | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.verify | ||
import org.mockito.kotlin.verifyNoMoreInteractions | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNull | ||
|
||
class UrlDetailsTest { | ||
|
||
@Test | ||
fun `does not crash on null span`() { | ||
val urlDetails = UrlUtils.UrlDetails("https://sentry.io/api", "q=1", "top") | ||
urlDetails.applyToSpan(null) | ||
} | ||
|
||
@Test | ||
fun `applies query and fragment to span`() { | ||
val urlDetails = UrlUtils.UrlDetails("https://sentry.io/api", "q=1", "top") | ||
val span = mock<ISpan>() | ||
urlDetails.applyToSpan(span) | ||
|
||
verify(span).setData("http.query", "q=1") | ||
verify(span).setData("http.fragment", "top") | ||
} | ||
|
||
@Test | ||
fun `applies query to span`() { | ||
val urlDetails = UrlUtils.UrlDetails("https://sentry.io/api", "q=1", null) | ||
val span = mock<ISpan>() | ||
urlDetails.applyToSpan(span) | ||
|
||
verify(span).setData("http.query", "q=1") | ||
verifyNoMoreInteractions(span) | ||
} | ||
|
||
@Test | ||
fun `applies fragment to span`() { | ||
val urlDetails = UrlUtils.UrlDetails("https://sentry.io/api", null, "top") | ||
val span = mock<ISpan>() | ||
urlDetails.applyToSpan(span) | ||
|
||
verify(span).setData("http.fragment", "top") | ||
verifyNoMoreInteractions(span) | ||
} | ||
|
||
@Test | ||
fun `does not crash on null request`() { | ||
val urlDetails = UrlUtils.UrlDetails("https://sentry.io/api", "q=1", "top") | ||
urlDetails.applyToRequest(null) | ||
} | ||
|
||
@Test | ||
fun `applies details to request`() { | ||
val urlDetails = UrlUtils.UrlDetails("https://sentry.io/api", "q=1", "top") | ||
val request = Request() | ||
urlDetails.applyToRequest(request) | ||
|
||
assertEquals("https://sentry.io/api", request.url) | ||
assertEquals("q=1", request.queryString) | ||
assertEquals("top", request.fragment) | ||
} | ||
|
||
@Test | ||
fun `applies details without fragment and url to request`() { | ||
val urlDetails = UrlUtils.UrlDetails("https://sentry.io/api", null, null) | ||
val request = Request() | ||
urlDetails.applyToRequest(request) | ||
|
||
assertEquals("https://sentry.io/api", request.url) | ||
assertNull(request.queryString) | ||
assertNull(request.fragment) | ||
} | ||
|
||
@Test | ||
fun `returns fallback for null URL`() { | ||
val urlDetails = UrlUtils.UrlDetails(null, null, null) | ||
assertEquals("unknown", urlDetails.urlOrFallback) | ||
} | ||
} |