Skip to content

Commit 89c41d5

Browse files
committed
Move test case around in collector tests
1 parent de6e3bc commit 89c41d5

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

internal/framework/runnables/cronjob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
type CronJobConfig struct {
1414
// Worker is the function that will be run for every cronjob iteration.
1515
Worker func(context.Context)
16-
// ReadyCh represents if the cronjob is ready to start.
16+
// ReadyCh delays the start of the job until the channel is closed.
1717
ReadyCh <-chan struct{}
1818
// Logger is the logger.
1919
Logger logr.Logger

internal/mode/static/telemetry/collector_test.go

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -162,22 +162,6 @@ var _ = Describe("Collector", Ordered, func() {
162162
},
163163
},
164164
},
165-
{
166-
Name: "upstream3",
167-
ErrorMsg: "there is an error here",
168-
Endpoints: []resolver.Endpoint{
169-
{
170-
Address: "endpoint1",
171-
Port: 80,
172-
}, {
173-
Address: "endpoint2",
174-
Port: 80,
175-
}, {
176-
Address: "endpoint3",
177-
Port: 80,
178-
},
179-
},
180-
},
181165
},
182166
}
183167

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

243227
Describe("NGF resource count collector", func() {
244228
var (
245-
graph1 *graph.Graph
246-
config1 *dataplane.Configuration
229+
graph1 *graph.Graph
230+
config1, invalidUpstreamsConfig *dataplane.Configuration
247231
)
248232

249233
BeforeAll(func() {
@@ -280,6 +264,32 @@ var _ = Describe("Collector", Ordered, func() {
280264
},
281265
},
282266
}
267+
268+
invalidUpstreamsConfig = &dataplane.Configuration{
269+
Upstreams: []dataplane.Upstream{
270+
{
271+
Name: "invalidUpstream",
272+
ErrorMsg: "there is an error here",
273+
Endpoints: []resolver.Endpoint{
274+
{
275+
Address: "endpoint1",
276+
Port: 80,
277+
}, {
278+
Address: "endpoint2",
279+
Port: 80,
280+
}, {
281+
Address: "endpoint3",
282+
Port: 80,
283+
},
284+
},
285+
},
286+
{
287+
Name: "emptyUpstream",
288+
ErrorMsg: "",
289+
Endpoints: []resolver.Endpoint{},
290+
},
291+
},
292+
}
283293
})
284294

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

327+
It("ignores invalid and empty upstreams", func() {
328+
fakeGraphGetter.GetLatestGraphReturns(&graph.Graph{})
329+
fakeConfigurationGetter.GetLatestConfigurationReturns(invalidUpstreamsConfig)
330+
expData.NGFResourceCounts = telemetry.NGFResourceCounts{
331+
Gateways: 0,
332+
GatewayClasses: 0,
333+
HTTPRoutes: 0,
334+
Secrets: 0,
335+
Services: 0,
336+
Endpoints: 0,
337+
}
338+
339+
data, err := dataCollector.Collect(ctx)
340+
341+
Expect(err).To(BeNil())
342+
Expect(expData).To(Equal(data))
343+
})
344+
317345
When("it encounters an error while collecting data", func() {
318346
BeforeEach(func() {
319347
fakeGraphGetter.GetLatestGraphReturns(&graph.Graph{})

0 commit comments

Comments
 (0)