Skip to content

Commit

Permalink
feat: add nats server on integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 16, 2024
1 parent f7ce827 commit eb0a819
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions pkg/testserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testserver
import (
"context"
"fmt"
"github.com/formancehq/go-libs/publish"
"io"
"net/http"
"strings"
Expand Down Expand Up @@ -30,6 +31,7 @@ type T interface {

type Configuration struct {
PostgresConfiguration bunconnect.ConnectionOptions
NatsURL string
Output io.Writer
Debug bool
}
Expand Down Expand Up @@ -75,6 +77,14 @@ func (s *Server) Start() {
fmt.Sprint(s.configuration.PostgresConfiguration.ConnMaxIdleTime),
)
}
if s.configuration.NatsURL != "" {
args = append(
args,
"--" + publish.PublisherNatsEnabledFlag,
"--" + publish.PublisherNatsURLFlag, s.configuration.NatsURL,
)
}

if s.configuration.Debug {
args = append(args, "--"+service.DebugFlag)
}
Expand Down
10 changes: 9 additions & 1 deletion test/e2e/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package test_suite

import (
"encoding/json"
"github.com/formancehq/go-libs/testing/platform/natstesting"
"os"

"github.com/formancehq/go-libs/logging"
Expand All @@ -17,12 +18,14 @@ import (
var (
dockerPool = NewDeferred[*docker.Pool]()
pgServer = NewDeferred[*PostgresServer]()
natsServer = NewDeferred[*natstesting.NatsServer]()
debug = os.Getenv("DEBUG") == "true"
logger = logging.NewDefaultLogger(GinkgoWriter, debug, false)
)

type ParallelExecutionContext struct {
PostgresServer *PostgresServer
NatsServer *natstesting.NatsServer
}

var _ = SynchronizedBeforeSuite(func() []byte {
Expand All @@ -38,13 +41,18 @@ var _ = SynchronizedBeforeSuite(func() []byte {
WithPGCrypto(),
)
})
natsServer.LoadAsync(func() *natstesting.NatsServer {
By("Initializing nats server")
return natstesting.CreateServer(GinkgoT(), debug, logger)
})

By("Waiting services alive")
Wait(pgServer)
Wait(pgServer, natsServer)
By("All services ready.")

data, err := json.Marshal(ParallelExecutionContext{
PostgresServer: pgServer.GetValue(),
NatsServer: natsServer.GetValue(),
})
Expect(err).To(BeNil())

Expand Down
1 change: 1 addition & 0 deletions test/e2e/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var _ = Context("Ledger integration tests", func() {
PostgresConfiguration: db.GetValue().ConnectionOptions(),
Output: GinkgoWriter,
Debug: debug,
NatsURL: natsServer.GetValue().URL,
}
})
When("starting the service", func() {
Expand Down

0 comments on commit eb0a819

Please sign in to comment.