Skip to content

Commit

Permalink
Add more public point functions for v2 client
Browse files Browse the repository at this point in the history
Closes #4505
  • Loading branch information
sparrc committed Oct 19, 2015
1 parent ef72c3c commit 66a31ee
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
25 changes: 25 additions & 0 deletions client/v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,31 @@ func (p *Point) PrecisionString(precison string) string {
return p.pt.PrecisionString(precison)
}

// Name returns the measurement name of the point
func (p *Point) Name() string {
return p.pt.Name()
}

// Name returns the tags associated with the point
func (p *Point) Tags() map[string]string {
return p.pt.Tags()
}

// Time return the timestamp for the point
func (p *Point) Time() time.Time {
return p.pt.Time()
}

// UnixNano returns the unix nano time of the point
func (p *Point) UnixNano() int64 {
return p.pt.UnixNano()
}

// Fields returns the fields for the point
func (p *Point) Fields() map[string]interface{} {
return p.pt.Fields()
}

func (c *client) Write(bp BatchPoints) error {
u := c.url
u.Path = "write"
Expand Down
49 changes: 49 additions & 0 deletions client/v2/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"reflect"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -186,6 +187,54 @@ func TestClient_PointWithoutTimeString(t *testing.T) {
}
}

func TestClient_PointName(t *testing.T) {
tags := map[string]string{"cpu": "cpu-total"}
fields := map[string]interface{}{"idle": 10.1, "system": 50.9, "user": 39.0}
p := NewPoint("cpu_usage", tags, fields)

exp := "cpu_usage"
if p.Name() != exp {
t.Errorf("Error, got %s, expected %s",
p.Name(), exp)
}
}

func TestClient_PointTags(t *testing.T) {
tags := map[string]string{"cpu": "cpu-total"}
fields := map[string]interface{}{"idle": 10.1, "system": 50.9, "user": 39.0}
p := NewPoint("cpu_usage", tags, fields)

if !reflect.DeepEqual(tags, p.Tags()) {
t.Errorf("Error, got %v, expected %v",
p.Tags(), tags)
}
}

func TestClient_PointUnixNano(t *testing.T) {
const shortForm = "2006-Jan-02"
time1, _ := time.Parse(shortForm, "2013-Feb-03")
tags := map[string]string{"cpu": "cpu-total"}
fields := map[string]interface{}{"idle": 10.1, "system": 50.9, "user": 39.0}
p := NewPoint("cpu_usage", tags, fields, time1)

exp := int64(1359849600000000000)
if p.UnixNano() != exp {
t.Errorf("Error, got %d, expected %d",
p.UnixNano(), exp)
}
}

func TestClient_PointFields(t *testing.T) {
tags := map[string]string{"cpu": "cpu-total"}
fields := map[string]interface{}{"idle": 10.1, "system": 50.9, "user": 39.0}
p := NewPoint("cpu_usage", tags, fields)

if !reflect.DeepEqual(fields, p.Fields()) {
t.Errorf("Error, got %v, expected %v",
p.Fields(), fields)
}
}

func TestBatchPoints_PrecisionError(t *testing.T) {
_, err := NewBatchPoints(BatchPointsConfig{Precision: "foobar"})
if err == nil {
Expand Down

0 comments on commit 66a31ee

Please sign in to comment.