...

Source file src/go.opentelemetry.io/otel/sdk/resource/os_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  	"testing"
    19  
    20  	"github.com/stretchr/testify/require"
    21  
    22  	"go.opentelemetry.io/otel/attribute"
    23  	"go.opentelemetry.io/otel/sdk/resource"
    24  	semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
    25  )
    26  
    27  func mockRuntimeProviders() {
    28  	resource.SetRuntimeProviders(
    29  		fakeRuntimeNameProvider,
    30  		fakeRuntimeVersionProvider,
    31  		func() string { return "LINUX" },
    32  		fakeRuntimeArchProvider,
    33  	)
    34  
    35  	resource.SetOSDescriptionProvider(
    36  		func() (string, error) { return "Test", nil },
    37  	)
    38  }
    39  
    40  func TestMapRuntimeOSToSemconvOSType(t *testing.T) {
    41  	tt := []struct {
    42  		Name   string
    43  		Goos   string
    44  		OSType attribute.KeyValue
    45  	}{
    46  		{"Apple Darwin", "darwin", semconv.OSTypeDarwin},
    47  		{"DragonFly BSD", "dragonfly", semconv.OSTypeDragonflyBSD},
    48  		{"FreeBSD", "freebsd", semconv.OSTypeFreeBSD},
    49  		{"Linux", "linux", semconv.OSTypeLinux},
    50  		{"NetBSD", "netbsd", semconv.OSTypeNetBSD},
    51  		{"OpenBSD", "openbsd", semconv.OSTypeOpenBSD},
    52  		{"Oracle Solaris", "solaris", semconv.OSTypeSolaris},
    53  		{"Microsoft Windows", "windows", semconv.OSTypeWindows},
    54  		{"Unknown", "unknown", semconv.OSTypeKey.String("unknown")},
    55  		{"UNKNOWN", "UNKNOWN", semconv.OSTypeKey.String("unknown")},
    56  	}
    57  
    58  	for _, tc := range tt {
    59  		tc := tc
    60  
    61  		t.Run(tc.Name, func(t *testing.T) {
    62  			osTypeAttribute := resource.MapRuntimeOSToSemconvOSType(tc.Goos)
    63  			require.EqualValues(t, osTypeAttribute, tc.OSType)
    64  		})
    65  	}
    66  }
    67  

View as plain text