...

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

View as plain text