...

Source file src/go.opentelemetry.io/otel/sdk/internal/internaltest/text_map_carrier_test.go

Documentation: go.opentelemetry.io/otel/sdk/internal/internaltest

     1  // Code created by gotmpl. DO NOT MODIFY.
     2  // source: internal/shared/internaltest/text_map_carrier_test.go.tmpl
     3  
     4  // Copyright The OpenTelemetry Authors
     5  //
     6  // Licensed under the Apache License, Version 2.0 (the "License");
     7  // you may not use this file except in compliance with the License.
     8  // You may obtain a copy of the License at
     9  //
    10  //     http://www.apache.org/licenses/LICENSE-2.0
    11  //
    12  // Unless required by applicable law or agreed to in writing, software
    13  // distributed under the License is distributed on an "AS IS" BASIS,
    14  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  // See the License for the specific language governing permissions and
    16  // limitations under the License.
    17  
    18  package internaltest
    19  
    20  import (
    21  	"reflect"
    22  	"testing"
    23  )
    24  
    25  var key, value = "test", "true"
    26  
    27  func TestTextMapCarrierKeys(t *testing.T) {
    28  	tmc := NewTextMapCarrier(map[string]string{key: value})
    29  	expected, actual := []string{key}, tmc.Keys()
    30  	if !reflect.DeepEqual(actual, expected) {
    31  		t.Errorf("expected tmc.Keys() to be %v but it was %v", expected, actual)
    32  	}
    33  }
    34  
    35  func TestTextMapCarrierGet(t *testing.T) {
    36  	tmc := NewTextMapCarrier(map[string]string{key: value})
    37  	tmc.GotN(t, 0)
    38  	if got := tmc.Get("empty"); got != "" {
    39  		t.Errorf("TextMapCarrier.Get returned %q for an empty key", got)
    40  	}
    41  	tmc.GotKey(t, "empty")
    42  	tmc.GotN(t, 1)
    43  	if got := tmc.Get(key); got != value {
    44  		t.Errorf("TextMapCarrier.Get(%q) returned %q, want %q", key, got, value)
    45  	}
    46  	tmc.GotKey(t, key)
    47  	tmc.GotN(t, 2)
    48  }
    49  
    50  func TestTextMapCarrierSet(t *testing.T) {
    51  	tmc := NewTextMapCarrier(nil)
    52  	tmc.SetN(t, 0)
    53  	tmc.Set(key, value)
    54  	if got, ok := tmc.data[key]; !ok {
    55  		t.Errorf("TextMapCarrier.Set(%q,%q) failed to store pair", key, value)
    56  	} else if got != value {
    57  		t.Errorf("TextMapCarrier.Set(%q,%q) stored (%q,%q), not (%q,%q)", key, value, key, got, key, value)
    58  	}
    59  	tmc.SetKeyValue(t, key, value)
    60  	tmc.SetN(t, 1)
    61  }
    62  
    63  func TestTextMapCarrierReset(t *testing.T) {
    64  	tmc := NewTextMapCarrier(map[string]string{key: value})
    65  	tmc.GotN(t, 0)
    66  	tmc.SetN(t, 0)
    67  	tmc.Reset(nil)
    68  	tmc.GotN(t, 0)
    69  	tmc.SetN(t, 0)
    70  	if got := tmc.Get(key); got != "" {
    71  		t.Error("TextMapCarrier.Reset() failed to clear initial data")
    72  	}
    73  	tmc.GotN(t, 1)
    74  	tmc.GotKey(t, key)
    75  	tmc.Set(key, value)
    76  	tmc.SetKeyValue(t, key, value)
    77  	tmc.SetN(t, 1)
    78  	tmc.Reset(nil)
    79  	tmc.GotN(t, 0)
    80  	tmc.SetN(t, 0)
    81  	if got := tmc.Get(key); got != "" {
    82  		t.Error("TextMapCarrier.Reset() failed to clear data")
    83  	}
    84  }
    85  

View as plain text