Skip to content

Commit 1f80e31

Browse files
committed
Allow testing for expected log entries in testNodeSourceEndpoints
This commit adds the required logic to be able to test for the existence (and absence) of certain log messages in testNodeSourceEndpoints. As an example, this is implemented for the tests around excludeUnschedulable. A side effect of using LogsToBuffer is that tests can't run in parallel due to the log buffer being shared across all parallel test cases. As such, these specific tests are now executed one after another.
1 parent 6494085 commit 1f80e31

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

source/node_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ func testNodeSourceEndpoints(t *testing.T) {
113113
unschedulable bool // default to false
114114
expected []*endpoint.Endpoint
115115
expectError bool
116+
expectedLogs []string
117+
expectedAbsentLogs []string
116118
}{
117119
{
118120
title: "node with short hostname returns one endpoint",
@@ -372,6 +374,9 @@ func testNodeSourceEndpoints(t *testing.T) {
372374
unschedulable: true,
373375
excludeUnschedulable: true,
374376
expected: []*endpoint.Endpoint{},
377+
expectedLogs: []string{
378+
"Skipping node node1 because it is unschedulable",
379+
},
375380
},
376381
{
377382
title: "unschedulable node returns node with excludeUnschedulable=false",
@@ -382,10 +387,15 @@ func testNodeSourceEndpoints(t *testing.T) {
382387
expected: []*endpoint.Endpoint{
383388
{RecordType: "A", DNSName: "node1", Targets: endpoint.Targets{"1.2.3.4"}},
384389
},
390+
expectedAbsentLogs: []string{
391+
"Skipping node node1 because it is unschedulable",
392+
},
385393
},
386394
} {
387395
tc := tc
388396
t.Run(tc.title, func(t *testing.T) {
397+
buf := testutils.LogsToBuffer(log.DebugLevel, t)
398+
389399
labelSelector := labels.Everything()
390400
if tc.labelSelector != "" {
391401
var err error
@@ -434,6 +444,14 @@ func testNodeSourceEndpoints(t *testing.T) {
434444

435445
// Validate returned endpoints against desired endpoints.
436446
validateEndpoints(t, endpoints, tc.expected)
447+
448+
for _, entry := range tc.expectedLogs {
449+
assert.Contains(t, buf.String(), entry)
450+
}
451+
452+
for _, entry := range tc.expectedAbsentLogs {
453+
assert.NotContains(t, buf.String(), entry)
454+
}
437455
})
438456
}
439457
}

0 commit comments

Comments
 (0)