Skip to content

Commit

Permalink
fixed test to check actual value
Browse files Browse the repository at this point in the history
Closes #273

caught a typo :D using it
  • Loading branch information
jrxFive authored and sparrc committed Oct 18, 2015
1 parent c3dad00 commit 3192c78
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ of metrics collected and from how many plugins.
- [#244](https://github.com/influxdb/telegraf/pull/244): netstat plugin, thanks @shirou!
- [#262](https://github.com/influxdb/telegraf/pull/262): zookeeper plugin, thanks @jrxFive!
- [#237](https://github.com/influxdb/telegraf/pull/237): statsd service plugin, thanks @sparrc
- [#273](https://github.com/influxdb/telegraf/pull/273): puppet agent plugin, thats @jrxFive!

### Bugfixes
- [#228](https://github.com/influxdb/telegraf/pull/228): New version of package will replace old one. Thanks @ekini!
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ Telegraf currently has support for collecting metrics from
* postgresql
* procstat
* prometheus
* puppetagent
* rabbitmq
* redis
* rethinkdb
Expand Down
9 changes: 5 additions & 4 deletions plugins/puppetagent/puppetagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package puppetagent

import (
"fmt"
"github.com/influxdb/telegraf/plugins"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"reflect"
"strings"

"github.com/influxdb/telegraf/plugins"
)

// PuppetAgent is a PuppetAgent plugin
Expand All @@ -16,8 +17,8 @@ type PuppetAgent struct {
}

var sampleConfig = `
#Location of puppet last run summary file
location = "/var/lib/puppet/state/last_run_summary.yaml"
# Location of puppet last run summary file
location = "/var/lib/puppet/state/last_run_summary.yaml"
`

type State struct {
Expand Down Expand Up @@ -57,7 +58,7 @@ type time struct {
Exec float64 `yaml:"exec"`
Anchor float64 `yaml:"anchor"`
SSHAuthorizedKey float64 `yaml:"ssh_authorized_key"`
Service float64 `yaml:"server"`
Service float64 `yaml:"service"`
Package float64 `yaml:"package"`
Total float64 `yaml:"total"`
ConfigRetrieval float64 `yaml:"config_retrieval"`
Expand Down
85 changes: 57 additions & 28 deletions plugins/puppetagent/puppetagent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,61 @@ func TestGather(t *testing.T) {
}
pa.Gather(&acc)

assert.True(t, acc.HasIntValue("events_failure"))
assert.True(t, acc.HasIntValue("events_total"))
assert.True(t, acc.HasIntValue("events_success"))
assert.True(t, acc.HasIntValue("resources_failed"))
assert.True(t, acc.HasIntValue("resources_scheduled"))
assert.True(t, acc.HasIntValue("resources_changed"))
assert.True(t, acc.HasIntValue("resources_skipped"))
assert.True(t, acc.HasIntValue("resources_total"))
assert.True(t, acc.HasIntValue("resources_failedtorestart"))
assert.True(t, acc.HasIntValue("resources_restarted"))
assert.True(t, acc.HasIntValue("resources_outofsync"))
assert.True(t, acc.HasIntValue("changes_total"))

assert.True(t, acc.HasIntValue("time_lastrun"))
assert.True(t, acc.HasIntValue("version_config"))

assert.True(t, acc.HasFloatValue("time_user"))
assert.True(t, acc.HasFloatValue("time_schedule"))
assert.True(t, acc.HasFloatValue("time_filebucket"))
assert.True(t, acc.HasFloatValue("time_file"))
assert.True(t, acc.HasFloatValue("time_exec"))
assert.True(t, acc.HasFloatValue("time_anchor"))
assert.True(t, acc.HasFloatValue("time_sshauthorizedkey"))
assert.True(t, acc.HasFloatValue("time_service"))
assert.True(t, acc.HasFloatValue("time_package"))
assert.True(t, acc.HasFloatValue("time_total"))
assert.True(t, acc.HasFloatValue("time_configretrieval"))
assert.True(t, acc.HasFloatValue("time_cron"))
checkInt := []struct {
name string
value int64
}{
{"events_failure", 0},
{"events_total", 0},
{"events_success", 0},
{"resources_failed", 0},
{"resources_scheduled", 0},
{"resources_changed", 0},
{"resources_skipped", 0},
{"resources_total", 109},
{"resources_failedtorestart", 0},
{"resources_restarted", 0},
{"resources_outofsync", 0},
{"changes_total", 0},
{"time_lastrun", 1444936531},
{"version_config", 1444936521},
}

for _, c := range checkInt {
assert.Equal(t, true, acc.CheckValue(c.name, c.value))
}

checkFloat := []struct {
name string
value float64
}{
{"time_user", 0.004331},
{"time_schedule", 0.001123},
{"time_filebucket", 0.000353},
{"time_file", 0.441472},
{"time_exec", 0.508123},
{"time_anchor", 0.000555},
{"time_sshauthorizedkey", 0.000764},
{"time_service", 1.807795},
{"time_package", 1.325788},
{"time_total", 8.85354707064819},
{"time_configretrieval", 4.75567007064819},
{"time_cron", 0.000584},
}

for _, f := range checkFloat {
assert.Equal(t, true, acc.CheckValue(f.name, f.value))
}

checkString := []struct {
name string
value string
}{
{"version_puppet", "3.7.5"},
}

for _, s := range checkString {
assert.Equal(t, true, acc.CheckValue(s.name, s.value))
}

}

0 comments on commit 3192c78

Please sign in to comment.