0.3.0 unit tests: amon, datadog, librato

This commit is contained in:
Cameron Sparr 2016-01-07 10:09:04 -07:00
parent b9869eadc3
commit 0e398f5802
3 changed files with 30 additions and 20 deletions

View File

@ -18,7 +18,7 @@ func TestBuildPoint(t *testing.T) {
err error err error
}{ }{
{ {
testutil.TestPoint(float64(0.0)), testutil.TestPoint(float64(0.0), "testpt"),
Point{ Point{
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()), float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
0.0, 0.0,
@ -26,7 +26,7 @@ func TestBuildPoint(t *testing.T) {
nil, nil,
}, },
{ {
testutil.TestPoint(float64(1.0)), testutil.TestPoint(float64(1.0), "testpt"),
Point{ Point{
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()), float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
1.0, 1.0,
@ -34,7 +34,7 @@ func TestBuildPoint(t *testing.T) {
nil, nil,
}, },
{ {
testutil.TestPoint(int(10)), testutil.TestPoint(int(10), "testpt"),
Point{ Point{
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()), float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
10.0, 10.0,
@ -42,7 +42,7 @@ func TestBuildPoint(t *testing.T) {
nil, nil,
}, },
{ {
testutil.TestPoint(int32(112345)), testutil.TestPoint(int32(112345), "testpt"),
Point{ Point{
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()), float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
112345.0, 112345.0,
@ -50,7 +50,7 @@ func TestBuildPoint(t *testing.T) {
nil, nil,
}, },
{ {
testutil.TestPoint(int64(112345)), testutil.TestPoint(int64(112345), "testpt"),
Point{ Point{
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()), float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
112345.0, 112345.0,
@ -58,7 +58,7 @@ func TestBuildPoint(t *testing.T) {
nil, nil,
}, },
{ {
testutil.TestPoint(float32(11234.5)), testutil.TestPoint(float32(11234.5), "testpt"),
Point{ Point{
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()), float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
11234.5, 11234.5,
@ -66,7 +66,7 @@ func TestBuildPoint(t *testing.T) {
nil, nil,
}, },
{ {
testutil.TestPoint("11234.5"), testutil.TestPoint("11234.5", "testpt"),
Point{ Point{
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()), float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
11234.5, 11234.5,
@ -75,15 +75,16 @@ func TestBuildPoint(t *testing.T) {
}, },
} }
for _, tt := range tagtests { for _, tt := range tagtests {
pt, err := buildPoint(tt.ptIn) pt, err := buildPoints(tt.ptIn)
if err != nil && tt.err == nil { if err != nil && tt.err == nil {
t.Errorf("%s: unexpected error, %+v\n", tt.ptIn.Name(), err) t.Errorf("%s: unexpected error, %+v\n", tt.ptIn.Name(), err)
} }
if tt.err != nil && err == nil { if tt.err != nil && err == nil {
t.Errorf("%s: expected an error (%s) but none returned", tt.ptIn.Name(), tt.err.Error()) t.Errorf("%s: expected an error (%s) but none returned", tt.ptIn.Name(), tt.err.Error())
} }
if !reflect.DeepEqual(pt, tt.outPt) && tt.err == nil { if !reflect.DeepEqual(pt["value"], tt.outPt) && tt.err == nil {
t.Errorf("%s: \nexpected %+v\ngot %+v\n", tt.ptIn.Name(), tt.outPt, pt) t.Errorf("%s: \nexpected %+v\ngot %+v\n",
tt.ptIn.Name(), tt.outPt, pt["value"])
} }
} }
} }

View File

@ -162,15 +162,16 @@ func TestBuildPoint(t *testing.T) {
}, },
} }
for _, tt := range tagtests { for _, tt := range tagtests {
pt, err := buildPoint(tt.ptIn) pt, err := buildPoints(tt.ptIn)
if err != nil && tt.err == nil { if err != nil && tt.err == nil {
t.Errorf("%s: unexpected error, %+v\n", tt.ptIn.Name(), err) t.Errorf("%s: unexpected error, %+v\n", tt.ptIn.Name(), err)
} }
if tt.err != nil && err == nil { if tt.err != nil && err == nil {
t.Errorf("%s: expected an error (%s) but none returned", tt.ptIn.Name(), tt.err.Error()) t.Errorf("%s: expected an error (%s) but none returned", tt.ptIn.Name(), tt.err.Error())
} }
if !reflect.DeepEqual(pt, tt.outPt) && tt.err == nil { if !reflect.DeepEqual(pt["value"], tt.outPt) && tt.err == nil {
t.Errorf("%s: \nexpected %+v\ngot %+v\n", tt.ptIn.Name(), tt.outPt, pt) t.Errorf("%s: \nexpected %+v\ngot %+v\n",
tt.ptIn.Name(), tt.outPt, pt["value"])
} }
} }
} }

View File

@ -142,15 +142,20 @@ func TestBuildGauge(t *testing.T) {
l := NewLibrato(fakeUrl) l := NewLibrato(fakeUrl)
for _, gt := range gaugeTests { for _, gt := range gaugeTests {
gauge, err := l.buildGauge(gt.ptIn) gauges, err := l.buildGauges(gt.ptIn)
if err != nil && gt.err == nil { if err != nil && gt.err == nil {
t.Errorf("%s: unexpected error, %+v\n", gt.ptIn.Name(), err) t.Errorf("%s: unexpected error, %+v\n", gt.ptIn.Name(), err)
} }
if gt.err != nil && err == nil { if gt.err != nil && err == nil {
t.Errorf("%s: expected an error (%s) but none returned", gt.ptIn.Name(), gt.err.Error()) t.Errorf("%s: expected an error (%s) but none returned",
gt.ptIn.Name(), gt.err.Error())
} }
if !reflect.DeepEqual(gauge, gt.outGauge) && gt.err == nil { if len(gauges) == 0 {
t.Errorf("%s: \nexpected %+v\ngot %+v\n", gt.ptIn.Name(), gt.outGauge, gauge) continue
}
if gt.err == nil && !reflect.DeepEqual(gauges[0], gt.outGauge) {
t.Errorf("%s: \nexpected %+v\ngot %+v\n",
gt.ptIn.Name(), gt.outGauge, gauges[0])
} }
} }
} }
@ -198,15 +203,18 @@ func TestBuildGaugeWithSource(t *testing.T) {
l := NewLibrato(fakeUrl) l := NewLibrato(fakeUrl)
l.SourceTag = "hostname" l.SourceTag = "hostname"
for _, gt := range gaugeTests { for _, gt := range gaugeTests {
gauge, err := l.buildGauge(gt.ptIn) gauges, err := l.buildGauges(gt.ptIn)
if err != nil && gt.err == nil { if err != nil && gt.err == nil {
t.Errorf("%s: unexpected error, %+v\n", gt.ptIn.Name(), err) t.Errorf("%s: unexpected error, %+v\n", gt.ptIn.Name(), err)
} }
if gt.err != nil && err == nil { if gt.err != nil && err == nil {
t.Errorf("%s: expected an error (%s) but none returned", gt.ptIn.Name(), gt.err.Error()) t.Errorf("%s: expected an error (%s) but none returned", gt.ptIn.Name(), gt.err.Error())
} }
if !reflect.DeepEqual(gauge, gt.outGauge) && gt.err == nil { if len(gauges) == 0 {
t.Errorf("%s: \nexpected %+v\ngot %+v\n", gt.ptIn.Name(), gt.outGauge, gauge) continue
}
if gt.err == nil && !reflect.DeepEqual(gauges[0], gt.outGauge) {
t.Errorf("%s: \nexpected %+v\ngot %+v\n", gt.ptIn.Name(), gt.outGauge, gauges[0])
} }
} }
} }