Skip to content

Commit

Permalink
Improve testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mapno committed Oct 10, 2019
1 parent 9e1f2b1 commit 38678ae
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions prometheusvanilla/builders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
bucketsTag reflect.StructTag = `name:"some_name" help:"some help for the metric" buckets:"0.001,0.005,0.01,0.05,0.1,0.5,1,5,10"`
maxAgeTag reflect.StructTag = `name:"some_name" help:"some help for the metric" max_age:"1h"`
objectivesTag reflect.StructTag = `name:"some_name" help:"some help for the metric" max_age:"1h" objectives:"0.55,0.95,0.98"`
objectivesMalformedTag reflect.StructTag = `name:"some_name" help:"some help for the metric" max_age:"1h" objectives:"this,will,fail"`
expectedBuckets = []float64{0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10}
expectedMaxAge = time.Hour
expectedObjectives = map[float64]float64{0.55: 0.045, 0.95: 0.005, 0.98: 0.002}
Expand Down Expand Up @@ -88,25 +89,30 @@ func TestMaxAge(t *testing.T) {
t.Run("Test it retrieves custom max_age", func(t *testing.T) {
maxAge, err := maxAgeFromTag(maxAgeTag)
assert.NoError(t, err)
assert.Equal(t, maxAge, expectedMaxAge)
assert.Equal(t, expectedMaxAge, maxAge)
})
t.Run("Test it returns 0 when no max_age is found", func(t *testing.T) {
maxAge, err := maxAgeFromTag(defaultTag)
assert.NoError(t, err)
assert.Equal(t, maxAge, time.Duration(0))
assert.Equal(t, time.Duration(0), maxAge)
})
}

func TestObjectives(t *testing.T) {
t.Run("Test parsing objectives from tag", func(t *testing.T) {
obj, err := objectivesFromTag(objectivesTag)
assert.NoError(t, err)
assert.Equal(t, obj, expectedObjectives)
assert.Equal(t, expectedObjectives, obj)
})
t.Run("Test returning default objective values when none are specified", func(t *testing.T) {
obj, err := objectivesFromTag(defaultTag)
assert.NoError(t, err)
assert.Equal(t, obj, DefaultObjectives())
assert.Equal(t, DefaultObjectives(), obj)
})
t.Run("Test returning default objective values when none are specified", func(t *testing.T) {
obj, err := objectivesFromTag(objectivesMalformedTag)
assert.Error(t, err)
assert.Nil(t, obj)
})
}

Expand Down

0 comments on commit 38678ae

Please sign in to comment.