(t *testing.T)
| 126 | } |
| 127 | |
| 128 | func TestLoggerWith(t *testing.T) { |
| 129 | tests := []struct { |
| 130 | name string |
| 131 | initialFields []Field |
| 132 | withMethod func(*Logger, ...Field) *Logger |
| 133 | }{ |
| 134 | { |
| 135 | "regular non lazy logger", |
| 136 | []Field{Int("foo", 42)}, |
| 137 | (*Logger).With, |
| 138 | }, |
| 139 | { |
| 140 | "regular non lazy logger no initial fields", |
| 141 | []Field{}, |
| 142 | (*Logger).With, |
| 143 | }, |
| 144 | { |
| 145 | "lazy with logger", |
| 146 | []Field{Int("foo", 42)}, |
| 147 | (*Logger).WithLazy, |
| 148 | }, |
| 149 | { |
| 150 | "lazy with logger no initial fields", |
| 151 | []Field{}, |
| 152 | (*Logger).WithLazy, |
| 153 | }, |
| 154 | } |
| 155 | for _, tt := range tests { |
| 156 | t.Run(tt.name, func(t *testing.T) { |
| 157 | withLogger(t, DebugLevel, opts(Fields(tt.initialFields...)), func(logger *Logger, logs *observer.ObservedLogs) { |
| 158 | // Child loggers should have copy-on-write semantics, so two children |
| 159 | // shouldn't stomp on each other's fields or affect the parent's fields. |
| 160 | tt.withMethod(logger).Info("") |
| 161 | tt.withMethod(logger, String("one", "two")).Info("") |
| 162 | tt.withMethod(logger, String("three", "four")).Info("") |
| 163 | tt.withMethod(logger, String("five", "six")).With(String("seven", "eight")).Info("") |
| 164 | logger.Info("") |
| 165 | |
| 166 | assert.Equal(t, []observer.LoggedEntry{ |
| 167 | {Context: tt.initialFields}, |
| 168 | {Context: append(tt.initialFields, String("one", "two"))}, |
| 169 | {Context: append(tt.initialFields, String("three", "four"))}, |
| 170 | {Context: append(tt.initialFields, String("five", "six"), String("seven", "eight"))}, |
| 171 | {Context: tt.initialFields}, |
| 172 | }, logs.AllUntimed(), "Unexpected cross-talk between child loggers.") |
| 173 | }) |
| 174 | }) |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | func TestLoggerWithCaptures(t *testing.T) { |
| 179 | type withF func(*Logger, ...Field) *Logger |
nothing calls this directly
no test coverage detected