mirror of
https://github.com/hanzo-fi/go-libs.git
synced 2026-10-30 20:53:44 +00:00
44 lines
875 B
Go
44 lines
875 B
Go
package ginkgo
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/hanzo-fi/go-libs/v5/pkg/testing/deferred"
|
|
"github.com/hanzo-fi/go-libs/v5/pkg/testing/testservice"
|
|
)
|
|
|
|
func DeferNew(
|
|
commandFactory func() *cobra.Command,
|
|
options ...testservice.Option,
|
|
) *deferred.Deferred[*testservice.Service] {
|
|
d := deferred.New[*testservice.Service]()
|
|
BeforeEach(func() {
|
|
d.Reset()
|
|
|
|
service := testservice.New(commandFactory, options...)
|
|
go func() {
|
|
defer GinkgoRecover()
|
|
|
|
err := service.Start(context.Background())
|
|
if err != nil {
|
|
d.SetErr(err)
|
|
Fail(err.Error())
|
|
}
|
|
d.SetValue(service)
|
|
}()
|
|
|
|
DeferCleanup(func() {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
|
|
Expect(service.Stop(ctx)).To(Succeed())
|
|
})
|
|
})
|
|
return d
|
|
}
|