Unit test improved.

This commit is contained in:
Amanda Hager Lopes de Andrade 2016-10-13 16:04:04 -03:00
parent b04f0dafe7
commit 5ca139deba
2 changed files with 11 additions and 12 deletions

View File

@ -148,10 +148,10 @@ func (a *Elasticsearch) WriteOneMessage(metric telegraf.Metric) (string, error)
Do()
if errMessage != nil {
return "",fmt.Errorf("FAILED to send Elasticsearch message to index %s : %s\n", a.IndexName, errMessage)
return "", fmt.Errorf("FAILED to send Elasticsearch message to index %s : %s\n", a.IndexName, errMessage)
}
return put1.Id,nil
return put1.Id, nil
}

View File

@ -1,15 +1,14 @@
package elasticsearch
import (
"encoding/json"
"testing"
"time"
"encoding/json"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)
func TestConnectAndWrite(t *testing.T) {
@ -45,21 +44,21 @@ func TestConnectAndWrite(t *testing.T) {
get1, errGet := e.Client.Get().
Index(e.IndexName).
Type(metrictest.Name()).
Id(messageid).
Type(metrictest.Name()).
Id(messageid).
Do()
require.NoError(t, errGet)
require.Equal(t,true,get1.Found,"Message not found on Elasticsearch.")
require.Equal(t, true, get1.Found, "Message not found on Elasticsearch.")
require.NotEqual(t,nil,get1.Source,"Source not found on Elasticsearch.")
require.NotEqual(t, nil, get1.Source, "Source not found on Elasticsearch.")
var dat map[string]interface{}
err = json.Unmarshal(*get1.Source, &dat)
require.NoError(t, err)
require.Equal(t,"192.168.0.1",dat["host"],"Values of Host are not the same.")
require.Equal(t,"2010-11-10T23:00:00Z",dat["created"],"Values of Created are not the same.")
require.Equal(t,3.14,dat["value"],"Values of Value are not the same.")
require.Equal(t, "192.168.0.1", dat["host"], "Values of Host are not the same.")
require.Equal(t, "2010-11-10T23:00:00Z", dat["created"], "Values of Created are not the same.")
require.Equal(t, 3.14, dat["value"], "Values of Value are not the same.")
}