MCPcopy
hub / github.com/etcd-io/etcd / TestEncodeTimePrecisionToMicroSeconds

Function TestEncodeTimePrecisionToMicroSeconds

client/pkg/logutil/zap_test.go:39–59  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

37)
38
39func TestEncodeTimePrecisionToMicroSeconds(t *testing.T) {
40 buf := bytes.NewBuffer(nil)
41 syncer := zapcore.AddSync(buf)
42 zc := zapcore.NewCore(
43 zapcore.NewJSONEncoder(DefaultZapLoggerConfig.EncoderConfig),
44 syncer,
45 zap.NewAtomicLevelAt(zap.InfoLevel),
46 )
47
48 lg := zap.New(zc)
49 lg.Info("TestZapLog")
50 fields := commonLogFields{}
51 require.NoError(t, json.Unmarshal(buf.Bytes(), &fields))
52 // example 1: 2024-06-06T23:37:21.948385Z
53 // example 2 with zone offset: 2024-06-06T16:16:44.176778-0700
54 regex := `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.(\d+)(Z|[+-]\d{4})`
55 re := regexp.MustCompile(regex)
56 matches := re.FindStringSubmatch(fields.Timestamp)
57 require.Len(t, matches, 3)
58 require.Lenf(t, matches[1], fractionSecondsPrecision, "unexpected timestamp %s", fields.Timestamp)
59}
60
61func TestMergeOutputPaths(t *testing.T) {
62 tests := []struct {

Callers

nothing calls this directly

Calls 3

InfoMethod · 0.80
UnmarshalMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…