|
8 | 8 |
|
9 | 9 | "github.com/stretchr/testify/assert" |
10 | 10 | "github.com/stretchr/testify/require" |
| 11 | + "go.opentelemetry.io/otel/attribute" |
11 | 12 |
|
12 | 13 | "go.opentelemetry.io/collector/component" |
13 | 14 | "go.opentelemetry.io/collector/service/telemetry" |
@@ -48,3 +49,36 @@ func TestCreateResource(t *testing.T) { |
48 | 49 | }, raw) |
49 | 50 | }) |
50 | 51 | } |
| 52 | + |
| 53 | +func TestAttributeValueString(t *testing.T) { |
| 54 | + t.Run("string attribute", func(t *testing.T) { |
| 55 | + val := attribute.StringValue("test-value") |
| 56 | + result, err := attributeValueString("test.attr", val) |
| 57 | + require.NoError(t, err) |
| 58 | + assert.Equal(t, "test-value", result) |
| 59 | + }) |
| 60 | + |
| 61 | + t.Run("int64 attribute returns error", func(t *testing.T) { |
| 62 | + val := attribute.Int64Value(42) |
| 63 | + result, err := attributeValueString("test.attr", val) |
| 64 | + require.Error(t, err) |
| 65 | + assert.Empty(t, result) |
| 66 | + assert.Contains(t, err.Error(), `attribute "test.attr": expected string, got INT64`) |
| 67 | + }) |
| 68 | + |
| 69 | + t.Run("bool attribute returns error", func(t *testing.T) { |
| 70 | + val := attribute.BoolValue(true) |
| 71 | + result, err := attributeValueString("test.attr", val) |
| 72 | + require.Error(t, err) |
| 73 | + assert.Empty(t, result) |
| 74 | + assert.Contains(t, err.Error(), `attribute "test.attr": expected string, got BOOL`) |
| 75 | + }) |
| 76 | + |
| 77 | + t.Run("float64 attribute returns error", func(t *testing.T) { |
| 78 | + val := attribute.Float64Value(3.14) |
| 79 | + result, err := attributeValueString("test.attr", val) |
| 80 | + require.Error(t, err) |
| 81 | + assert.Empty(t, result) |
| 82 | + assert.Contains(t, err.Error(), `attribute "test.attr": expected string, got FLOAT64`) |
| 83 | + }) |
| 84 | +} |
0 commit comments