| 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/assert" |
| 10 |
"github.com/stretchr/testify/require" |
| 11 |
"golang.org/x/sys/windows/registry" |
| 12 |
|
| 13 |
"go.opentelemetry.io/otel/sdk/resource" |
| 14 |
) |
| 15 |
|
| 16 |
func TestPlatformOSDescription(t *testing.T) { |
| 17 |
osDescription, err := resource.PlatformOSDescription() |
| 18 |
|
| 19 |
require.NoError(t, err) |
| 20 |
require.Regexp(t, `^(\w+\s)+\(\d+\)\s\[Version\s\d+(\.\d+){3}\]$`, osDescription) |
| 21 |
} |
| 22 |
|
| 23 |
func TestReadRegistryValues(t *testing.T) { |
| 24 |
k, err := registry.OpenKey( |
| 25 |
registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE) |
| 26 |
|
| 27 |
require.NoError(t, err, "should open Windows CurrentVersion registry key") |
| 28 |
|
| 29 |
defer k.Close() |
| 30 |
|
| 31 |
assert.NotEmpty(t, resource.ReadProductName(k), "should read ProductName") |
| 32 |
assert.NotEmpty(t, resource.ReadReleaseID(k), "should read ReleaseID") |
| 33 |
assert.NotEmpty(t, resource.ReadCurrentMajorVersionNumber(k), "should read CurrentMajorVersionNumber") |
| 34 |
assert.NotEmpty(t, resource.ReadCurrentMinorVersionNumber(k), "should read CurrentMinorVersionNumber") |
| 35 |
assert.NotEmpty(t, resource.ReadCurrentBuildNumber(k), "should read CurrentBuildNumber") |
| 36 |
assert.NotEmpty(t, resource.ReadUBR(k), "should read UBR") |
| 37 |
assert.NotPanics(t, func() { resource.ReadDisplayVersion(k) }, "should not panic when reading DisplayVersion") |
| 38 |
} |