@@ -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+ errorLogRe = regexp .MustCompile (`(?m)^([IWEF]\d{4} \d{2}:\d{2}:\d{2}\.\d+.+?)(?=^[IWEF]\d{4} \d{2}:\d{2}:\d{2}\.\d+|$)` )
4951)
5052
5153// InvalidResourceSpec implements a test that verifies that creating a new cluster fails when the specified resource does not exist
@@ -224,13 +226,21 @@ func errorExistsInLog(logFolder string, expectedError string) (bool, error) {
224226 }
225227
226228 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 ) {
232- Byf ("Found %q error" , expectedError )
233- return expectedErrorFound
229+ logContent , err := os .ReadFile (path )
230+ if err != nil {
231+ return err
232+ }
233+
234+ matches := errorLogRe .FindAllStringSubmatch (string (logContent ), - 1 )
235+
236+ for _ , match := range matches {
237+ if len (match ) > 1 {
238+ logEntry := match [1 ]
239+ if strings .Contains (logEntry , expectedError ) &&
240+ strings .Contains (logEntry , clusterResources .Cluster .Namespace ) {
241+ Byf ("Found %q error" , expectedError )
242+ return expectedErrorFound
243+ }
234244 }
235245 }
236246 }
0 commit comments