Permalink
Browse files

client: add test for writing string values

  • Loading branch information...
1 parent a1be304 commit 9625c4d48556aef080d24a1947e2424e9eb94698 @suyash suyash committed Jul 27, 2016
Showing with 55 additions and 0 deletions.
  1. +55 −0 client_test.go
View
@@ -436,3 +436,58 @@ func TestWritingInstanceMetric(t *testing.T) {
t.Errorf("expected a string at offset %v", off)
}
}
+
+func TestStringValueWriting(t *testing.T) {
+ c, err := NewPCPClient("test", ProcessFlag)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ metric := c.MustRegisterString("test.str", "kirk", CounterSemantics, StringType, OneUnit)
+ c.MustStart()
+ defer c.MustStop()
+
+ h, _, _, v, _, _, s, err := mmvdump.Dump(c.buffer.Bytes())
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ if h.Toc != 3 {
+ t.Errorf("expected toc to be 3, not %v", h.Toc)
+ }
+
+ sm := metric.(*PCPSingletonMetric)
+
+ if val, ok := v[uint64(sm.valueoffset)]; !ok {
+ t.Errorf("expected value at %v", sm.valueoffset)
+ } else {
+ add := uint64(val.Extra)
+ if str, ok := s[add]; !ok {
+ t.Errorf("expected a string at address %v", add)
+ } else {
+ if v := string(str.Payload[:4]); v != "kirk" {
+ t.Errorf("expected metric value to be kirk, not %v", v)
+ }
+ }
+ }
+
+ sm.Set("spock")
+
+ _, _, _, v, _, _, s, err = mmvdump.Dump(c.buffer.Bytes())
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ val := v[uint64(sm.valueoffset)]
+ add := uint64(val.Extra)
+ if str, ok := s[add]; !ok {
+ t.Errorf("expected a string at address %v", add)
+ } else {
+ if v := string(str.Payload[:5]); v != "spock" {
+ t.Errorf("expected metric value to be spock, not %v", v)
+ }
+ }
+}

0 comments on commit 9625c4d

Please sign in to comment.