Skip to content

Commit

Permalink
support Micronaut 3.x in test which only triggers filter once
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr committed Apr 13, 2022
1 parent 17befa0 commit c4b886b
Showing 1 changed file with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import io.sentry.IHub
import spock.lang.AutoCleanup
import spock.lang.Specification

import java.util.concurrent.atomic.AtomicInteger

class SentryFilterSpec extends Specification {

@AutoCleanup Gru gru = Gru.create(Http.create(this))
Expand Down Expand Up @@ -64,6 +66,11 @@ class SentryFilterSpec extends Specification {
}

void 'try error message'() {
given:
AtomicInteger pushCalls = new AtomicInteger()
AtomicInteger breadcrumbsCalls = new AtomicInteger()
AtomicInteger configureScopeCalls = new AtomicInteger()
AtomicInteger popCalls = new AtomicInteger()
when:
gru.test {
post('/test/parameter')
Expand All @@ -74,13 +81,33 @@ class SentryFilterSpec extends Specification {
then:
gru.verify()

2 * hub.pushScope()
2 * hub.addBreadcrumb(_)
2 * hub.configureScope(_)
2 * hub.popScope()
_ * hub.pushScope() >> {
pushCalls.incrementAndGet()
}
_ * hub.addBreadcrumb(_) >> {
breadcrumbsCalls.incrementAndGet()
}
_ * hub.configureScope(_) >> {
configureScopeCalls.incrementAndGet()
}
_ * hub.popScope() >> {
popCalls.incrementAndGet()
}

expect:
// the filter is only called once for Micronaut 3.x but twice for Micronaut 1.x and 2.x
pushCalls.get() in 1..2
pushCalls.get() == breadcrumbsCalls.get()
pushCalls.get() == configureScopeCalls.get()
pushCalls.get() == popCalls.get()
}

void 'try validation'() {
given:
AtomicInteger pushCalls = new AtomicInteger()
AtomicInteger breadcrumbsCalls = new AtomicInteger()
AtomicInteger configureScopeCalls = new AtomicInteger()
AtomicInteger popCalls = new AtomicInteger()
when:
gru.test {
put('/test/validated')
Expand All @@ -91,10 +118,25 @@ class SentryFilterSpec extends Specification {
then:
gru.verify()

2 * hub.pushScope()
2 * hub.addBreadcrumb(_)
2 * hub.configureScope(_)
2 * hub.popScope()
_ * hub.pushScope() >> {
pushCalls.incrementAndGet()
}
_ * hub.addBreadcrumb(_) >> {
breadcrumbsCalls.incrementAndGet()
}
_ * hub.configureScope(_) >> {
configureScopeCalls.incrementAndGet()
}
_ * hub.popScope() >> {
popCalls.incrementAndGet()
}

expect:
// the filter is only called once for Micronaut 3.x but twice for Micronaut 1.x and 2.x
pushCalls.get() in 1..2
pushCalls.get() == breadcrumbsCalls.get()
pushCalls.get() == configureScopeCalls.get()
pushCalls.get() == popCalls.get()
}

}

0 comments on commit c4b886b

Please sign in to comment.