|
17 | 17 | package container |
18 | 18 |
|
19 | 19 | import ( |
| 20 | + "encoding/json" |
20 | 21 | "errors" |
| 22 | + "fmt" |
21 | 23 | "strings" |
22 | 24 | "testing" |
23 | 25 | "time" |
@@ -83,6 +85,8 @@ func TestContainerHealthCheckBasic(t *testing.T) { |
83 | 85 | Output: expect.All(func(stdout string, t tig.T) { |
84 | 86 | inspect := nerdtest.InspectContainer(helpers, data.Identifier()) |
85 | 87 | h := inspect.State.Health |
| 88 | + debug, _ := json.MarshalIndent(h, "", " ") |
| 89 | + t.Log(string(debug)) |
86 | 90 | assert.Assert(t, h != nil, "expected health state to be present") |
87 | 91 | assert.Equal(t, healthcheck.Healthy, h.Status) |
88 | 92 | assert.Equal(t, 0, h.FailingStreak) |
@@ -158,6 +162,8 @@ func TestContainerHealthCheckAdvance(t *testing.T) { |
158 | 162 | Output: expect.All(func(stdout string, t tig.T) { |
159 | 163 | inspect := nerdtest.InspectContainer(helpers, data.Identifier()) |
160 | 164 | h := inspect.State.Health |
| 165 | + debug, _ := json.MarshalIndent(h, "", " ") |
| 166 | + t.Log(string(debug)) |
161 | 167 | assert.Assert(t, h != nil, "expected health state") |
162 | 168 | assert.Equal(t, h.FailingStreak, 1) |
163 | 169 | assert.Assert(t, len(inspect.State.Health.Log) > 0, "expected health log to have entries") |
@@ -194,6 +200,8 @@ func TestContainerHealthCheckAdvance(t *testing.T) { |
194 | 200 | Output: expect.All(func(stdout string, t tig.T) { |
195 | 201 | inspect := nerdtest.InspectContainer(helpers, data.Identifier()) |
196 | 202 | h := inspect.State.Health |
| 203 | + debug, _ := json.MarshalIndent(h, "", " ") |
| 204 | + t.Log(string(debug)) |
197 | 205 | assert.Assert(t, h != nil, "expected health state") |
198 | 206 | assert.Equal(t, h.Status, healthcheck.Unhealthy) |
199 | 207 | assert.Equal(t, h.FailingStreak, 2) |
@@ -224,6 +232,8 @@ func TestContainerHealthCheckAdvance(t *testing.T) { |
224 | 232 | Output: expect.All(func(stdout string, t tig.T) { |
225 | 233 | inspect := nerdtest.InspectContainer(helpers, data.Identifier()) |
226 | 234 | h := inspect.State.Health |
| 235 | + debug, _ := json.MarshalIndent(h, "", " ") |
| 236 | + t.Log(string(debug)) |
227 | 237 | assert.Assert(t, h != nil, "expected health state") |
228 | 238 | assert.Equal(t, h.Status, healthcheck.Starting) |
229 | 239 | assert.Equal(t, h.FailingStreak, 0) |
@@ -253,6 +263,8 @@ func TestContainerHealthCheckAdvance(t *testing.T) { |
253 | 263 | Output: expect.All(func(stdout string, t tig.T) { |
254 | 264 | inspect := nerdtest.InspectContainer(helpers, data.Identifier()) |
255 | 265 | h := inspect.State.Health |
| 266 | + debug, _ := json.MarshalIndent(h, "", " ") |
| 267 | + t.Log(string(debug)) |
256 | 268 | assert.Assert(t, h != nil, "expected health state") |
257 | 269 | assert.Equal(t, h.Status, healthcheck.Unhealthy) |
258 | 270 | assert.Equal(t, h.FailingStreak, 1) |
@@ -303,6 +315,8 @@ func TestContainerHealthCheckAdvance(t *testing.T) { |
303 | 315 | Output: expect.All(func(_ string, t tig.T) { |
304 | 316 | inspect := nerdtest.InspectContainer(helpers, data.Identifier()) |
305 | 317 | h := inspect.State.Health |
| 318 | + debug, _ := json.MarshalIndent(h, "", " ") |
| 319 | + t.Log(string(debug)) |
306 | 320 | assert.Assert(t, h != nil, "expected health state") |
307 | 321 | assert.Equal(t, h.Status, healthcheck.Healthy) |
308 | 322 | assert.Assert(t, len(h.Log) > 0) |
@@ -334,6 +348,8 @@ func TestContainerHealthCheckAdvance(t *testing.T) { |
334 | 348 | Output: expect.All(func(stdout string, t tig.T) { |
335 | 349 | inspect := nerdtest.InspectContainer(helpers, data.Identifier()) |
336 | 350 | h := inspect.State.Health |
| 351 | + debug, _ := json.MarshalIndent(h, "", " ") |
| 352 | + t.Log(string(debug)) |
337 | 353 | assert.Assert(t, h != nil, "expected health state") |
338 | 354 | assert.Equal(t, h.Status, healthcheck.Healthy) |
339 | 355 | assert.Assert(t, h.FailingStreak == 0) |
@@ -365,6 +381,8 @@ func TestContainerHealthCheckAdvance(t *testing.T) { |
365 | 381 | Output: expect.All(func(stdout string, t tig.T) { |
366 | 382 | inspect := nerdtest.InspectContainer(helpers, data.Identifier()) |
367 | 383 | h := inspect.State.Health |
| 384 | + debug, _ := json.MarshalIndent(h, "", " ") |
| 385 | + t.Log(string(debug)) |
368 | 386 | assert.Assert(t, h != nil, "expected health state") |
369 | 387 | assert.Equal(t, h.Status, healthcheck.Healthy) |
370 | 388 | assert.Equal(t, h.FailingStreak, 0) |
@@ -398,11 +416,13 @@ func TestContainerHealthCheckAdvance(t *testing.T) { |
398 | 416 | Output: expect.All(func(_ string, t tig.T) { |
399 | 417 | inspect := nerdtest.InspectContainer(helpers, data.Identifier()) |
400 | 418 | h := inspect.State.Health |
| 419 | + debug, _ := json.MarshalIndent(h, "", " ") |
| 420 | + t.Log(string(debug)) |
401 | 421 | assert.Assert(t, h != nil, "expected health state") |
402 | 422 | assert.Equal(t, h.Status, healthcheck.Healthy) |
403 | 423 | assert.Assert(t, len(h.Log) >= 3, "expected at least 3 health log entries") |
404 | 424 | for _, log := range h.Log { |
405 | | - assert.Assert(t, len(log.Output) >= 1024, "each output should be >= 1024 bytes") |
| 425 | + assert.Assert(t, len(log.Output) >= 1024, fmt.Sprintf("each output should be >= 1024 bytes, was: %s", log.Output)) |
406 | 426 | } |
407 | 427 | }), |
408 | 428 | } |
@@ -434,6 +454,8 @@ func TestContainerHealthCheckAdvance(t *testing.T) { |
434 | 454 | Output: expect.All(func(_ string, t tig.T) { |
435 | 455 | inspect := nerdtest.InspectContainer(helpers, data.Identifier()) |
436 | 456 | h := inspect.State.Health |
| 457 | + debug, _ := json.MarshalIndent(h, "", " ") |
| 458 | + t.Log(string(debug)) |
437 | 459 | assert.Assert(t, h != nil, "expected health state") |
438 | 460 | assert.Equal(t, h.Status, healthcheck.Unhealthy) |
439 | 461 | assert.Assert(t, len(h.Log) <= 5, "expected health log to contain at most 5 entries") |
@@ -462,6 +484,8 @@ func TestContainerHealthCheckAdvance(t *testing.T) { |
462 | 484 | Output: expect.All(func(_ string, t tig.T) { |
463 | 485 | inspect := nerdtest.InspectContainer(helpers, data.Identifier()) |
464 | 486 | h := inspect.State.Health |
| 487 | + debug, _ := json.MarshalIndent(h, "", " ") |
| 488 | + t.Log(string(debug)) |
465 | 489 | assert.Assert(t, h != nil, "expected health state") |
466 | 490 | assert.Equal(t, h.Status, healthcheck.Healthy) |
467 | 491 | assert.Equal(t, h.FailingStreak, 0) |
@@ -499,6 +523,8 @@ func TestContainerHealthCheckAdvance(t *testing.T) { |
499 | 523 | Output: expect.All(func(stdout string, t tig.T) { |
500 | 524 | inspect := nerdtest.InspectContainer(helpers, data.Identifier()) |
501 | 525 | h := inspect.State.Health |
| 526 | + debug, _ := json.MarshalIndent(h, "", " ") |
| 527 | + t.Log(string(debug)) |
502 | 528 | assert.Assert(t, h != nil, "expected health state") |
503 | 529 | assert.Equal(t, h.Status, healthcheck.Unhealthy) |
504 | 530 | assert.Assert(t, h.FailingStreak >= 3) |
@@ -532,6 +558,8 @@ func TestContainerHealthCheckAdvance(t *testing.T) { |
532 | 558 | Output: expect.All(func(stdout string, t tig.T) { |
533 | 559 | inspect := nerdtest.InspectContainer(helpers, data.Identifier()) |
534 | 560 | h := inspect.State.Health |
| 561 | + debug, _ := json.MarshalIndent(h, "", " ") |
| 562 | + t.Log(string(debug)) |
535 | 563 | assert.Assert(t, h != nil, "expected health state") |
536 | 564 | assert.Equal(t, h.Status, healthcheck.Starting) |
537 | 565 | assert.Equal(t, h.FailingStreak, 0, "failing streak should not increase during start period") |
@@ -561,6 +589,8 @@ func TestContainerHealthCheckAdvance(t *testing.T) { |
561 | 589 | Output: expect.All(func(stdout string, t tig.T) { |
562 | 590 | inspect := nerdtest.InspectContainer(helpers, data.Identifier()) |
563 | 591 | h := inspect.State.Health |
| 592 | + debug, _ := json.MarshalIndent(h, "", " ") |
| 593 | + t.Log(string(debug)) |
564 | 594 | assert.Assert(t, h != nil, "expected health state") |
565 | 595 | assert.Equal(t, h.Status, healthcheck.Healthy, "expected healthy status even during start-period") |
566 | 596 | assert.Equal(t, h.FailingStreak, 0) |
|
0 commit comments