diff --git a/internal/orchestrator/updates_test.go b/internal/orchestrator/updates_test.go index 5b12b1cf..1dd6e0ab 100644 --- a/internal/orchestrator/updates_test.go +++ b/internal/orchestrator/updates_test.go @@ -44,10 +44,14 @@ func init() { logrus.SetFormatter(&logrus.JSONFormatter{}) } -func startJetStreamServer() *server.Server { +func startJetStreamServer(t *testing.T) *server.Server { + t.Helper() + opts := srvtest.DefaultTestOptions opts.Port = -1 opts.JetStream = true + opts.StoreDir = t.TempDir() + return srvtest.RunServer(&opts) } @@ -63,17 +67,9 @@ func jetStreamContext(s *server.Server) (*nats.Conn, nats.JetStreamContext) { return nc, js } -func shutdownJetStream(s *server.Server) { - var sd string - if config := s.JetStreamConfig(); config != nil { - sd = config.StoreDir - } +func shutdownJetStream(t *testing.T, s *server.Server) { + t.Helper() s.Shutdown() - if sd != "" { - if err := os.RemoveAll(sd); err != nil { - logger.Fatalf("Unable to remove storage %q: %v", sd, err) - } - } s.WaitForShutdown() } @@ -81,8 +77,9 @@ func shutdownJetStream(s *server.Server) { func TestMain(m *testing.M) { logger = logrus.New() - srv := startJetStreamServer() - defer shutdownJetStream(srv) + t := &testing.T{} + srv := startJetStreamServer(t) + defer shutdownJetStream(t, srv) nc, js = jetStreamContext(srv) // nc is closed on evJS.Close(), js needs no cleanup evJS = events.NewJetstreamFromConn(nc) defer evJS.Close() diff --git a/internal/status/kv_test.go b/internal/status/kv_test.go index 18fa2b8d..48ed08ca 100644 --- a/internal/status/kv_test.go +++ b/internal/status/kv_test.go @@ -25,6 +25,8 @@ func startJetStreamServer(t *testing.T) *server.Server { opts := srvtest.DefaultTestOptions opts.Port = -1 opts.JetStream = true + opts.StoreDir = t.TempDir() + return srvtest.RunServer(&opts) } diff --git a/internal/store/nats_test.go b/internal/store/nats_test.go index 0ae999c6..6c205a29 100644 --- a/internal/store/nats_test.go +++ b/internal/store/nats_test.go @@ -30,10 +30,14 @@ func init() { logrus.SetFormatter(&logrus.JSONFormatter{}) } -func startJetStreamServer() *server.Server { +func startJetStreamServer(t *testing.T) *server.Server { + t.Helper() + opts := srvtest.DefaultTestOptions opts.Port = -1 opts.JetStream = true + opts.StoreDir = t.TempDir() + return srvtest.RunServer(&opts) } @@ -49,17 +53,9 @@ func jetStreamContext(s *server.Server) (*nats.Conn, nats.JetStreamContext) { return nc, js } -func shutdownJetStream(s *server.Server) { - var sd string - if config := s.JetStreamConfig(); config != nil { - sd = config.StoreDir - } +func shutdownJetStream(t *testing.T, s *server.Server) { + t.Helper() s.Shutdown() - if sd != "" { - if err := os.RemoveAll(sd); err != nil { - logger.Fatalf("Unable to remove storage %q: %v", sd, err) - } - } s.WaitForShutdown() } @@ -67,8 +63,9 @@ func shutdownJetStream(s *server.Server) { func TestMain(m *testing.M) { logger = logrus.New() - srv := startJetStreamServer() - defer shutdownJetStream(srv) + t := &testing.T{} + srv := startJetStreamServer(t) + defer shutdownJetStream(t, srv) nc, js = jetStreamContext(srv) // nc is closed on evJS.Close(), js needs no cleanup evJS = events.NewJetstreamFromConn(nc) defer evJS.Close()