File: os_test.go

package info (click to toggle)
golang-opentelemetry-otel 1.31.0-5
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 11,844 kB
  • sloc: makefile: 237; sh: 51
file content (55 lines) | stat: -rw-r--r-- 1,461 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package resource_test

import (
	"testing"

	"github.com/stretchr/testify/require"

	"go.opentelemetry.io/otel/attribute"
	"go.opentelemetry.io/otel/sdk/resource"
	semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
)

func mockRuntimeProviders() {
	resource.SetRuntimeProviders(
		fakeRuntimeNameProvider,
		fakeRuntimeVersionProvider,
		func() string { return "LINUX" },
		fakeRuntimeArchProvider,
	)

	resource.SetOSDescriptionProvider(
		func() (string, error) { return "Test", nil },
	)
}

func TestMapRuntimeOSToSemconvOSType(t *testing.T) {
	tt := []struct {
		Name   string
		Goos   string
		OSType attribute.KeyValue
	}{
		{"Apple Darwin", "darwin", semconv.OSTypeDarwin},
		{"DragonFly BSD", "dragonfly", semconv.OSTypeDragonflyBSD},
		{"FreeBSD", "freebsd", semconv.OSTypeFreeBSD},
		{"Linux", "linux", semconv.OSTypeLinux},
		{"NetBSD", "netbsd", semconv.OSTypeNetBSD},
		{"OpenBSD", "openbsd", semconv.OSTypeOpenBSD},
		{"Oracle Solaris", "solaris", semconv.OSTypeSolaris},
		{"Microsoft Windows", "windows", semconv.OSTypeWindows},
		{"Unknown", "unknown", semconv.OSTypeKey.String("unknown")},
		{"UNKNOWN", "UNKNOWN", semconv.OSTypeKey.String("unknown")},
	}

	for _, tc := range tt {
		tc := tc

		t.Run(tc.Name, func(t *testing.T) {
			osTypeAttribute := resource.MapRuntimeOSToSemconvOSType(tc.Goos)
			require.EqualValues(t, osTypeAttribute, tc.OSType)
		})
	}
}