moby/integration/system
Sebastiaan van Stijn 587ad8845a
integration/system: update TestInfoAPI to not use string-matching
This test was rewritten from an integration-cli test in commit
68d9beedbe, and originally implemented in
f4942ed864, which rewrote it from a unit-
test to an integration test.

Originally, it would check for the raw JSON response from the daemon, and
check for individual fields to be present in the output, but after commit
0fd5a65428, `client.Info()` was used, and
now the response is unmarshalled into a `system.Info`.

The remainder of the test remained the same in that rewrite, and as a
result were were now effectively testing if a `system.Info` struct,
when marshalled as JSON would show all the fields (surprise: it does).

TL;DR; the test would even pass with an empty `system.Info{}` struct,
which didn't provide much coverage, as it passed without a daemon:

    func TestInfoAPI(t *testing.T) {
        // always shown fields
        stringsToCheck := []string{
            "ID",
            "Containers",
            "ContainersRunning",
            "ContainersPaused",
            "ContainersStopped",
            "Images",
            "LoggingDriver",
            "OperatingSystem",
            "NCPU",
            "OSType",
            "Architecture",
            "MemTotal",
            "KernelVersion",
            "Driver",
            "ServerVersion",
            "SecurityOptions",
        }

        out := fmt.Sprintf("%+v", system.Info{})
        for _, linePrefix := range stringsToCheck {
            assert.Check(t, is.Contains(out, linePrefix))
        }
    }

This patch makes the test _slightly_ better by checking if the fields
are non-empty. More work is needed on this test though; currently it
uses the (already running) daemon, so it's hard to check for specific
fields to be correct (withouth knowing state of the daemon), but it's
not unlikely that other tests (partially) cover some of that. A TODO
comment was added to look into that (we should probably combine some
tests to prevent overlap, and make it easier to spot "gaps" as well).

While working on this, also moving the `SystemTime` into this test,
because that field is (no longer) dependent on "debug" state

(It is was actually this change that led me down this rabbit-hole)

                         ()_()
                         (-.-)
                        '(")(")'

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-11-03 10:17:15 +01:00
..
cgroupdriver_systemd_test.go api/types: move ContainerStartOptions to api/types/container 2023-10-12 11:29:24 +02:00
disk_usage_test.go Fix disk usage test 2023-10-18 21:20:54 -07:00
event_test.go Wire up tests to support otel tracing 2023-09-07 18:38:22 +00:00
info_linux_test.go Wire up tests to support otel tracing 2023-09-07 18:38:22 +00:00
info_test.go integration/system: update TestInfoAPI to not use string-matching 2023-11-03 10:17:15 +01:00
login_test.go Wire up tests to support otel tracing 2023-09-07 18:38:22 +00:00
main_test.go Wire up tests to support otel tracing 2023-09-07 18:38:22 +00:00
ping_test.go Wire up tests to support otel tracing 2023-09-07 18:38:22 +00:00
version_test.go Wire up tests to support otel tracing 2023-09-07 18:38:22 +00:00