ceen/internal/testutil/testutil.go
2022-06-16 22:19:06 +02:00

28 lines
509 B
Go

package testutil
import (
"os"
"github.com/nats-io/nats-server/v2/server"
natsserver "github.com/nats-io/nats-server/v2/test"
)
func NewNatsServer(port int) *server.Server {
opts := natsserver.DefaultTestOptions
opts.Port = port
opts.JetStream = true
return natsserver.RunServer(&opts)
}
func ShutdownNatsServer(s *server.Server) {
var sd string
if config := s.JetStreamConfig(); config != nil {
sd = config.StoreDir
}
s.Shutdown()
if sd != "" {
os.RemoveAll(sd)
}
s.WaitForShutdown()
}