@@ -22,6 +22,7 @@ import (
22
22
"fmt"
23
23
"os"
24
24
"path/filepath"
25
+ "regexp"
25
26
"strings"
26
27
27
28
. "github.com/onsi/ginkgo/v2"
46
47
cancelWatches context.CancelFunc
47
48
clusterResources * clusterctl.ApplyClusterTemplateAndWaitResult
48
49
MachineInErrorMessage = "CloudStackMachine VM in error state. Deleting associated Machine"
50
+ // Pattern that matches start of Kubernetes log entries
51
+ logEntryPattern = `[IWEF]\d{4} \d{2}:\d{2}:\d{2}\.\d{6}`
49
52
)
50
53
51
54
// InvalidResourceSpec implements a test that verifies that creating a new cluster fails when the specified resource does not exist
@@ -224,17 +227,21 @@ func errorExistsInLog(logFolder string, expectedError string) (bool, error) {
224
227
}
225
228
226
229
if strings .Contains (path , "manager.log" ) {
227
- log , _ := os .ReadFile (path )
228
- logLines := strings .Split (string (log ), "\n " )
229
- for _ , line := range logLines {
230
- if strings .Contains (line , expectedError ) &&
231
- strings .Contains (line , clusterResources .Cluster .Namespace ) {
230
+ logContent , err := os .ReadFile (path )
231
+ if err != nil {
232
+ return err
233
+ }
234
+
235
+ // Split log content by the log entry pattern
236
+ entries := regexp .MustCompile (logEntryPattern ).Split (string (logContent ), - 1 )
237
+ for _ , entry := range entries {
238
+ if strings .Contains (entry , expectedError ) &&
239
+ strings .Contains (entry , clusterResources .Cluster .Namespace ) {
232
240
Byf ("Found %q error" , expectedError )
233
241
return expectedErrorFound
234
242
}
235
243
}
236
244
}
237
-
238
245
return nil
239
246
})
240
247
0 commit comments