-
Notifications
You must be signed in to change notification settings - Fork 58
miscellaneous documentation fixes #165
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c88f93e
remove outdated comment
a8907b5
add TESTING.md
731d7ed
prefer otel spec envvar over OTEL_CLI
15ef9e1
add a section on adding tests
06249ab
write nice top-of-file comments and make them similar
58ad62d
remove extra 'a'
ce0b6e1
add a note about CSV parsing of attributes & headers
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # Testing otel-cli | ||
|
|
||
| ## Synopsis | ||
|
|
||
| otel-cli's primary method of testing is functional, implemented in | ||
| `main_test.go` and accompanying files. It sets up a server and runs an otel-cli | ||
| build through a number of tests to verify that everything from environment | ||
| variable passing to server TLS negotiation work as expected. | ||
|
|
||
| ## Unit Testing | ||
|
|
||
| Do it. It doesn't have to be fancy, just exercise the code a little. It's more | ||
| about all of us being able to iterate quickly than reaching total coverage. | ||
|
|
||
| Most unit tests are in the `otelcli` package. The tests in the root of this | ||
| project are not unit tests. | ||
|
|
||
| ## The otel-cli Test Harness | ||
|
|
||
| When `go test` is run in the root of this project, it runs the available | ||
| `./otel-cli` binary through a suite of tests, providing otel-cli with its | ||
| endpoint information (via templates) and examining the payloads received on the | ||
| server. | ||
|
|
||
| The otel-cli test harness is more complex than otel-cli itself. Its goal is to | ||
| be able to test that setting e.g. `OTEL_EXPORTER_OTLP_CLIENT_KEY` works all the | ||
| way through to authenticating to a TLS server. The bugs are going to exist in | ||
| the glue code, since that's mostly what otel-cli is. Each of Cobra, | ||
| `encoding/json`, and opentelemetry-go are thorougly unit and battle tested. So, | ||
| otel-cli tests a build in a functional test harness. | ||
|
|
||
| Tests are defined in `data_for_test.go` in Go data structures. Suites are a a | ||
| group of Fixtures that go together. Mostly Suites are necessary for the | ||
| backgrounding feature, to test e.g. `otel-cli span background`, and to organize | ||
| tests by functionality, etc.. Fixtures configure everything for an otel-cli | ||
| invocation, and what to expect back from it. | ||
|
|
||
| The OTLP server functionality originally built for `otel-cli server tui` is | ||
| re-used in the tests to run a server in a goroutine. It supports both gRPC and | ||
| HTTP variants of OTLP, and can be configured with TLS. This allows otel-cli to | ||
| connect to a server and send traces, which the harness then compares to | ||
| expectations defined in the test Fixture. | ||
|
|
||
| otel-cli has a special subcommand, `otel-cli status` that sends a span and | ||
| reports back on otel-cli's internal state. The test harness detects status | ||
| commands and can check data in it. | ||
|
|
||
| `tls_for_test.go` implements an ephemeral certificate authority that is created | ||
| and destroyed on each run. The rest of the test harness injects the CA and certs | ||
| created into the tests, allowing for full-system testing. | ||
|
|
||
| A Fixture can be configured to run "in the background". In this case, the harness | ||
| will behave as if you ran the command `./otel-cli &` and let following fixtures | ||
| run on top of it. This is mostly used to test `otel-cli span background`, which | ||
| exists primarily to run as a backgrounded job in a shell script. When background | ||
| jobs are in use, be careful with test names as they are used as a key to manage | ||
| the process. | ||
|
|
||
| ## Adding Tests | ||
|
|
||
| For a new area of functionality, you'll want to add a Suite. A Suite is mostly | ||
| for organization of tests, but is also used to manage state when testing background | ||
| jobs. A Fixture is made of two parts: an otel-cli command configuration, and a | ||
| data structure of expected results. The harness presents otel-cli with the exact | ||
| ARGV specified in `Config.CliArgs`, and a clean environment with only the envvars | ||
| provided in the `Env` stringmap. The output from otel-cli is captured with stdout | ||
| and stderr combined. This can be tested against as well. | ||
|
|
||
| When otel-cli reads an environment variable it clears it, to prevent opentelemetry-go | ||
| from double-processing it. This is why envvars set in `Config.Env` don't show up | ||
| in `Results.Env`. | ||
|
|
||
| It is often wise to pass `"--fail", "--verbose"` to CliArgs for debugging and it's | ||
| fine to leave them on permanently. Without them otel-cli will be silent about | ||
| failures and you'll get a confusing test output. | ||
|
|
||
| Most of the time it's best to copy an existing Suite or Fixture and adjust it to | ||
| the case you're trying to test. Please try to clean out any unneeded config when | ||
| you do this so the tests are easy to understand. It's not bad to to test a little | ||
| extra surface area, just try to keep things readable. | ||
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.