...

Source file src/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/resource_test.go

Documentation: go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform

     1  // Copyright The OpenTelemetry Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package tracetransform
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/assert"
    21  
    22  	"go.opentelemetry.io/otel/attribute"
    23  	"go.opentelemetry.io/otel/sdk/resource"
    24  )
    25  
    26  func TestNilResource(t *testing.T) {
    27  	assert.Empty(t, Resource(nil))
    28  }
    29  
    30  func TestEmptyResource(t *testing.T) {
    31  	assert.Empty(t, Resource(&resource.Resource{}))
    32  }
    33  
    34  /*
    35  * This does not include any testing on the ordering of Resource Attributes.
    36  * They are stored as a map internally to the Resource and their order is not
    37  * guaranteed.
    38   */
    39  
    40  func TestResourceAttributes(t *testing.T) {
    41  	attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)}
    42  
    43  	got := Resource(resource.NewSchemaless(attrs...)).GetAttributes()
    44  	if !assert.Len(t, attrs, 2) {
    45  		return
    46  	}
    47  	assert.ElementsMatch(t, KeyValues(attrs), got)
    48  }
    49  

View as plain text