TestJSONEncodeEntry is an more "integrated" test that makes it easier to get coverage on the json encoder (e.g. putJSONEncoder, let alone EncodeEntry itself) than the tests in json_encoder_impl_test.go; it needs to be in the zapcore_test package, so that it can import the toplevel zap package for fi
(t *testing.T)
| 37 | // zapcore_test package, so that it can import the toplevel zap package for |
| 38 | // field constructor convenience. |
| 39 | func TestJSONEncodeEntry(t *testing.T) { |
| 40 | type bar struct { |
| 41 | Key string `json:"key"` |
| 42 | Val float64 `json:"val"` |
| 43 | } |
| 44 | |
| 45 | type foo struct { |
| 46 | A string `json:"aee"` |
| 47 | B int `json:"bee"` |
| 48 | C float64 `json:"cee"` |
| 49 | D []bar `json:"dee"` |
| 50 | } |
| 51 | |
| 52 | tests := []struct { |
| 53 | desc string |
| 54 | expected string |
| 55 | ent zapcore.Entry |
| 56 | fields []zapcore.Field |
| 57 | }{ |
| 58 | { |
| 59 | desc: "info entry with some fields", |
| 60 | expected: `{ |
| 61 | "L": "info", |
| 62 | "T": "2018-06-19T16:33:42.000Z", |
| 63 | "N": "bob", |
| 64 | "M": "lob law", |
| 65 | "so": "passes", |
| 66 | "answer": 42, |
| 67 | "a_float32": 2.71, |
| 68 | "common_pie": 3.14, |
| 69 | "complex_value": "3.14-2.71i", |
| 70 | "null_value": null, |
| 71 | "array_with_null_elements": [{}, null, null, 2], |
| 72 | "such": { |
| 73 | "aee": "lol", |
| 74 | "bee": 123, |
| 75 | "cee": 0.9999, |
| 76 | "dee": [ |
| 77 | {"key": "pi", "val": 3.141592653589793}, |
| 78 | {"key": "tau", "val": 6.283185307179586} |
| 79 | ] |
| 80 | } |
| 81 | }`, |
| 82 | ent: zapcore.Entry{ |
| 83 | Level: zapcore.InfoLevel, |
| 84 | Time: time.Date(2018, 6, 19, 16, 33, 42, 99, time.UTC), |
| 85 | LoggerName: "bob", |
| 86 | Message: "lob law", |
| 87 | }, |
| 88 | fields: []zapcore.Field{ |
| 89 | zap.String("so", "passes"), |
| 90 | zap.Int("answer", 42), |
| 91 | zap.Float64("common_pie", 3.14), |
| 92 | zap.Float32("a_float32", 2.71), |
| 93 | zap.Complex128("complex_value", 3.14-2.71i), |
| 94 | // Cover special-cased handling of nil in AddReflect() and |
| 95 | // AppendReflect(). Note that for the latter, we explicitly test |
| 96 | // correct results for both the nil static interface{} value |
nothing calls this directly
no test coverage detected