Skip to content

Commit

Permalink
Move test case around in collector tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bjee19 committed Feb 6, 2024
1 parent de6e3bc commit 89c41d5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 19 deletions.
2 changes: 1 addition & 1 deletion internal/framework/runnables/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
type CronJobConfig struct {
// Worker is the function that will be run for every cronjob iteration.
Worker func(context.Context)
// ReadyCh represents if the cronjob is ready to start.
// ReadyCh delays the start of the job until the channel is closed.
ReadyCh <-chan struct{}
// Logger is the logger.
Logger logr.Logger
Expand Down
64 changes: 46 additions & 18 deletions internal/mode/static/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,6 @@ var _ = Describe("Collector", Ordered, func() {
},
},
},
{
Name: "upstream3",
ErrorMsg: "there is an error here",
Endpoints: []resolver.Endpoint{
{
Address: "endpoint1",
Port: 80,
}, {
Address: "endpoint2",
Port: 80,
}, {
Address: "endpoint3",
Port: 80,
},
},
},
},
}

Expand Down Expand Up @@ -242,8 +226,8 @@ var _ = Describe("Collector", Ordered, func() {

Describe("NGF resource count collector", func() {
var (
graph1 *graph.Graph
config1 *dataplane.Configuration
graph1 *graph.Graph
config1, invalidUpstreamsConfig *dataplane.Configuration
)

BeforeAll(func() {
Expand Down Expand Up @@ -280,6 +264,32 @@ var _ = Describe("Collector", Ordered, func() {
},
},
}

invalidUpstreamsConfig = &dataplane.Configuration{
Upstreams: []dataplane.Upstream{
{
Name: "invalidUpstream",
ErrorMsg: "there is an error here",
Endpoints: []resolver.Endpoint{
{
Address: "endpoint1",
Port: 80,
}, {
Address: "endpoint2",
Port: 80,
}, {
Address: "endpoint3",
Port: 80,
},
},
},
{
Name: "emptyUpstream",
ErrorMsg: "",
Endpoints: []resolver.Endpoint{},
},
},
}
})

When("collecting NGF resource counts", func() {
Expand Down Expand Up @@ -314,6 +324,24 @@ var _ = Describe("Collector", Ordered, func() {
Expect(expData).To(Equal(data))
})

It("ignores invalid and empty upstreams", func() {
fakeGraphGetter.GetLatestGraphReturns(&graph.Graph{})
fakeConfigurationGetter.GetLatestConfigurationReturns(invalidUpstreamsConfig)
expData.NGFResourceCounts = telemetry.NGFResourceCounts{
Gateways: 0,
GatewayClasses: 0,
HTTPRoutes: 0,
Secrets: 0,
Services: 0,
Endpoints: 0,
}

data, err := dataCollector.Collect(ctx)

Expect(err).To(BeNil())
Expect(expData).To(Equal(data))
})

When("it encounters an error while collecting data", func() {
BeforeEach(func() {
fakeGraphGetter.GetLatestGraphReturns(&graph.Graph{})
Expand Down

0 comments on commit 89c41d5

Please sign in to comment.