Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for different merges #873

Open
wants to merge 1 commit into
base: resource-conv
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions sdk/resource/auto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
)
Expand Down Expand Up @@ -76,3 +77,98 @@ func TestDetect(t *testing.T) {
})
}
}

func TestMerge2(t *testing.T) {
cases := []struct {
name string
res1, res2 *resource.Resource
want *resource.Resource
}{
{
name: "No upgrade",
res1: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.18.0",
attribute.String("res1", "1.18.0"),
attribute.String("browser.user_agent", "go_test"), //This should not be upgraded to 1.19.0's "user_agent.original"
),
res2: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.15.0",
attribute.String("res2", "1.15.0"),
),
want: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.18.0",
attribute.String("res1", "1.18.0"),
attribute.String("browser.user_agent", "go_test"),
attribute.String("res2", "1.15.0"),
),
},
{
name: "With upgrade",
res1: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.18.0",
attribute.String("res1", "1.18.0"),
attribute.String("browser.user_agent", "go_test"),
),
res2: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.19.0",
attribute.String("res2", "1.19.0"),
),
want: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.19.0",
attribute.String("res1", "1.18.0"),
attribute.String("user_agent.original", "go_test"),
attribute.String("res2", "1.19.0"),
),
},
{
name: "Transient upgrade",
res1: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.18.0",
attribute.String("res1", "1.18.0"),
attribute.String("browser.user_agent", "go_test"),
),
res2: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.20.0",
attribute.String("res2", "1.20.0"),
),
want: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.20.0",
attribute.String("res1", "1.18.0"),
attribute.String("user_agent.original", "go_test"),
attribute.String("res2", "1.20.0"),
),
},
{
name: "Doesn't upgrade outside of resources",
res1: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.18.0",
attribute.String("res1", "1.18.0"),
attribute.String("faas.execution", "af47"), // This is a span attribute it shouldn't be modified by Merge
),
res2: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.20.0",
attribute.String("res2", "1.20.0"),
),
want: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.20.0",
attribute.String("res1", "1.18.0"),
attribute.String("faas.execution", "af47"),
attribute.String("res2", "1.20.0"),
),
},
{
name: "Doesn't upgrade previous version transitions",
res1: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.20.0",
attribute.String("res1", "1.20.0"),
attribute.String("browser.user_agent", "go_test"),
),
res2: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.21.0",
attribute.String("res2", "1.21.0"),
),
want: resource.NewWithAttributes("https://opentelemetry.io/schemas/1.21.0",
attribute.String("res1", "1.20.0"),
attribute.String("browser.user_agent", "go_test"),
attribute.String("res2", "1.21.0"),
),
},
}
for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
got, err := resource.Merge(tt.res1, tt.res2)
require.NoError(t, err)
assert.Equal(t, tt.want, got)

got, err = resource.Merge(tt.res2, tt.res1)
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
}
Loading