Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli/command/system: TestEventsFormat: set cmd.Args to prevent test-failures #5695

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

thaJeztah
Copy link
Member

When running the tests with options set, such as -update for updating "golden" files, this test would pick up test arguments because no arguments were set to invoke the command;

go test . -update
Error: unknown shorthand flag: 'u' in -update
Usage:
  events [OPTIONS] [flags]

Flags:
  -f, --filter filter   Filter output based on conditions provided
      --format string   Format output using a custom template:
                        'json':             Print in JSON format
                        'TEMPLATE':         Print output using the given Go template.
                        Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates
  -h, --help            help for events
      --since string    Show all events created since timestamp
      --until string    Stream events until this timestamp

--- FAIL: TestEventsFormat (0.00s)
    --- FAIL: TestEventsFormat/default (0.00s)
        events_test.go:75: assertion failed: error is not nil: unknown shorthand flag: 'u' in -update
    --- FAIL: TestEventsFormat/json (0.00s)
        events_test.go:75: assertion failed: error is not nil: unknown shorthand flag: 'u' in -update
    --- FAIL: TestEventsFormat/json_template (0.00s)
        events_test.go:75: assertion failed: error is not nil: unknown shorthand flag: 'u' in -update
    --- FAIL: TestEventsFormat/json_action (0.00s)
        events_test.go:75: assertion failed: error is not nil: unknown shorthand flag: 'u' in -update

This patch:

  • changes the test to use command-arguments instead of manually setting the flag options; this also adds test-coverage for parsing actual command arguments.
  • discards stdout/stderr of the command to prevent noise in test output

- A picture of a cute animal (not mandatory but encouraged)

…ilures

When running the tests with options set, such as `-update` for updating
"golden" files, this test would pick up test arguments because no arguments
were set to invoke the command;

    go test . -update
    Error: unknown shorthand flag: 'u' in -update
    Usage:
      events [OPTIONS] [flags]

    Flags:
      -f, --filter filter   Filter output based on conditions provided
          --format string   Format output using a custom template:
                            'json':             Print in JSON format
                            'TEMPLATE':         Print output using the given Go template.
                            Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates
      -h, --help            help for events
          --since string    Show all events created since timestamp
          --until string    Stream events until this timestamp

    --- FAIL: TestEventsFormat (0.00s)
        --- FAIL: TestEventsFormat/default (0.00s)
            events_test.go:75: assertion failed: error is not nil: unknown shorthand flag: 'u' in -update
        --- FAIL: TestEventsFormat/json (0.00s)
            events_test.go:75: assertion failed: error is not nil: unknown shorthand flag: 'u' in -update
        --- FAIL: TestEventsFormat/json_template (0.00s)
            events_test.go:75: assertion failed: error is not nil: unknown shorthand flag: 'u' in -update
        --- FAIL: TestEventsFormat/json_action (0.00s)
            events_test.go:75: assertion failed: error is not nil: unknown shorthand flag: 'u' in -update

This patch:

- changes the test to use command-arguments instead of manually setting the
  flag options; this also adds test-coverage for parsing actual command arguments.
- discards stdout/stderr of the command to prevent noise in test output

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Dec 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.51%. Comparing base (91d097e) to head (73ff81b).
Report is 12 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5695   +/-   ##
=======================================
  Coverage   59.51%   59.51%           
=======================================
  Files         346      346           
  Lines       29379    29379           
=======================================
  Hits        17486    17486           
  Misses      10923    10923           
  Partials      970      970           

@thaJeztah
Copy link
Member Author

Failures are due to the docker / docker:dind image on hub being broken; docker-library/docker#520

@thaJeztah thaJeztah requested a review from a team December 16, 2024 22:15
@thaJeztah thaJeztah merged commit ecd1622 into docker:master Dec 17, 2024
104 checks passed
@thaJeztah thaJeztah deleted the fix_TestEventsFormat branch December 17, 2024 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants