mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-03 22:52:30 +02:00
Fix empty host.id (#4317)
This commit is contained in:
parent
f6a658c6c2
commit
9b0c4d2caf
@ -36,6 +36,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
|
||||
- Correctly format log messages from the `go.opentelemetry.io/otel/exporters/zipkin` exporter. (#4143)
|
||||
- Log an error for calls to `NewView` in `go.opentelemetry.io/otel/sdk/metric` that have empty criteria. (#4307)
|
||||
- Fix `resource.WithHostID()` to not set an empty `host.id`. (#4317)
|
||||
|
||||
## [1.16.0/0.39.0] 2023-05-18
|
||||
|
||||
|
@ -21,7 +21,7 @@ import "os"
|
||||
func readFile(filename string) (string, error) {
|
||||
b, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return "", nil
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(b), nil
|
||||
|
53
sdk/resource/host_id_readfile_test.go
Normal file
53
sdk/resource/host_id_readfile_test.go
Normal file
@ -0,0 +1,53 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build linux || dragonfly || freebsd || netbsd || openbsd || solaris
|
||||
|
||||
package resource
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestReadFileExistent(t *testing.T) {
|
||||
fileContents := "foo"
|
||||
|
||||
f, err := os.CreateTemp("", "readfile_")
|
||||
require.NoError(t, err)
|
||||
|
||||
defer os.Remove(f.Name())
|
||||
|
||||
_, err = f.WriteString(fileContents)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.Close())
|
||||
|
||||
result, err := readFile(f.Name())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, result, fileContents)
|
||||
}
|
||||
|
||||
func TestReadFileNonExistent(t *testing.T) {
|
||||
// create unique filename
|
||||
f, err := os.CreateTemp("", "readfile_")
|
||||
require.NoError(t, err)
|
||||
|
||||
// make file non-existent
|
||||
require.NoError(t, os.Remove(f.Name()))
|
||||
|
||||
_, err = readFile(f.Name())
|
||||
require.ErrorIs(t, err, os.ErrNotExist)
|
||||
}
|
Loading…
Reference in New Issue
Block a user