-
-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add selective interception. * Update README.md. * Align formatting in README with other points. * Avoid header name duplication. * Strip interception header also in the no-op library.
- Loading branch information
Showing
8 changed files
with
175 additions
and
11 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
47 changes: 47 additions & 0 deletions
47
library-no-op/src/test/java/com/chuckerteam/chucker/api/ChuckerInterceptorTest.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,47 @@ | ||
package com.chuckerteam.chucker.api | ||
|
||
import android.content.Context | ||
import com.google.common.truth.Truth.assertThat | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
import okhttp3.mockwebserver.MockResponse | ||
import okhttp3.mockwebserver.MockWebServer | ||
import org.junit.Rule | ||
import org.junit.jupiter.api.Test | ||
|
||
class ChuckerInterceptorTest { | ||
@get:Rule val server = MockWebServer() | ||
private val serverUrl = server.url("/") // Starts server implicitly | ||
private val mockContext = mockk<Context> { | ||
every { getString(any()) } returns "" | ||
} | ||
private val client = OkHttpClient.Builder() | ||
.addInterceptor(ChuckerInterceptor(mockContext)) | ||
.build() | ||
|
||
@Test | ||
fun skipChuckerHeader_isNotAvailableForTheServerRequest() { | ||
server.enqueue(MockResponse().setBody("Hello, world!")) | ||
val request = Request.Builder().url(serverUrl) | ||
.addHeader(Chucker.SKIP_INTERCEPTOR_HEADER_NAME, "true") | ||
.build() | ||
|
||
val response = client.newCall(request).execute() | ||
|
||
assertThat(response.request().header(Chucker.SKIP_INTERCEPTOR_HEADER_NAME)).isNull() | ||
} | ||
|
||
@Test | ||
fun doNotSkipChuckerHeader_isNotAvailableForTheServerRequest() { | ||
server.enqueue(MockResponse().setBody("Hello, world!")) | ||
val request = Request.Builder().url(serverUrl) | ||
.addHeader(Chucker.SKIP_INTERCEPTOR_HEADER_NAME, "false") | ||
.build() | ||
|
||
val response = client.newCall(request).execute() | ||
|
||
assertThat(response.request().header(Chucker.SKIP_INTERCEPTOR_HEADER_NAME)).isNull() | ||
} | ||
} |
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