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

ktesting improvements #365

Merged
merged 3 commits into from
Feb 3, 2023
Merged

Commits on Feb 2, 2023

  1. ktesting: use klog-like header

    In practice, replacing normal klog text output with ktesting lost the time
    stamps. This is perhaps not important for unit tests, but for benchmarking
    those can be crucial.
    
    Now ktesting uses a stripped down klog header:
    - The source code location comes first, because
      that is printed by the testing package.
    - Instead if INFO and ERROR, the short I and E are used.
    - The useless tid/pid part isn't present.
    
    Example:
    
        $ go test -v ./ktesting/example/
        === RUN   TestKlogr
            example_test.go:45: I0201 17:58:36.235936] hello world
            example_test.go:46: E0201 17:58:36.236052] failed err="failed: some error"
            example_test.go:47: I0201 17:58:36.236086] verbosity 1
            example_test.go:48: I0201 17:58:36.236110] main/helper: with prefix
            example_test.go:50: I0201 17:58:36.236154] key/value pairs int=1 float=2 pair="(1, 2)" raw={Name:joe NS:kube-system} kobj="kube-system/joe"
            example_test.go:57: I0201 17:58:36.236187] info message level 4
            example_test.go:58: I0201 17:58:36.236209] info message level 5
        --- PASS: TestKlogr (0.00s)
        PASS
    pohly committed Feb 2, 2023
    Configuration menu
    Copy the full SHA
    8b4cfd2 View commit details
    Browse the repository at this point in the history
  2. ktesting: capture log entries only if requested

    Most users won't need this feature. It was enabled by default to keep the API
    simple and because the primary goal was unit testing, but benchmarks also need
    this and there unnecessary overhead needs to be avoided.
    pohly committed Feb 2, 2023
    Configuration menu
    Copy the full SHA
    d113925 View commit details
    Browse the repository at this point in the history
  3. ktesting: allow overriding default formatter

    The intended usage is to replace fmt.Sprintf("%+v") with gomega.format.Object +
    YAML support, therefore the only public API change is in the (still
    experimental) ktesting.
    
    Internally the additional function pointer gets passed through via a new
    Formatter struct. To minimize the impact on klog and textlogger, the
    package-level functions still exist and use an empty Formatter.
    pohly committed Feb 2, 2023
    Configuration menu
    Copy the full SHA
    1b27ee8 View commit details
    Browse the repository at this point in the history