Skip to content

Add CLI end-to-end tests for docs examples and output formats - #52

Merged
andreagrandi merged 1 commit into
masterfrom
cli-e2e-docs-tests
May 20, 2026
Merged

Add CLI end-to-end tests for docs examples and output formats#52
andreagrandi merged 1 commit into
masterfrom
cli-e2e-docs-tests

Conversation

@andreagrandi

Copy link
Copy Markdown
Owner

Summary

Adds CLI end-to-end tests that exercise the full command path — arg parsing, validation, config, the real HTTP client, response parsing, and output formatting — against a mocked Scalyr server. Only the HTTP response is mocked (via httptest.Server); no real Scalyr credentials are required.

Closes #43.

What's covered

  • internal/cli/e2e_test.go (new):
    • TestE2EQueryOutputFormatsquery across all 6 formats (multiline, singleline, compact, csv, json, json-pretty) with exact-string / JSONEq assertions.
    • TestE2EQueryColumnsCSV, TestE2EQueryFieldsJSON--columns and --fields shaping output.
    • TestE2EQueryNonTTYDefaultsToJSON — documented pipeline fallback to JSON.
    • TestE2EQueryRequestPayload — verifies docs-example flags map into the request body.
    • TestE2E{PowerQuery,NumericQuery,FacetQuery,TimeseriesQuery}OutputFormats — csv/json/json-pretty per command.
    • TestE2EDocsExamples — one literal README invocation per command.

Design notes

  • runCLI helper spins up a mock server, points --token/--server at it, captures stdout, and returns the parsed request body.
  • resetCLIFlags restores all flag globals to defaults before each run so values don't leak across rootCmd executions.

Acceptance criteria

  • Representative docs examples are exercised in tests.
  • Output format regressions are caught.
  • Tests do not require real Scalyr credentials.

Test plan

  • go test -race ./... passes.
  • gofmt / go vet clean.

Exercise the full CLI path (arg parsing, validation, config, HTTP client,
response parsing, output formatting) against a mocked Scalyr server, with
no real credentials required. Covers JSON, CSV, and human-readable output
formats for query, power-query, numeric-query, facet-query, and
timeseries-query, plus representative README examples (#43).
@andreagrandi
andreagrandi merged commit a9c0a52 into master May 20, 2026
7 checks passed
@andreagrandi
andreagrandi deleted the cli-e2e-docs-tests branch May 20, 2026 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add CLI end-to-end tests for docs examples and output formats

1 participant