Unit test couchbase input plugin

This commit is contained in:
Vebjorn Ljosa 2016-03-18 18:37:57 -04:00
parent de10b8ef26
commit 233cd77e9d
2 changed files with 51 additions and 13 deletions

View File

@ -36,7 +36,7 @@ func (r *Couchbase) Description() string {
// Returns one of the errors encountered while gathering stats (if any). // Returns one of the errors encountered while gathering stats (if any).
func (r *Couchbase) Gather(acc telegraf.Accumulator) error { func (r *Couchbase) Gather(acc telegraf.Accumulator) error {
if len(r.Servers) == 0 { if len(r.Servers) == 0 {
r.gatherServer("http://localhost:8091/", acc) r.gatherServer("http://localhost:8091/", acc, nil)
return nil return nil
} }
@ -48,7 +48,7 @@ func (r *Couchbase) Gather(acc telegraf.Accumulator) error {
wg.Add(1) wg.Add(1)
go func(serv string) { go func(serv string) {
defer wg.Done() defer wg.Done()
outerr = r.gatherServer(serv, acc) outerr = r.gatherServer(serv, acc, nil)
}(serv) }(serv)
} }
@ -57,17 +57,21 @@ func (r *Couchbase) Gather(acc telegraf.Accumulator) error {
return outerr return outerr
} }
func (r *Couchbase) gatherServer(addr string, acc telegraf.Accumulator) error { func (r *Couchbase) gatherServer(addr string, acc telegraf.Accumulator, pool *couchbase.Pool) error {
client, err := couchbase.Connect(addr) if pool == nil {
if err != nil { client, err := couchbase.Connect(addr)
return err if err != nil {
} return err
// `default` is the only possible pool name. It's a }
// placeholder for a possible future Couchbase feature. See
// http://stackoverflow.com/a/16990911/17498. // `default` is the only possible pool name. It's a
pool, err := client.GetPool("default") // placeholder for a possible future Couchbase feature. See
if err != nil { // http://stackoverflow.com/a/16990911/17498.
return err p, err := client.GetPool("default")
if err != nil {
return err
}
pool = &p
} }
for i := 0; i < len(pool.Nodes); i++ { for i := 0; i < len(pool.Nodes); i++ {
node := pool.Nodes[i] node := pool.Nodes[i]

File diff suppressed because one or more lines are too long