Skip to content

Commit

Permalink
Fix unit tests for new metric implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc committed Dec 1, 2016
1 parent db7a4b2 commit e5c7a71
Show file tree
Hide file tree
Showing 29 changed files with 226 additions and 180 deletions.
26 changes: 13 additions & 13 deletions agent/accumulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestAdd(t *testing.T) {
testm = <-metrics
actual = testm.String()
assert.Equal(t,
fmt.Sprintf("acctest,acc=test value=101 %d", now.UnixNano()),
fmt.Sprintf("acctest,acc=test value=101 %d\n", now.UnixNano()),
actual)
}

Expand Down Expand Up @@ -70,7 +70,7 @@ func TestAddFields(t *testing.T) {
testm = <-metrics
actual = testm.String()
assert.Equal(t,
fmt.Sprintf("acctest,acc=test usage=99 %d", now.UnixNano()),
fmt.Sprintf("acctest,acc=test usage=99 %d\n", now.UnixNano()),
actual)
}

Expand Down Expand Up @@ -126,7 +126,7 @@ func TestAddNoIntervalWithPrecision(t *testing.T) {
testm = <-a.metrics
actual = testm.String()
assert.Equal(t,
fmt.Sprintf("acctest,acc=test value=101 %d", int64(1139572800000000000)),
fmt.Sprintf("acctest,acc=test value=101 %d\n", int64(1139572800000000000)),
actual)
}

Expand Down Expand Up @@ -158,7 +158,7 @@ func TestAddDisablePrecision(t *testing.T) {
testm = <-a.metrics
actual = testm.String()
assert.Equal(t,
fmt.Sprintf("acctest,acc=test value=101 %d", int64(1139572800082912748)),
fmt.Sprintf("acctest,acc=test value=101 %d\n", int64(1139572800082912748)),
actual)
}

Expand Down Expand Up @@ -190,7 +190,7 @@ func TestAddNoPrecisionWithInterval(t *testing.T) {
testm = <-a.metrics
actual = testm.String()
assert.Equal(t,
fmt.Sprintf("acctest,acc=test value=101 %d", int64(1139572800000000000)),
fmt.Sprintf("acctest,acc=test value=101 %d\n", int64(1139572800000000000)),
actual)
}

Expand All @@ -207,7 +207,7 @@ func TestDifferentPrecisions(t *testing.T) {
testm := <-a.metrics
actual := testm.String()
assert.Equal(t,
fmt.Sprintf("acctest,acc=test value=101 %d", int64(1139572800000000000)),
fmt.Sprintf("acctest,acc=test value=101 %d\n", int64(1139572800000000000)),
actual)

a.SetPrecision(0, time.Millisecond)
Expand All @@ -217,7 +217,7 @@ func TestDifferentPrecisions(t *testing.T) {
testm = <-a.metrics
actual = testm.String()
assert.Equal(t,
fmt.Sprintf("acctest,acc=test value=101 %d", int64(1139572800083000000)),
fmt.Sprintf("acctest,acc=test value=101 %d\n", int64(1139572800083000000)),
actual)

a.SetPrecision(0, time.Microsecond)
Expand All @@ -227,7 +227,7 @@ func TestDifferentPrecisions(t *testing.T) {
testm = <-a.metrics
actual = testm.String()
assert.Equal(t,
fmt.Sprintf("acctest,acc=test value=101 %d", int64(1139572800082913000)),
fmt.Sprintf("acctest,acc=test value=101 %d\n", int64(1139572800082913000)),
actual)

a.SetPrecision(0, time.Nanosecond)
Expand All @@ -237,7 +237,7 @@ func TestDifferentPrecisions(t *testing.T) {
testm = <-a.metrics
actual = testm.String()
assert.Equal(t,
fmt.Sprintf("acctest,acc=test value=101 %d", int64(1139572800082912748)),
fmt.Sprintf("acctest,acc=test value=101 %d\n", int64(1139572800082912748)),
actual)
}

Expand Down Expand Up @@ -270,7 +270,7 @@ func TestAddGauge(t *testing.T) {
testm = <-metrics
actual = testm.String()
assert.Equal(t,
fmt.Sprintf("acctest,acc=test value=101 %d", now.UnixNano()),
fmt.Sprintf("acctest,acc=test value=101 %d\n", now.UnixNano()),
actual)
assert.Equal(t, testm.Type(), telegraf.Gauge)
}
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestAddCounter(t *testing.T) {
testm = <-metrics
actual = testm.String()
assert.Equal(t,
fmt.Sprintf("acctest,acc=test value=101 %d", now.UnixNano()),
fmt.Sprintf("acctest,acc=test value=101 %d\n", now.UnixNano()),
actual)
assert.Equal(t, testm.Type(), telegraf.Counter)
}
Expand All @@ -328,11 +328,11 @@ func (tm *TestMetricMaker) MakeMetric(
return m
}
case telegraf.Counter:
if m, err := telegraf.NewCounterMetric(measurement, tags, fields, t); err == nil {
if m, err := metric.New(measurement, tags, fields, t, telegraf.Counter); err == nil {
return m
}
case telegraf.Gauge:
if m, err := telegraf.NewGaugeMetric(measurement, tags, fields, t); err == nil {
if m, err := metric.New(measurement, tags, fields, t, telegraf.Gauge); err == nil {
return m
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/models/running_aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ func TestMakeMetricA(t *testing.T) {
)
assert.Equal(
t,
fmt.Sprintf("RITest value=101i %d\n", now.UnixNano()),
m.String(),
fmt.Sprintf("RITest value=101i %d", now.UnixNano()),
)
assert.Equal(
t,
Expand All @@ -202,8 +202,8 @@ func TestMakeMetricA(t *testing.T) {
)
assert.Equal(
t,
fmt.Sprintf("RITest value=101i %d\n", now.UnixNano()),
m.String(),
fmt.Sprintf("RITest value=101i %d", now.UnixNano()),
)
assert.Equal(
t,
Expand All @@ -220,8 +220,8 @@ func TestMakeMetricA(t *testing.T) {
)
assert.Equal(
t,
fmt.Sprintf("RITest value=101i %d\n", now.UnixNano()),
m.String(),
fmt.Sprintf("RITest value=101i %d", now.UnixNano()),
)
assert.Equal(
t,
Expand Down
39 changes: 24 additions & 15 deletions internal/models/running_input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestMakeMetricNilFields(t *testing.T) {
)
assert.Equal(
t,
fmt.Sprintf("RITest value=101i %d", now.UnixNano()),
fmt.Sprintf("RITest value=101i %d\n", now.UnixNano()),
m.String(),
)
}
Expand Down Expand Up @@ -78,8 +78,8 @@ func TestMakeMetric(t *testing.T) {
)
assert.Equal(
t,
fmt.Sprintf("RITest value=101i %d\n", now.UnixNano()),
m.String(),
fmt.Sprintf("RITest value=101i %d", now.UnixNano()),
)
assert.Equal(
t,
Expand All @@ -96,8 +96,8 @@ func TestMakeMetric(t *testing.T) {
)
assert.Equal(
t,
fmt.Sprintf("RITest value=101i %d\n", now.UnixNano()),
m.String(),
fmt.Sprintf("RITest value=101i %d", now.UnixNano()),
)
assert.Equal(
t,
Expand All @@ -114,8 +114,8 @@ func TestMakeMetric(t *testing.T) {
)
assert.Equal(
t,
fmt.Sprintf("RITest value=101i %d\n", now.UnixNano()),
m.String(),
fmt.Sprintf("RITest value=101i %d", now.UnixNano()),
)
assert.Equal(
t,
Expand Down Expand Up @@ -148,8 +148,8 @@ func TestMakeMetricWithPluginTags(t *testing.T) {
)
assert.Equal(
t,
fmt.Sprintf("RITest,foo=bar value=101i %d\n", now.UnixNano()),
m.String(),
fmt.Sprintf("RITest,foo=bar value=101i %d", now.UnixNano()),
)
}

Expand Down Expand Up @@ -204,8 +204,8 @@ func TestMakeMetricWithDaemonTags(t *testing.T) {
)
assert.Equal(
t,
fmt.Sprintf("RITest,foo=bar value=101i %d\n", now.UnixNano()),
m.String(),
fmt.Sprintf("RITest,foo=bar value=101i %d", now.UnixNano()),
)
}

Expand Down Expand Up @@ -237,8 +237,8 @@ func TestMakeMetricInfFields(t *testing.T) {
)
assert.Equal(
t,
fmt.Sprintf("RITest value=101i %d\n", now.UnixNano()),
m.String(),
fmt.Sprintf("RITest value=101i %d", now.UnixNano()),
)
}

Expand Down Expand Up @@ -275,11 +275,20 @@ func TestMakeMetricAllFieldTypes(t *testing.T) {
telegraf.Untyped,
now,
)
assert.Equal(
t,
fmt.Sprintf("RITest a=10i,b=10i,c=10i,d=10i,e=10i,f=10i,g=10i,h=10i,i=10i,j=10,k=9223372036854775807i,l=\"foobar\",m=true %d", now.UnixNano()),
m.String(),
)
assert.Contains(t, m.String(), "a=10i")
assert.Contains(t, m.String(), "b=10i")
assert.Contains(t, m.String(), "c=10i")
assert.Contains(t, m.String(), "d=10i")
assert.Contains(t, m.String(), "e=10i")
assert.Contains(t, m.String(), "f=10i")
assert.Contains(t, m.String(), "g=10i")
assert.Contains(t, m.String(), "h=10i")
assert.Contains(t, m.String(), "i=10i")
assert.Contains(t, m.String(), "j=10")
assert.NotContains(t, m.String(), "j=10i")
assert.Contains(t, m.String(), "k=9223372036854775807i")
assert.Contains(t, m.String(), "l=\"foobar\"")
assert.Contains(t, m.String(), "m=true")
}

func TestMakeMetricNameOverride(t *testing.T) {
Expand All @@ -300,8 +309,8 @@ func TestMakeMetricNameOverride(t *testing.T) {
)
assert.Equal(
t,
fmt.Sprintf("foobar value=101i %d\n", now.UnixNano()),
m.String(),
fmt.Sprintf("foobar value=101i %d", now.UnixNano()),
)
}

Expand All @@ -323,8 +332,8 @@ func TestMakeMetricNamePrefix(t *testing.T) {
)
assert.Equal(
t,
fmt.Sprintf("foobar_RITest value=101i %d\n", now.UnixNano()),
m.String(),
fmt.Sprintf("foobar_RITest value=101i %d", now.UnixNano()),
)
}

Expand All @@ -346,7 +355,7 @@ func TestMakeMetricNameSuffix(t *testing.T) {
)
assert.Equal(
t,
fmt.Sprintf("RITest_foobar value=101i %d\n", now.UnixNano()),
m.String(),
fmt.Sprintf("RITest_foobar value=101i %d", now.UnixNano()),
)
}
14 changes: 7 additions & 7 deletions internal/models/running_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func BenchmarkRunningOutputAddWrite(b *testing.B) {
ro.Quiet = true

for n := 0; n < b.N; n++ {
ro.AddMetric(first5[0])
ro.AddMetric(testutil.TestMetric(101, "metric1"))
ro.Write()
}
}
Expand All @@ -55,7 +55,7 @@ func BenchmarkRunningOutputAddWriteEvery100(b *testing.B) {
ro.Quiet = true

for n := 0; n < b.N; n++ {
ro.AddMetric(first5[0])
ro.AddMetric(testutil.TestMetric(101, "metric1"))
if n%100 == 0 {
ro.Write()
}
Expand All @@ -74,7 +74,7 @@ func BenchmarkRunningOutputAddFailWrites(b *testing.B) {
ro.Quiet = true

for n := 0; n < b.N; n++ {
ro.AddMetric(first5[0])
ro.AddMetric(testutil.TestMetric(101, "metric1"))
}
}

Expand Down Expand Up @@ -140,7 +140,7 @@ func TestRunningOutput_TagIncludeNoMatch(t *testing.T) {
m := &mockOutput{}
ro := NewRunningOutput("test", m, conf, 1000, 10000)

ro.AddMetric(first5[0])
ro.AddMetric(testutil.TestMetric(101, "metric1"))
assert.Len(t, m.Metrics(), 0)

err := ro.Write()
Expand All @@ -161,7 +161,7 @@ func TestRunningOutput_TagExcludeMatch(t *testing.T) {
m := &mockOutput{}
ro := NewRunningOutput("test", m, conf, 1000, 10000)

ro.AddMetric(first5[0])
ro.AddMetric(testutil.TestMetric(101, "metric1"))
assert.Len(t, m.Metrics(), 0)

err := ro.Write()
Expand All @@ -182,7 +182,7 @@ func TestRunningOutput_TagExcludeNoMatch(t *testing.T) {
m := &mockOutput{}
ro := NewRunningOutput("test", m, conf, 1000, 10000)

ro.AddMetric(first5[0])
ro.AddMetric(testutil.TestMetric(101, "metric1"))
assert.Len(t, m.Metrics(), 0)

err := ro.Write()
Expand All @@ -203,7 +203,7 @@ func TestRunningOutput_TagIncludeMatch(t *testing.T) {
m := &mockOutput{}
ro := NewRunningOutput("test", m, conf, 1000, 10000)

ro.AddMetric(first5[0])
ro.AddMetric(testutil.TestMetric(101, "metric1"))
assert.Len(t, m.Metrics(), 0)

err := ro.Write()
Expand Down
Loading

0 comments on commit e5c7a71

Please sign in to comment.