Skip to content

Commit f6ed14e

Browse files
authored
Merge pull request #282 from Random-Liu/add-run-as-group-test
Add run as group test
2 parents 4403b80 + ef52269 commit f6ed14e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+4291
-2190
lines changed

pkg/validate/container.go

+19-18
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const (
5151
type logMessage struct {
5252
timestamp time.Time
5353
stream streamType
54-
log []byte
54+
log string
5555
}
5656

5757
var _ = framework.KubeDescribe("Container", func() {
@@ -127,7 +127,7 @@ var _ = framework.KubeDescribe("Container", func() {
127127

128128
By("test execSync")
129129
cmd := []string{"echo", "hello"}
130-
expectedLogMessage := []byte("hello" + "\n")
130+
expectedLogMessage := "hello\n"
131131
verifyExecSyncOutput(rc, containerID, cmd, expectedLogMessage)
132132
})
133133
})
@@ -216,11 +216,8 @@ var _ = framework.KubeDescribe("Container", func() {
216216
}, time.Minute, time.Second*4).Should(Equal(runtimeapi.ContainerState_CONTAINER_EXITED))
217217

218218
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)
224221
})
225222

226223
It("runtime should support reopening container log [Conformance]", func() {
@@ -363,21 +360,21 @@ func listContainerForID(c internalapi.RuntimeService, containerID string) []*run
363360
}
364361

365362
// 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 {
367364
By("execSync for containerID: " + containerID)
368365
stdout, stderr, err := c.ExecSync(containerID, command, time.Duration(defaultExecSyncTimeout)*time.Second)
369366
framework.ExpectNoError(err, "failed to execSync in container %q", containerID)
370367
Expect(stderr).To(BeNil(), "The stderr should be nil.")
371368
framework.Logf("Execsync succeed")
372369

373-
return stdout
370+
return string(stdout)
374371
}
375372

376373
// 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) {
378375
By("verify execSync output")
379376
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)
381378
framework.Logf("verfiy Execsync output succeed")
382379
}
383380

@@ -466,7 +463,7 @@ func parseDockerJSONLog(log []byte, msg *logMessage) {
466463

467464
msg.timestamp = l.Created
468465
msg.stream = streamType(l.Stream)
469-
msg.log = []byte(l.Log)
466+
msg.log = l.Log
470467
}
471468

472469
// parseCRILog parses logs in CRI log format.
@@ -486,7 +483,7 @@ func parseCRILog(log string, msg *logMessage) {
486483
msg.timestamp = timeStamp
487484
msg.stream = streamType(stream)
488485
// Skip the tag field.
489-
msg.log = []byte(logMessage[3] + "\n")
486+
msg.log = logMessage[3] + "\n"
490487
}
491488

492489
// parseLogLine parses log by row.
@@ -523,12 +520,16 @@ func parseLogLine(podConfig *runtimeapi.PodSandboxConfig, logPath string) []logM
523520
}
524521

525522
// 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) {
527524
By("verify log contents")
528-
log := parseLogLine(podConfig, logPath)
525+
msgs := parseLogLine(podConfig, logPath)
529526

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+
}
533533
}
534+
Expect(found).To(BeTrue(), "expected log %q (stream=%q) not found in logs %+v", log, stream, msgs)
534535
}

0 commit comments

Comments
 (0)