Skip to content

Commit

Permalink
parametrize tests to run with both v3 and v4 implementations of `Apol…
Browse files Browse the repository at this point in the history
…loCall<D>::execute`
  • Loading branch information
lcian committed Feb 14, 2025
1 parent 18d3d8d commit 47fbe9e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions sentry-apollo-4/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies {
testImplementation(Config.TestLibs.mockWebserver)
testImplementation(Config.Libs.apolloKotlin4)
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
testImplementation("org.jetbrains.kotlin:kotlin-reflect:2.0.0")
}

configure<SourceSetContainer> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.sentry.apollo4

import com.apollographql.apollo.ApolloCall
import com.apollographql.apollo.ApolloClient
import com.apollographql.apollo.api.ApolloResponse
import com.apollographql.apollo.api.Operation
import com.apollographql.apollo.api.http.HttpRequest
import com.apollographql.apollo.api.http.HttpResponse
import com.apollographql.apollo.exception.ApolloException
Expand All @@ -26,14 +29,20 @@ import org.mockito.kotlin.mock
import org.mockito.kotlin.never
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import kotlin.reflect.KSuspendFunction1
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue

class SentryApollo4BuilderExtensionsClientErrorsTest {
class SentryApollo4BuilderExtensionsClientErrorsTestWithV4Implementation : SentryApollo4BuilderExtensionsClientErrorsTest(ApolloCall<*>::execute)
class SentryApollo4BuilderExtensionsClientErrorsTestWithV3Implementation : SentryApollo4BuilderExtensionsClientErrorsTest(ApolloCall<*>::executeV3)

abstract class SentryApollo4BuilderExtensionsClientErrorsTest(
private val executeQueryImplementation: KSuspendFunction1<ApolloCall<*>, ApolloResponse<out Operation.Data>>
) {
class Fixture {
val server = MockWebServer()
lateinit var scopes: IScopes
Expand Down Expand Up @@ -379,7 +388,7 @@ class SentryApollo4BuilderExtensionsClientErrorsTest {
private fun executeQuery(sut: ApolloClient, id: String = "83") = runBlocking {
val coroutine = launch {
try {
sut.query(LaunchDetailsQuery(id)).execute()
executeQueryImplementation(sut.query(LaunchDetailsQuery(id)))
} catch (e: ApolloException) {
return@launch
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.sentry.apollo4

import com.apollographql.apollo.ApolloCall
import com.apollographql.apollo.ApolloClient
import com.apollographql.apollo.api.ApolloResponse
import com.apollographql.apollo.api.Operation
import com.apollographql.apollo.exception.ApolloException
import io.sentry.Breadcrumb
import io.sentry.IScopes
Expand All @@ -26,12 +29,18 @@ import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import java.util.concurrent.TimeUnit
import kotlin.reflect.KSuspendFunction1
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue

class SentryApollo4BuilderExtensionsTest {
class SentryApollo4BuilderExtensionsTestWithV4Implementation : SentryApollo4BuilderExtensionsTest(ApolloCall<*>::execute)
class SentryApollo4BuilderExtensionsTestWithV3Implementation : SentryApollo4BuilderExtensionsTest(ApolloCall<*>::executeV3)

abstract class SentryApollo4BuilderExtensionsTest(
private val executeQueryImplementation: KSuspendFunction1<ApolloCall<*>, ApolloResponse<out Operation.Data>>
) {

class Fixture {
val server = MockWebServer()
Expand Down Expand Up @@ -199,7 +208,7 @@ class SentryApollo4BuilderExtensionsTest {

val coroutine = launch {
try {
sut.query(LaunchDetailsQuery(id)).execute()
executeQueryImplementation(sut.query(LaunchDetailsQuery(id)))
} catch (e: ApolloException) {
return@launch
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.sentry.apollo4

import com.apollographql.apollo.ApolloCall
import com.apollographql.apollo.ApolloClient
import com.apollographql.apollo.api.ApolloResponse
import com.apollographql.apollo.api.Operation
import com.apollographql.apollo.api.http.HttpRequest
import com.apollographql.apollo.api.http.HttpResponse
import com.apollographql.apollo.exception.ApolloException
Expand Down Expand Up @@ -43,13 +46,19 @@ import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import java.util.concurrent.TimeUnit
import kotlin.reflect.KSuspendFunction1
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue

class SentryApollo4HttpInterceptorTest {
class SentryApollo4HttpInterceptorTestWithV4Implementation : SentryApollo4HttpInterceptorTest(ApolloCall<*>::execute)
class SentryApollo4HttpInterceptorTestWithV3Implementation : SentryApollo4HttpInterceptorTest(ApolloCall<*>::executeV3)

abstract class SentryApollo4HttpInterceptorTest(
private val executeQueryImplementation: KSuspendFunction1<ApolloCall<*>, ApolloResponse<out Operation.Data>>
) {

class Fixture {
val server = MockWebServer()
Expand Down Expand Up @@ -367,7 +376,7 @@ class SentryApollo4HttpInterceptorTest {

val coroutine = launch {
try {
sut.query(LaunchDetailsQuery(id)).execute()
executeQueryImplementation(sut.query(LaunchDetailsQuery(id)))
} catch (e: ApolloException) {
return@launch
}
Expand Down

0 comments on commit 47fbe9e

Please sign in to comment.