@@ -51,7 +51,7 @@ const (
51
51
type logMessage struct {
52
52
timestamp time.Time
53
53
stream streamType
54
- log [] byte
54
+ log string
55
55
}
56
56
57
57
var _ = framework .KubeDescribe ("Container" , func () {
@@ -127,7 +127,7 @@ var _ = framework.KubeDescribe("Container", func() {
127
127
128
128
By ("test execSync" )
129
129
cmd := []string {"echo" , "hello" }
130
- expectedLogMessage := [] byte ( "hello" + " \n ")
130
+ expectedLogMessage := "hello\n "
131
131
verifyExecSyncOutput (rc , containerID , cmd , expectedLogMessage )
132
132
})
133
133
})
@@ -216,11 +216,8 @@ var _ = framework.KubeDescribe("Container", func() {
216
216
}, time .Minute , time .Second * 4 ).Should (Equal (runtimeapi .ContainerState_CONTAINER_EXITED ))
217
217
218
218
By ("check the log context" )
219
- expectedLogMessage := & logMessage {
220
- log : []byte (defaultLog + "\n " ),
221
- stream : stdoutType ,
222
- }
223
- verifyLogContents (podConfig , logPath , expectedLogMessage )
219
+ expectedLogMessage := defaultLog + "\n "
220
+ verifyLogContents (podConfig , logPath , expectedLogMessage , stdoutType )
224
221
})
225
222
226
223
It ("runtime should support reopening container log [Conformance]" , func () {
@@ -363,21 +360,21 @@ func listContainerForID(c internalapi.RuntimeService, containerID string) []*run
363
360
}
364
361
365
362
// execSyncContainer test execSync for containerID and make sure the response is right.
366
- func execSyncContainer (c internalapi.RuntimeService , containerID string , command []string ) [] byte {
363
+ func execSyncContainer (c internalapi.RuntimeService , containerID string , command []string ) string {
367
364
By ("execSync for containerID: " + containerID )
368
365
stdout , stderr , err := c .ExecSync (containerID , command , time .Duration (defaultExecSyncTimeout )* time .Second )
369
366
framework .ExpectNoError (err , "failed to execSync in container %q" , containerID )
370
367
Expect (stderr ).To (BeNil (), "The stderr should be nil." )
371
368
framework .Logf ("Execsync succeed" )
372
369
373
- return stdout
370
+ return string ( stdout )
374
371
}
375
372
376
373
// execSyncContainer test execSync for containerID and make sure the response is right.
377
- func verifyExecSyncOutput (c internalapi.RuntimeService , containerID string , command []string , expectedLogMessage [] byte ) {
374
+ func verifyExecSyncOutput (c internalapi.RuntimeService , containerID string , command []string , expectedLogMessage string ) {
378
375
By ("verify execSync output" )
379
376
stdout := execSyncContainer (c , containerID , command )
380
- Expect (string ( stdout )) .To (Equal (string ( expectedLogMessage )) , "The stdout output of execSync should be %s" , string ( expectedLogMessage ) )
377
+ Expect (stdout ).To (Equal (expectedLogMessage ), "The stdout output of execSync should be %s" , expectedLogMessage )
381
378
framework .Logf ("verfiy Execsync output succeed" )
382
379
}
383
380
@@ -466,7 +463,7 @@ func parseDockerJSONLog(log []byte, msg *logMessage) {
466
463
467
464
msg .timestamp = l .Created
468
465
msg .stream = streamType (l .Stream )
469
- msg .log = [] byte ( l .Log )
466
+ msg .log = l .Log
470
467
}
471
468
472
469
// parseCRILog parses logs in CRI log format.
@@ -486,7 +483,7 @@ func parseCRILog(log string, msg *logMessage) {
486
483
msg .timestamp = timeStamp
487
484
msg .stream = streamType (stream )
488
485
// Skip the tag field.
489
- msg .log = [] byte ( logMessage [3 ] + "\n " )
486
+ msg .log = logMessage [3 ] + "\n "
490
487
}
491
488
492
489
// parseLogLine parses log by row.
@@ -523,12 +520,16 @@ func parseLogLine(podConfig *runtimeapi.PodSandboxConfig, logPath string) []logM
523
520
}
524
521
525
522
// verifyLogContents verifies the contents of container log.
526
- func verifyLogContents (podConfig * runtimeapi.PodSandboxConfig , logPath string , expectedLogMessage * logMessage ) {
523
+ func verifyLogContents (podConfig * runtimeapi.PodSandboxConfig , logPath string , log string , stream streamType ) {
527
524
By ("verify log contents" )
528
- log := parseLogLine (podConfig , logPath )
525
+ msgs := parseLogLine (podConfig , logPath )
529
526
530
- for _ , msg := range log {
531
- Expect (string (msg .log )).To (Equal (string (expectedLogMessage .log )), "Log should be %s" , string (expectedLogMessage .log ))
532
- Expect (string (msg .stream )).To (Equal (string (expectedLogMessage .stream )), "Stream should be %s" , string (expectedLogMessage .stream ))
527
+ found := false
528
+ for _ , msg := range msgs {
529
+ if msg .log == log && msg .stream == stream {
530
+ found = true
531
+ break
532
+ }
533
533
}
534
+ Expect (found ).To (BeTrue (), "expected log %q (stream=%q) not found in logs %+v" , log , stream , msgs )
534
535
}
0 commit comments