1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/daemon/logger/journald/journald_test.go
Yong Tang 9528ea930c Sanitize docker labels when used as journald field names
This fix tries to address the issue raised in #23528 where
docker labels caused journald log error because journald
has special requirements on field names.

This fix addresses this issue by sanitize the labels per
requirements of journald.

Additional unit tests have been added to cover the changes.

This fix fixes #23528.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2016-08-05 15:20:47 -07:00

23 lines
647 B
Go

// +build linux
package journald
import (
"testing"
)
func TestSanitizeKeyMod(t *testing.T) {
entries := map[string]string{
"io.kubernetes.pod.name": "IO_KUBERNETES_POD_NAME",
"io?.kubernetes.pod.name": "IO__KUBERNETES_POD_NAME",
"?io.kubernetes.pod.name": "IO_KUBERNETES_POD_NAME",
"io123.kubernetes.pod.name": "IO123_KUBERNETES_POD_NAME",
"_io123.kubernetes.pod.name": "IO123_KUBERNETES_POD_NAME",
"__io123_kubernetes.pod.name": "IO123_KUBERNETES_POD_NAME",
}
for k, v := range entries {
if sanitizeKeyMod(k) != v {
t.Fatalf("Failed to sanitize %s, got %s, expected %s", k, sanitizeKeyMod(k), v)
}
}
}