Revert "bug fixes and refactoring"

This reverts commit 86961cc814.
This commit is contained in:
David G. Simmons
2017-11-03 13:28:35 -04:00
parent ae9c881d33
commit 1b7a1d9228
4 changed files with 91 additions and 89 deletions

View File

@@ -1,16 +1,17 @@
package particle
import (
"github.com/influxdata/telegraf/testutil"
"log"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/influxdata/telegraf/testutil"
)
func postWebhooks(rb *ParticleWebhook, eventBody string) *httptest.ResponseRecorder {
req, _ := http.NewRequest("POST", "/", strings.NewReader(eventBody))
log.Printf("eventBody: %s\n", eventBody)
w := httptest.NewRecorder()
w.Code = 500
@@ -20,10 +21,10 @@ func postWebhooks(rb *ParticleWebhook, eventBody string) *httptest.ResponseRecor
}
func TestNewItem(t *testing.T) {
t.Parallel()
var acc testutil.Accumulator
rb := &ParticleWebhook{Path: "/particle", acc: &acc}
resp := postWebhooks(rb, NewItemJSON())
log.Printf("Respnse: %s\n", resp.Body)
if resp.Code != http.StatusOK {
t.Errorf("POST new_item returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK)
}
@@ -31,12 +32,12 @@ func TestNewItem(t *testing.T) {
fields := map[string]interface{}{
"temp_c": 26.680000,
"temp_f": 80.024001,
"infrared": 528.0,
"lux": 0.0,
"humidity": 44.937500,
"pressure": 998.998901,
"altitude": 119.331436,
"broadband": 1266.0,
"broadband": 1266,
"infrared": 528,
"lux": 0,
}
tags := map[string]string{
@@ -44,54 +45,13 @@ func TestNewItem(t *testing.T) {
"location": "TravelingWilbury",
}
acc.AssertContainsTaggedFields(t, "temperature", fields, tags)
acc.AssertContainsTaggedFields(t, "particle_webhooks", fields, tags)
}
func TestUnknowItem(t *testing.T) {
t.Parallel()
var acc testutil.Accumulator
rb := &ParticleWebhook{Path: "/particle", acc: &acc}
rb := &ParticleWebhook{Path: "/particle"}
resp := postWebhooks(rb, UnknowJSON())
log.Printf("Response: %s\n", resp.Body)
if resp.Code != http.StatusOK {
t.Errorf("POST unknown returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK)
}
}
func NewItemJSON() string {
return `
{
"event": "temperature",
"data": {
"tags": {
"id": "230035001147343438323536",
"location": "TravelingWilbury"
},
"values": {
"temp_c": 26.680000,
"temp_f": 80.024001,
"humidity": 44.937500,
"pressure": 998.998901,
"altitude": 119.331436,
"broadband": 1266,
"infrared": 528,
"lux": 0
}
},
"ttl": 60,
"published_at": "2017-09-28T21:54:10.897Z",
"coreid": "123456789938323536",
"userid": "1234ee123ac8e5ec1231a123d",
"version": 10,
"public": false,
"productID": 1234,
"name": "sensor",
"influx_db": "mydata"
}`
}
func UnknowJSON() string {
return `
{
"event": "roger"
}`
}