Merge `OTEL_RESOURCE_ATTRIBUTES` when there is one already in the environment. This allows user-specified resource attributes to be passed on to CLI plugins while still allowing the extra attributes added for telemetry information. This was the original intended use-case but it seems to have never made it in. The reason `OTEL_RESOURCE_ATTRIBUTES` was used is because we could combine it with user-centric ones. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
27 lines
814 B
Go
27 lines
814 B
Go
package manager
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/spf13/cobra"
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func TestPluginResourceAttributesEnvvar(t *testing.T) {
|
|
cmd := &cobra.Command{
|
|
Annotations: map[string]string{
|
|
cobra.CommandDisplayNameAnnotation: "docker",
|
|
},
|
|
}
|
|
|
|
// Ensure basic usage is fine.
|
|
env := appendPluginResourceAttributesEnvvar(nil, cmd, Plugin{Name: "compose"})
|
|
assert.DeepEqual(t, []string{"OTEL_RESOURCE_ATTRIBUTES=docker.cli.cobra.command_path=docker%20compose"}, env)
|
|
|
|
// Add a user-based environment variable to OTEL_RESOURCE_ATTRIBUTES.
|
|
t.Setenv("OTEL_RESOURCE_ATTRIBUTES", "a.b.c=foo")
|
|
|
|
env = appendPluginResourceAttributesEnvvar(nil, cmd, Plugin{Name: "compose"})
|
|
assert.DeepEqual(t, []string{"OTEL_RESOURCE_ATTRIBUTES=a.b.c=foo,docker.cli.cobra.command_path=docker%20compose"}, env)
|
|
}
|