Skip to content

Commit

Permalink
use FilterCallsByName to simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahkm committed Dec 17, 2024
1 parent 530a452 commit 565a5b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 3 additions & 5 deletions ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,9 @@ func TestTracerStart(t *testing.T) {
assert.Equal(int64(1), counts["datadog.tracer.instrumentations"])

calls := tg.IncrCalls()
for _, c := range calls {
if c.GetName() == "datadog.tracer.instrumentations" {
assert.EqualValues(c.GetTags(), []string{"instrumentation:chi", "instrumentation_version:unknown"})
return
}
for _, c := range statsdtest.FilterCallsByName(calls, "datadog.tracer.instrumentations") {
assert.EqualValues(c.GetTags(), []string{"instrumentation:chi", "instrumentation_version:unknown"})
return
}
assert.Fail("expected instrumentation to have appropriate tags")

Expand Down
14 changes: 10 additions & 4 deletions internal/statsdtest/statsdtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ func (tc *TestStatsdCall) GetTags() []string {
return tc.tags
}

func (tc *TestStatsdCall) GetName() string {
return tc.name
}

func (tg *TestStatsdClient) Gauge(name string, value float64, tags []string, rate float64) error {
return tg.addMetric(callTypeGauge, tags, TestStatsdCall{
name: name,
Expand Down Expand Up @@ -222,6 +218,16 @@ func (tg *TestStatsdClient) CallsByName() map[string]int {
return counts
}

func FilterCallsByName(calls []TestStatsdCall, name string) []TestStatsdCall {
var matches []TestStatsdCall
for _, c := range calls {
if c.name == name {
matches = append(matches, c)
}
}
return matches
}

func (tg *TestStatsdClient) Counts() map[string]int64 {
tg.mu.RLock()
defer tg.mu.RUnlock()
Expand Down

0 comments on commit 565a5b8

Please sign in to comment.