@@ -183,8 +183,23 @@ func deleteAllPods(t *testing.T, namespace string) {
183
183
t .Log (errPod )
184
184
}
185
185
186
- func checkPodsLogs (t * testing.T , kubeClient * kubernetes.Clientset , message string , newLogsOnly ... bool ) {
187
- r , _ := regexp .Compile (message )
186
+ func logLineTime (t * testing.T , pattern string ) time.Time {
187
+ startOfLine := `\S\d{2}\d{2}\s\d{2}:\d{2}:\d{2}\.\d{6}\s*\d+\s\S+\.go:\d+]\s`
188
+ str := checkPodsLogs (t , clientset , startOfLine + pattern )
189
+ lineStart := regexp .MustCompile (startOfLine )
190
+ if lineStart .MatchString (str [22 :]) {
191
+ t .Fatal ("invalid logLineTime pattern, it matched more lines" )
192
+ }
193
+ str = strings .Split (strings .Split (str , "." )[0 ], " " )[1 ]
194
+ time1 , err := time .Parse ("15:04:05" , str )
195
+ e (t , err , "time parsing fail" )
196
+ return time1
197
+
198
+ }
199
+
200
+ func checkPodsLogs (t * testing.T , kubeClient * kubernetes.Clientset , message string , newLogsOnly ... bool ) string {
201
+ r , err := regexp .Compile (message )
202
+ e (t , err ,"Regex compilation failed" )
188
203
newPods , err := kubeClient .CoreV1 ().Pods ("openshift-insights" ).List (metav1.ListOptions {})
189
204
if err != nil {
190
205
t .Fatal (err .Error ())
@@ -194,6 +209,7 @@ func checkPodsLogs(t *testing.T, kubeClient *kubernetes.Clientset, message strin
194
209
if len (newLogsOnly )== 1 && newLogsOnly [0 ] {
195
210
logOptions = & corev1.PodLogOptions {SinceTime :& timeNow }
196
211
}
212
+ result := ""
197
213
for _ , newPod := range newPods .Items {
198
214
pod , err := kubeClient .CoreV1 ().Pods ("openshift-insights" ).Get (newPod .Name , metav1.GetOptions {})
199
215
if err != nil {
@@ -214,7 +230,7 @@ func checkPodsLogs(t *testing.T, kubeClient *kubernetes.Clientset, message strin
214
230
}
215
231
log := buf .String ()
216
232
217
- result : = r .FindString (log ) //strings.Contains(log, message)
233
+ result = r .FindString (log ) //strings.Contains(log, message)
218
234
if result == "" {
219
235
t .Logf ("No %s in logs\n " , message )
220
236
t .Logf ("Logs for verification: ****\n %s" , log )
@@ -228,6 +244,7 @@ func checkPodsLogs(t *testing.T, kubeClient *kubernetes.Clientset, message strin
228
244
t .Error (errLog )
229
245
}
230
246
}
247
+ return result
231
248
}
232
249
233
250
func forceUpdateSecret (ns string , secretName string , secret * v1.Secret ) error {
0 commit comments