Skip to content

Commit

Permalink
make zmq tests ordered
Browse files Browse the repository at this point in the history
  • Loading branch information
agbpatro committed Oct 27, 2023
1 parent 2c907d9 commit a99bf4c
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import (
"github.com/teslamotors/fleet-telemetry/telemetry"
)

var _ = Describe("Test full application config", func() {
var _ = Describe("Test full application config", Ordered, func() {

var config *Config
var (
config *Config
producers map[string][]telemetry.Producer
)

BeforeEach(func() {
config = &Config{
Expand All @@ -43,6 +46,21 @@ var _ = Describe("Test full application config", func() {
}
})

AfterEach(func() {
os.Clearenv()
type Closer interface {
Close() error
}
for _, typeProducers := range producers {
for _, producer := range typeProducers {
if closer, ok := producer.(Closer); ok {
err := closer.Close()
Expect(err).NotTo(HaveOccurred())
}
}
}
})

Context("ExtractServiceTLSConfig", func() {
It("fails when TLS is nil ", func() {
config = &Config{}
Expand Down Expand Up @@ -104,7 +122,7 @@ var _ = Describe("Test full application config", func() {
config, err := loadTestApplicationConfig(TestSmallConfig)
Expect(err).NotTo(HaveOccurred())

producers, err := config.ConfigureProducers(log)
producers, err = config.ConfigureProducers(log)
Expect(err).NotTo(HaveOccurred())
Expect(producers["FS"]).To(HaveLen(1))

Expand All @@ -119,7 +137,8 @@ var _ = Describe("Test full application config", func() {
log, _ := test.NewNullLogger()
config.Records = map[string][]telemetry.Dispatcher{"FS": {"kinesis"}}

producers, err := config.ConfigureProducers(log)
var err error
producers, err = config.ConfigureProducers(log)
Expect(err).To(MatchError("Expected Kinesis to be configured"))
Expect(producers).To(BeNil())
})
Expand Down Expand Up @@ -165,41 +184,23 @@ var _ = Describe("Test full application config", func() {
It("pubsub config works", func() {
log, _ := test.NewNullLogger()
_ = os.Setenv("PUBSUB_EMULATOR_HOST", "some_url")
producers, err := pubsubConfig.ConfigureProducers(log)
var err error
producers, err = pubsubConfig.ConfigureProducers(log)
Expect(err).NotTo(HaveOccurred())
Expect(producers["FS"]).NotTo(BeNil())
})
})

Context("configure zmq", func() {
var (
zmqConfig *Config
producers map[string][]telemetry.Producer
lock chan struct{} = make(chan struct{}, 1)
)
var zmqConfig *Config

BeforeEach(func() {
var err error
zmqConfig, err = loadTestApplicationConfig(TestZMQConfig)
Expect(err).NotTo(HaveOccurred())
})

AfterEach(func() {
os.Clearenv()
type Closer interface {
Close() error
}
for _, typeProducers := range producers {
for _, producer := range typeProducers {
if closer, ok := producer.(Closer); ok {
closer.Close()
}
}
}
})

It("returns an error if zmq isn't included", func() {
lock <- struct{}{}
log, _ := test.NewNullLogger()
config.Records = map[string][]telemetry.Dispatcher{"FS": {"zmq"}}
var err error
Expand All @@ -208,17 +209,14 @@ var _ = Describe("Test full application config", func() {
Expect(producers).To(BeNil())
producers, err = zmqConfig.ConfigureProducers(log)
Expect(err).To(BeNil())
<-lock
})

It("zmq config works", func() {
lock <- struct{}{}
log, _ := test.NewNullLogger()
var err error
producers, err = zmqConfig.ConfigureProducers(log)
Expect(err).NotTo(HaveOccurred())
Expect(producers["FS"]).NotTo(BeNil())
<-lock
})
})

Expand Down

0 comments on commit a99bf4c

Please sign in to comment.