1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-12 02:28:07 +02:00

Add tests using new test framework

This commit is contained in:
Tyler Yahn 2020-10-15 09:17:04 -07:00
parent 3168c05901
commit af7ae17436
No known key found for this signature in database
GPG Key ID: 42AA23B0BC85B798

View File

@ -0,0 +1,53 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package internal_test
import (
"context"
"testing"
"go.opentelemetry.io/otel/api/global/internal"
"go.opentelemetry.io/otel/oteltest"
)
func TestTextMapPropagatorDelegation(t *testing.T) {
internal.ResetForTest()
ctx := context.Background()
carrier := oteltest.NewTextMapCarrier(nil)
// The default should be a noop.
prior := internal.TextMapPropagator()
prior.Inject(ctx, carrier)
ctx = prior.Extract(ctx, carrier)
if !carrier.GotN(t, 0) || !carrier.SetN(t, 0) {
return
}
// Make sure the delegate woks as expected.
delegate := oteltest.NewTextMapPropagator("test")
delegate.Inject(ctx, carrier)
ctx = delegate.Extract(ctx, carrier)
if !delegate.InjectedN(t, carrier, 1) || !delegate.ExtractedN(t, ctx, 1) {
return
}
// The prior propagator should use the delegate after it is set as the
// global.
internal.SetTextMapPropagator(delegate)
prior.Inject(ctx, carrier)
ctx = prior.Extract(ctx, carrier)
delegate.InjectedN(t, carrier, 2)
delegate.ExtractedN(t, ctx, 2)
}