Skip to content

Commit

Permalink
pkg/services/servicetest: make Run & RunHealthy pass-through
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Dec 3, 2023
1 parent d550085 commit 399001c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/services/servicetest/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ type TestingT interface {
}

// Run fails tb if the service fails to start or close.
func Run(tb TestingT, s Runnable) {
func Run[R Runnable](tb TestingT, r R) R {
tb.Helper()
require.NoError(tb, s.Start(tests.Context(tb)), "service failed to start")
tb.Cleanup(func() { assert.NoError(tb, s.Close(), "error closing service") })
require.NoError(tb, r.Start(tests.Context(tb)), "service failed to start")
tb.Cleanup(func() { assert.NoError(tb, r.Close(), "error closing service") })
return r
}

// RunHealthy fails tb if the service fails to start, close, is never ready, or is ever unhealthy (based on periodic checks).
// - after starting, readiness will always be checked at least once, before closing
// - if ever ready, then health will be checked at least once, before closing
func RunHealthy(tb TestingT, s services.Service) {
func RunHealthy[S services.Service](tb TestingT, s S) S {
tb.Helper()
Run(tb, s)

Expand Down Expand Up @@ -71,4 +72,5 @@ func RunHealthy(tb TestingT, s services.Service) {
}
}
}()
return s
}

0 comments on commit 399001c

Please sign in to comment.