@@ -602,3 +602,122 @@ func TestContainerHealthCheckAdvance(t *testing.T) {
602602
603603 testCase .Run (t )
604604}
605+
606+ func TestHealthCheck_SystemdIntegration_Basic (t * testing.T ) {
607+ testCase := nerdtest .Setup ()
608+ testCase .Require = require .Not (nerdtest .Docker )
609+
610+ testCase .SubTests = []* test.Case {
611+ //{
612+ // Description: "Basic healthy container with systemd-triggered healthcheck",
613+ // Setup: func(data test.Data, helpers test.Helpers) {
614+ // helpers.Ensure("run", "-d", "--name", data.Identifier(),
615+ // "--health-cmd", "echo healthy",
616+ // "--health-interval", "2s",
617+ // testutil.CommonImage, "sleep", "30")
618+ // // Wait for a couple of healthchecks to execute
619+ // time.Sleep(5 * time.Second)
620+ // },
621+ // Cleanup: func(data test.Data, helpers test.Helpers) {
622+ // helpers.Anyhow("rm", "-f", data.Identifier())
623+ // },
624+ // Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
625+ // return &test.Expected{
626+ // ExitCode: 0,
627+ // Output: expect.All(func(stdout, _ string, t *testing.T) {
628+ // inspect := nerdtest.InspectContainer(helpers, data.Identifier())
629+ // h := inspect.State.Health
630+ // assert.Assert(t, h != nil, "expected health state to be present")
631+ // assert.Equal(t, h.Status, "healthy")
632+ // assert.Assert(t, len(h.Log) > 0, "expected at least one health check log entry")
633+ // }),
634+ // }
635+ // },
636+ //},
637+ //{
638+ // Description: "Kill stops healthcheck execution",
639+ // Setup: func(data test.Data, helpers test.Helpers) {
640+ // helpers.Ensure("run", "-d", "--name", data.Identifier(),
641+ // "--health-cmd", "echo healthy",
642+ // "--health-interval", "1s",
643+ // testutil.CommonImage, "sleep", "30")
644+ // time.Sleep(5 * time.Second) // Wait for at least one health check to execute
645+ // helpers.Ensure("kill", data.Identifier()) // Kill the container
646+ // time.Sleep(3 * time.Second) // Wait to allow any potential extra healthchecks (shouldn't happen)
647+ // },
648+ // Cleanup: func(data test.Data, helpers test.Helpers) {
649+ // helpers.Anyhow("rm", "-f", data.Identifier())
650+ // },
651+ // Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
652+ // return &test.Expected{
653+ // ExitCode: 0,
654+ // Output: expect.All(func(stdout, _ string, t *testing.T) {
655+ // inspect := nerdtest.InspectContainer(helpers, data.Identifier())
656+ // h := inspect.State.Health
657+ // assert.Assert(t, h != nil, "expected health state to be present")
658+ // assert.Assert(t, len(h.Log) > 0, "expected at least one health check log entry")
659+ //
660+ // // Get container FinishedAt timestamp
661+ // containerEnd, err := time.Parse(time.RFC3339Nano, inspect.State.FinishedAt)
662+ // assert.NilError(t, err, "parsing container FinishedAt")
663+ //
664+ // // Assert all healthcheck log start times are before container finished
665+ // for _, entry := range h.Log {
666+ // assert.NilError(t, err, "parsing healthcheck Start time")
667+ // assert.Assert(t, entry.Start.Before(containerEnd), "healthcheck ran after container was killed")
668+ // }
669+ // }),
670+ // }
671+ // },
672+ //},
673+
674+ // {
675+ // Description: "Pause/unpause halts and resumes healthcheck execution",
676+ // Setup: func(data test.Data, helpers test.Helpers) {
677+ // data.Labels().Set("cID", data.Identifier())
678+ // helpers.Ensure("run", "-d", "--name", data.Identifier(),
679+ // "--health-cmd", "echo healthy",
680+ // "--health-interval", "1s",
681+ // testutil.CommonImage, "sleep", "30")
682+ // time.Sleep(4 * time.Second)
683+
684+ // // Inspect using raw command
685+ // helpers.Command("container", "inspect", data.Labels().Get("cID")).
686+ // Run(&test.Expected{
687+ // ExitCode: expect.ExitCodeNoCheck,
688+ // Output: func(stdout string, _ string, t *testing.T) {
689+ // var dc []dockercompat.Container
690+ // err := json.Unmarshal([]byte(stdout), &dc)
691+ // assert.NilError(t, err)
692+ // assert.Equal(t, len(dc), 1)
693+ // h := dc[0].State.Health
694+ // assert.Assert(t, h != nil, "expected health state to be present")
695+ // data.Labels().Set("healthStatus", h.Status)
696+ // data.Labels().Set("logCount", strconv.Itoa(len(h.Log)))
697+ // fmt.Printf("📋 Setup Inspect: Status=%s, LogCount=%s\n", h.Status, strconv.Itoa(len(h.Log)))
698+ // },
699+ // })
700+ // },
701+ // Cleanup: func(data test.Data, helpers test.Helpers) {
702+ // helpers.Anyhow("rm", "-f", data.Identifier())
703+ // },
704+ // Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
705+ // return &test.Expected{
706+ // ExitCode: 0,
707+ // Output: expect.All(func(stdout, _ string, t *testing.T) {
708+ // before := data.Labels().Get("logCountBeforePause")
709+ // after := data.Labels().Get("logCountAfterUnpause")
710+
711+ // beforeCount, _ := strconv.Atoi(before)
712+ // afterCount, _ := strconv.Atoi(after)
713+
714+ // assert.Assert(t, afterCount > beforeCount,
715+ // "expected more healthchecks after unpause (got %d → %d)", beforeCount, afterCount)
716+ // }),
717+ // }
718+ // },
719+ // },
720+ }
721+
722+ testCase .Run (t )
723+ }
0 commit comments