| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package resource_test |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/require" |
| 10 |
|
| 11 |
"go.opentelemetry.io/otel/attribute" |
| 12 |
"go.opentelemetry.io/otel/sdk/resource" |
| 13 |
semconv "go.opentelemetry.io/otel/semconv/v1.40.0" |
| 14 |
) |
| 15 |
|
| 16 |
func mockRuntimeProviders() { |
| 17 |
resource.SetRuntimeProviders( |
| 18 |
fakeRuntimeNameProvider, |
| 19 |
fakeRuntimeVersionProvider, |
| 20 |
func() string { return "LINUX" }, |
| 21 |
fakeRuntimeArchProvider, |
| 22 |
) |
| 23 |
|
| 24 |
resource.SetOSDescriptionProvider( |
| 25 |
func() (string, error) { return "Test", nil }, |
| 26 |
) |
| 27 |
} |
| 28 |
|
| 29 |
func TestMapRuntimeOSToSemconvOSType(t *testing.T) { |
| 30 |
tt := []struct { |
| 31 |
Name string |
| 32 |
Goos string |
| 33 |
OSType attribute.KeyValue |
| 34 |
}{ |
| 35 |
{"Apple Darwin", "darwin", semconv.OSTypeDarwin}, |
| 36 |
{"DragonFly BSD", "dragonfly", semconv.OSTypeDragonflyBSD}, |
| 37 |
{"FreeBSD", "freebsd", semconv.OSTypeFreeBSD}, |
| 38 |
{"Linux", "linux", semconv.OSTypeLinux}, |
| 39 |
{"NetBSD", "netbsd", semconv.OSTypeNetBSD}, |
| 40 |
{"OpenBSD", "openbsd", semconv.OSTypeOpenBSD}, |
| 41 |
{"Oracle Solaris", "solaris", semconv.OSTypeSolaris}, |
| 42 |
{"Microsoft Windows", "windows", semconv.OSTypeWindows}, |
| 43 |
{"Unknown", "unknown", semconv.OSTypeKey.String("unknown")}, |
| 44 |
{"UNKNOWN", "UNKNOWN", semconv.OSTypeKey.String("unknown")}, |
| 45 |
} |
| 46 |
|
| 47 |
for _, tc := range tt { |
| 48 |
t.Run(tc.Name, func(t *testing.T) { |
| 49 |
osTypeAttribute := resource.MapRuntimeOSToSemconvOSType(tc.Goos) |
| 50 |
require.Equal(t, osTypeAttribute, tc.OSType) |
| 51 |
}) |
| 52 |
} |
| 53 |
} |