@@ -22,6 +22,7 @@ import (
2222 "fmt"
2323 "os"
2424 "path/filepath"
25+ "regexp"
2526 "strings"
2627
2728 . "github.com/onsi/ginkgo/v2"
4647 cancelWatches context.CancelFunc
4748 clusterResources * clusterctl.ApplyClusterTemplateAndWaitResult
4849 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}`
4952)
5053
5154// 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) {
224227 }
225228
226229 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 ) {
232240 Byf ("Found %q error" , expectedError )
233241 return expectedErrorFound
234242 }
235243 }
236244 }
237-
238245 return nil
239246 })
240247
0 commit comments