Add CLI end-to-end tests for docs examples and output formats - #52
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):TestE2EQueryOutputFormats—queryacross all 6 formats (multiline, singleline, compact, csv, json, json-pretty) with exact-string /JSONEqassertions.TestE2EQueryColumnsCSV,TestE2EQueryFieldsJSON—--columnsand--fieldsshaping 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
runCLIhelper spins up a mock server, points--token/--serverat it, captures stdout, and returns the parsed request body.resetCLIFlagsrestores all flag globals to defaults before each run so values don't leak acrossrootCmdexecutions.Acceptance criteria
Test plan
go test -race ./...passes.gofmt/go vetclean.