INNER CODE UNIT · Go

TestJSONLogFormat

openkruise/kruise-game · main_test.go:57

func TestJSONLogFormat(t *testing.T) {
	var buf bytes.Buffer
	opts, _ := newTestOptions(t, &buf, "--log-format=json")
	logger := zap.New(zap.UseFlagOptions(&opts.ZapOptions))
	if kv := logging.ResourceKeyValues(); len(kv) > 0 {
		logger = logger.WithValues(kv...)
	}
	buf.Reset()
	logger.Info("hello")

	lines := bytes.Split(bytes.TrimSpace(buf.Bytes()), []byte("\n"))
	if len(lines) != 1 {
		t.Fatalf("expected single line JSON, got %d lines: %q", len(lines), buf.String())
	}
	var m map[string]interface{}
	if err := json.Unmarshal(lines[0], &m); err != nil {
		t.Fatalf("expected JSON log, got %v: %s", err, buf.String())
	}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…