Skip to content

Commit

Permalink
Fix existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Sep 12, 2023
1 parent a169b2b commit 519b76d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
34 changes: 25 additions & 9 deletions sdk/resource/auto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
Expand All @@ -30,19 +31,37 @@ func TestDetect(t *testing.T) {
cases := []struct {
name string
schema1, schema2 string
isErr bool
want string
}{
{
name: "different schema urls",
schema1: "https://opentelemetry.io/schemas/1.3.0",
schema2: "https://opentelemetry.io/schemas/1.4.0",
isErr: true,
want: "https://opentelemetry.io/schemas/1.4.0",
},
{
name: "same schema url",
schema1: "https://opentelemetry.io/schemas/1.4.0",
schema2: "https://opentelemetry.io/schemas/1.4.0",
isErr: false,
want: "https://opentelemetry.io/schemas/1.4.0",
},
{
name: "missing first schema url",
schema1: "",
schema2: "https://opentelemetry.io/schemas/1.4.0",
want: "https://opentelemetry.io/schemas/1.4.0",
},
{
name: "missing second schema url",
schema1: "https://opentelemetry.io/schemas/1.4.0",
schema2: "",
want: "https://opentelemetry.io/schemas/1.4.0",
},
{
name: "missing both schema url",
schema1: "",
schema2: "",
want: "",
},
}

Expand All @@ -51,12 +70,9 @@ func TestDetect(t *testing.T) {
d1 := resource.StringDetector(c.schema1, semconv.HostNameKey, os.Hostname)
d2 := resource.StringDetector(c.schema2, semconv.HostNameKey, os.Hostname)
r, err := resource.Detect(context.Background(), d1, d2)
assert.NotNil(t, r)
if c.isErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
require.NoError(t, err)
require.NotNil(t, r)
assert.Equal(t, c.want, r.SchemaURL())
})
}
}
4 changes: 2 additions & 2 deletions sdk/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ func Merge(a, b *Resource) (*Resource, error) {
if a.schemaURL != schemaURL {
a, err = upgradeResource(schemaURL, a)
if err != nil {
return nil, err
return Empty(), err
}
} else {
b, err = upgradeResource(schemaURL, b)
if err != nil {
return nil, err
return Empty(), err
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions sdk/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ func TestMerge(t *testing.T) {
schemaURL: "https://opentelemetry.io/schemas/1.4.0",
},
{
name: "Merge with different schemas",
a: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.4.0", kv41),
b: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.3.0", kv42),
want: nil,
isErr: true,
name: "Merge with different schemas",
a: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.4.0", kv41),
b: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.3.0", kv42),
want: []attribute.KeyValue{kv42},
schemaURL: "https://opentelemetry.io/schemas/1.4.0",
},
}
for _, c := range cases {
Expand Down

0 comments on commit 519b76d

Please sign in to comment.