Skip to content

Commit

Permalink
Add a second, more complex span exec test (#88)
Browse files Browse the repository at this point in the history
* Add a test that calls otel-cli exec otel-cli
Note spans, need to track down that bug.

* rename to 91 to conform

* check recorded vs expected span count
fix tests to pass now that check is implemented

* clean up test logging

* çlarify function name, we'll do a more in depth refactor later

* better test descriptions
  • Loading branch information
edw-eqix authored Sep 24, 2021
1 parent bbe3e8a commit 3c5849c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
4 changes: 2 additions & 2 deletions fixtures/90-span-exec-basic.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"description": "otel-cli exec basic test and stuff",
"description": "otel-cli exec runs echo",
"config": {
"env": {
"OTEL_EXPORTER_OTLP_ENDPOINT": "{{endpoint}}",
Expand All @@ -19,7 +19,7 @@
},
"expect": {
"output": "hello world\n",
"spans": 2,
"spans": 1,
"span_data": {
"trace_id": "edededededededededededededed9000",
"span_id": "*",
Expand Down
32 changes: 32 additions & 0 deletions fixtures/91-span-exec-nested.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"description": "otel-cli exec runs otel-cli exec",
"config": {
"env": {
"OTEL_EXPORTER_OTLP_ENDPOINT": "{{endpoint}}"
},
"cli_args": [
"exec",
"--service",
"main_test.go",
"--name",
"test-span-123",
"--kind",
"server",
"./otel-cli",
"exec",
"--tp-ignore-env",
"echo hello world $TRACEPARENT"
]
},
"expect": {
"output": "hello world\n",
"spans": 2,
"span_data": {
"trace_id": "*",
"span_id": "*",
"is_sampled": "true"
}
}
}
]
16 changes: 15 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ func checkAll(t *testing.T, fixture Fixture, endpoint string, results Results, s
// check timeout and process status expectations
checkProcess(t, fixture, results)

// compares the spans from the server against expectations in the fixture
// compare the number of recorded spans against expectations in the fixture
checkSpanCount(t, fixture, results)

// compares the data in each recorded span against expectations in the fixture
checkSpanData(t, fixture, endpoint, span, events)

// many of the basic plumbing tests use status so it has its own set of checks
Expand All @@ -205,6 +208,15 @@ func checkAll(t *testing.T, fixture Fixture, endpoint string, results Results, s
}
}

// compare the number of spans recorded by the test server against the
// number of expected spans in the fixture, if specified. If no expected
// span count is specified, this check always passes.
func checkSpanCount(t *testing.T, fixture Fixture, results Results) {
if results.Spans != fixture.Expect.Spans {
t.Errorf("[%s] span count was %d but expected %d", fixture.Filename, results.Spans, fixture.Expect.Spans)
}
}

// checkProcess validates configured expectations about whether otel-cli failed
// or the test timed out. These are mostly used for testing that otel-cli fails
// in the way we want it to.
Expand Down Expand Up @@ -454,6 +466,8 @@ gather:
// in a timeout with the above time.After
gatheredSpans++
if gatheredSpans == results.Spans {
// TODO: it would be slightly nicer to use plural.Selectf instead of 'span(s)'
t.Logf("[%s] test gathered %d span(s)", fixture.Filename, gatheredSpans)
break gather
}
}
Expand Down

0 comments on commit 3c5849c

Please sign in to comment.