...
1
2
3
4
5
6
7
8
9
10
11
12
13
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