Skip to content

enhancement: Add conditional test logging via environment variable #7

@jamestexas

Description

@jamestexas

Problem

The test suite contains many t.Logf() statements that are helpful for debugging but can be noisy during normal test runs. Currently, there's no way to conditionally enable/disable verbose test output.

Proposed Solution

Add support for conditional test logging via environment variable:

// Helper function
func logIfVerbose(t *testing.T, format string, args ...interface{}) {
    t.Helper()
    if os.Getenv("CMS_TEST_VERBOSE") == "1" {
        t.Logf(format, args...)
    }
}

// Usage in tests
logIfVerbose(t, "✓ SignDataWithSigner produced valid CMS signature")
logIfVerbose(t, "CMS signature length: %d bytes", len(signature))

Benefits

  • Cleaner test output by default (no debug logs)
  • Easy debugging when needed: CMS_TEST_VERBOSE=1 go test
  • Maintains existing debugging information for troubleshooting test failures
  • Consistent with Go testing patterns (similar to -v flag but more granular)

Implementation Notes

  • Add logIfVerbose helper to signer_test.go and verifier_test.go
  • Replace existing t.Logf() calls with logIfVerbose()
  • Document in test files and potentially in README/CONTRIBUTING.md
  • Could also support levels: CMS_TEST_VERBOSE=2 for even more detailed output

Related

This came up during code review feedback on PR #6 where Copilot suggested removing test logging statements. This enhancement would satisfy both needs: keep the valuable debugging info but make it opt-in.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions