Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
titusjaka authored and litleleprikon committed Oct 8, 2019
1 parent 10abe2a commit 167fa10
Showing 1 changed file with 65 additions and 11 deletions.
76 changes: 65 additions & 11 deletions filter/metrics_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,74 @@ func TestParseMetric(t *testing.T) {
Convey("Check metrics with magic '-1' timestamp", func() {
timeStart := time.Now().Unix()
magicTimestampMetrics := []ValidMetricCase{
{"One.two.three 123 -1", "One.two.three", "One.two.three", map[string]string{}, 123, timeStart},
{"One.two.three 1.23e2 -1", "One.two.three", "One.two.three", map[string]string{}, 123, timeStart},
{"One.two.three -123 -1", "One.two.three", "One.two.three", map[string]string{}, -123, timeStart},
{
input: "One.two.three 123 -1",
metric: "One.two.three",
name: "Metric with integer value and magic -1 as time value",
labels: map[string]string{},
value: 123,
timestamp: timeStart,
},
{
input: "One.two.three 1.23e2 -1",
metric: "One.two.three",
name: "Metric with float value and magic -1 as time value",
labels: map[string]string{},
value: 123,
timestamp: timeStart,
},
{
input: "One.two.three -123 -1",
metric: "One.two.three",
name: "Metric with negative integer value and magic -1 as time value",
labels: map[string]string{},
value: -123,
timestamp: timeStart,
},
{
input: "One.two.three +123 -1",
metric: "One.two.three",
name: "Metric with positive integer value and magic -1 as time value",
labels: map[string]string{},
value: 123,
timestamp: timeStart,
},
{
input: "One.two.three 123. -1",
metric: "One.two.three",
name: "Metric with integer with point value and magic -1 as time value",
labels: map[string]string{},
value: 123,
timestamp: timeStart,
},
{
input: "One.two.three 123.0 -1",
metric: "One.two.three",
name: "Metric with integer with 0 value and magic -1 as time value",
labels: map[string]string{},
value: 123,
timestamp: timeStart,
},
{
input: "One.two.three .123 -1",
metric: "One.two.three",
name: "Metric with float without 0 value and magic -1 as time value",
labels: map[string]string{},
value: 0.123,
timestamp: timeStart,
},
}

for _, magicMetric := range magicTimestampMetrics {
parsedMetric, err := ParseMetric([]byte(magicMetric.input))
So(err, ShouldBeEmpty)
So(parsedMetric.Metric, ShouldEqual, magicMetric.metric)
So(parsedMetric.Name, ShouldEqual, magicMetric.name)
So(parsedMetric.Labels, ShouldResemble, magicMetric.labels)
So(parsedMetric.Value, ShouldEqual, magicMetric.value)
// I add 5 seconds to avoid false failures
So(parsedMetric.Timestamp, ShouldBeBetweenOrEqual, magicMetric.timestamp, magicMetric.timestamp+5)
Convey(magicMetric.name, func() {
parsedMetric, err := ParseMetric([]byte(magicMetric.input))
So(err, ShouldBeEmpty)
So(parsedMetric.Metric, ShouldEqual, magicMetric.metric)
So(parsedMetric.Labels, ShouldResemble, magicMetric.labels)
So(parsedMetric.Value, ShouldEqual, magicMetric.value)
// I add 5 seconds to avoid false failures
So(parsedMetric.Timestamp, ShouldBeBetweenOrEqual, magicMetric.timestamp, magicMetric.timestamp+5)
})
}
})
})
Expand Down

0 comments on commit 167fa10

Please sign in to comment.