You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-23 22:34:47 +02:00
This PR contains the following updates: | Package | Type | Update | Change | Age | Confidence | |---|---|---|---|---|---| | golang.org/x/exp | require | digest | `27f1f14` -> `90e834f` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | | golang.org/x/exp/typeparams | indirect | digest | `27f1f14` -> `90e834f` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | | golang.org/x/net | indirect | minor | `v0.45.0` -> `v0.46.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | | golang.org/x/telemetry | indirect | digest | `ca0c2a9` -> `24f779f` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | | golang.org/x/tools | require | minor | `v0.37.0` -> `v0.38.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://redirect.github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/open-telemetry/opentelemetry-go). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMzEuOSIsInVwZGF0ZWRJblZlciI6IjQxLjE0My4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJTa2lwIENoYW5nZWxvZyIsImRlcGVuZGVuY2llcyJdfQ==--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Tyler Yahn <codingalias@gmail.com>
112 lines
2.7 KiB
Go
112 lines
2.7 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos
|
|
|
|
package resource_test
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"golang.org/x/sys/unix"
|
|
|
|
"go.opentelemetry.io/otel/sdk/resource"
|
|
)
|
|
|
|
func fakeUnameProvider(buf *unix.Utsname) error {
|
|
copy(buf.Sysname[:], "Mock OS")
|
|
copy(buf.Nodename[:], "DESKTOP-PC")
|
|
copy(buf.Release[:], "5.0.0")
|
|
copy(buf.Version[:], "#1 SMP Thu May 6 12:34:56 UTC 2021")
|
|
copy(buf.Machine[:], "x86_64")
|
|
|
|
return nil
|
|
}
|
|
|
|
func fakeUnameProviderWithError(*unix.Utsname) error {
|
|
return fmt.Errorf("error invoking uname(2)")
|
|
}
|
|
|
|
func TestUname(t *testing.T) {
|
|
resource.SetUnameProvider(fakeUnameProvider)
|
|
|
|
uname, err := resource.Uname()
|
|
|
|
require.Equal(t, "Mock OS DESKTOP-PC 5.0.0 #1 SMP Thu May 6 12:34:56 UTC 2021 x86_64", uname)
|
|
require.NoError(t, err)
|
|
|
|
resource.SetDefaultUnameProvider()
|
|
}
|
|
|
|
func TestUnameError(t *testing.T) {
|
|
resource.SetUnameProvider(fakeUnameProviderWithError)
|
|
|
|
uname, err := resource.Uname()
|
|
|
|
require.Empty(t, uname)
|
|
require.Error(t, err)
|
|
|
|
resource.SetDefaultUnameProvider()
|
|
}
|
|
|
|
func TestGetFirstAvailableFile(t *testing.T) {
|
|
tempDir := t.TempDir()
|
|
|
|
file1, _ := os.CreateTemp(tempDir, "candidate_")
|
|
file2, _ := os.CreateTemp(tempDir, "candidate_")
|
|
|
|
filename1, filename2 := file1.Name(), file2.Name()
|
|
|
|
tt := []struct {
|
|
Name string
|
|
Candidates []string
|
|
ExpectedFileName string
|
|
ExpectedErr string
|
|
}{
|
|
{"Gets first, skip second candidate", []string{filename1, filename2}, filename1, ""},
|
|
{"Skips first, gets second candidate", []string{"does_not_exists", filename2}, filename2, ""},
|
|
{
|
|
"Skips first, gets second, ignores third candidate",
|
|
[]string{"does_not_exists", filename2, filename1},
|
|
filename2,
|
|
"",
|
|
},
|
|
{"No candidates (empty slice)", []string{}, "", "no candidate file available: []"},
|
|
{"No candidates (nil slice)", nil, "", "no candidate file available: []"},
|
|
{
|
|
"Single nonexisting candidate",
|
|
[]string{"does_not_exists"},
|
|
"",
|
|
"no candidate file available: [does_not_exists]",
|
|
},
|
|
{
|
|
"Multiple nonexisting candidates",
|
|
[]string{"does_not_exists", "this_either"},
|
|
"",
|
|
"no candidate file available: [does_not_exists this_either]",
|
|
},
|
|
}
|
|
|
|
for _, tc := range tt {
|
|
t.Run(tc.Name, func(t *testing.T) {
|
|
file, err := resource.GetFirstAvailableFile(tc.Candidates)
|
|
|
|
filename := ""
|
|
if file != nil {
|
|
filename = file.Name()
|
|
}
|
|
|
|
errString := ""
|
|
if err != nil {
|
|
errString = err.Error()
|
|
}
|
|
|
|
require.Equal(t, tc.ExpectedFileName, filename)
|
|
require.Equal(t, tc.ExpectedErr, errString)
|
|
})
|
|
}
|
|
}
|