Unit test improved.
This commit is contained in:
parent
b04f0dafe7
commit
5ca139deba
|
@ -117,7 +117,7 @@ func (a *Elasticsearch) WriteOneMessage(metric telegraf.Metric) (string, error)
|
|||
|
||||
if host, ok := metric.Tags()["host"]; ok {
|
||||
m["host"] = host
|
||||
}
|
||||
}
|
||||
|
||||
// Elasticsearch 2.x does not support this dots-to-object transformation
|
||||
// and so dots in field names are not allowed in versions 2.X.
|
||||
|
@ -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
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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.")
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue