...

Source file src/go.opentelemetry.io/otel/sdk/resource/auto_test.go

Documentation: go.opentelemetry.io/otel/sdk/resource

     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 resource_test
    16  
    17  import (
    18  	"context"
    19  	"fmt"
    20  	"os"
    21  	"testing"
    22  
    23  	"github.com/stretchr/testify/assert"
    24  
    25  	"go.opentelemetry.io/otel/sdk/resource"
    26  	semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
    27  )
    28  
    29  func TestDetect(t *testing.T) {
    30  	cases := []struct {
    31  		name             string
    32  		schema1, schema2 string
    33  		isErr            bool
    34  	}{
    35  		{
    36  			name:    "different schema urls",
    37  			schema1: "https://opentelemetry.io/schemas/1.3.0",
    38  			schema2: "https://opentelemetry.io/schemas/1.4.0",
    39  			isErr:   true,
    40  		},
    41  		{
    42  			name:    "same schema url",
    43  			schema1: "https://opentelemetry.io/schemas/1.4.0",
    44  			schema2: "https://opentelemetry.io/schemas/1.4.0",
    45  			isErr:   false,
    46  		},
    47  	}
    48  
    49  	for _, c := range cases {
    50  		t.Run(fmt.Sprintf("case-%s", c.name), func(t *testing.T) {
    51  			d1 := resource.StringDetector(c.schema1, semconv.HostNameKey, os.Hostname)
    52  			d2 := resource.StringDetector(c.schema2, semconv.HostNameKey, os.Hostname)
    53  			r, err := resource.Detect(context.Background(), d1, d2)
    54  			assert.NotNil(t, r)
    55  			if c.isErr {
    56  				assert.Error(t, err)
    57  			} else {
    58  				assert.NoError(t, err)
    59  			}
    60  		})
    61  	}
    62  }
    63  

View as plain text