(t *testing.T)
| 227 | } |
| 228 | |
| 229 | func TestLogging(t *testing.T) { |
| 230 | const routes = ` |
| 231 | r1_1: Path("/foo") -> "https://foo.example.org"; |
| 232 | r1_2: Path("/bar") -> "https://bar.example.org"; |
| 233 | r1_3: Path("/baz") -> "https://baz.example.org"; |
| 234 | r1_4: Path("/qux") -> "https://qux.example.org"; |
| 235 | r1_5: Path("/quux") -> "https://quux.example.org"; |
| 236 | ` |
| 237 | |
| 238 | init := func(l logging.Logger, client routing.DataClient, suppress bool) *routing.Routing { |
| 239 | return routing.New(routing.Options{ |
| 240 | DataClients: []routing.DataClient{client}, |
| 241 | Log: l, |
| 242 | SuppressLogs: suppress, |
| 243 | }) |
| 244 | } |
| 245 | |
| 246 | testUpdate := func( |
| 247 | t *testing.T, suppress bool, |
| 248 | initQuery string, initCount int, |
| 249 | upsertQuery string, upsertCount int, |
| 250 | deleteQuery string, deleteCount int, |
| 251 | ) { |
| 252 | client, err := testdataclient.NewDoc(routes) |
| 253 | if err != nil { |
| 254 | t.Error(err) |
| 255 | return |
| 256 | } |
| 257 | defer client.Close() |
| 258 | |
| 259 | testLog := loggingtest.New() |
| 260 | defer testLog.Close() |
| 261 | |
| 262 | rt := init(testLog, client, suppress) |
| 263 | defer rt.Close() |
| 264 | |
| 265 | if err := testLog.WaitFor("route settings applied", 120*time.Millisecond); err != nil { |
| 266 | t.Error(err) |
| 267 | return |
| 268 | } |
| 269 | |
| 270 | count := testLog.Count(initQuery) |
| 271 | if count != initCount { |
| 272 | t.Error("unexpected count of log entries", count) |
| 273 | t.Log("expected", initCount, initQuery) |
| 274 | t.Log("got ", count) |
| 275 | return |
| 276 | } |
| 277 | |
| 278 | testLog.Reset() |
| 279 | |
| 280 | client.UpdateDoc( |
| 281 | `r1_1: Path("/foo_mod") -> "https://foo.example.org"; |
| 282 | r1_4: Path("/qux_mod") -> "https://qux.example.org"`, |
| 283 | []string{"r1_2"}, |
| 284 | ) |
| 285 | |
| 286 | if err := testLog.WaitFor("route settings applied", 120*time.Millisecond); err != nil { |
nothing calls this directly
no test coverage detected
searching dependent graphs…