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

Merge tags against existing tags in WithTags client option #278

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion statsd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func WithNamespace(namespace string) Option {
// WithTags sets global tags to be applied to every metrics, events and service checks.
func WithTags(tags []string) Option {
return func(o *Options) error {
o.tags = tags
o.tags = append(o.tags, tags...)
return nil
}
}
Expand Down
14 changes: 14 additions & 0 deletions statsd/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func TestResetOptions(t *testing.T) {
assert.Equal(t, options.aggregation, false)
assert.Equal(t, options.extendedAggregation, false)
}

func TestOptionsNamespaceWithoutDot(t *testing.T) {
testNamespace := "datadog"

Expand All @@ -113,3 +114,16 @@ func TestOptionsNamespaceWithoutDot(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, options.namespace, testNamespace+".")
}

func TestOptionsTagsMerge(t *testing.T) {
testTagsInitial := []string{"datadog"}
testTagsMerge := []string{"rocks"}

options, err := resolveOptions([]Option{
WithTags(testTagsInitial),
WithTags(testTagsMerge),
})

assert.NoError(t, err)
assert.Equal(t, append(testTagsInitial, testTagsMerge...), options.tags)
}