func TestProcessDeleteGauges(t *testing.T) { // Some data with expected mean of 20 flag.Set("delete-gauges", "true") gauges = make(map[string]float64) gauges["gaugordelete"] = math.MaxUint64 now := int64(1418052649) var buffer bytes.Buffer num := processGauges(&buffer, now, "external") assert.Equal(t, num, int64(0)) assert.Equal(t, buffer.String(), "") gauges["gaugordelete"] = 12345 num = processGauges(&buffer, now, "external") assert.Equal(t, num, int64(1)) gauges["gaugordelete"] = math.MaxUint64 num = processGauges(&buffer, now, "external") assert.Equal(t, buffer.String(), "gaugordelete 12345.000000 1418052649\n") assert.Equal(t, num, int64(0)) }
func TestParseLineMisc(t *testing.T) { d := []byte("a.key.with-0.dash:4|c") packet := parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "a.key.with-0.dash", packet.Bucket) assert.Equal(t, int64(4), packet.Value.(int64)) assert.Equal(t, "c", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) d = []byte("a.key.with 0.space:4|c") packet = parseLine(d) assert.Equal(t, "a.key.with_0.space", packet.Bucket) assert.Equal(t, int64(4), packet.Value.(int64)) assert.Equal(t, "c", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) d = []byte("a.key.with/0.slash:4|c") packet = parseLine(d) assert.Equal(t, "a.key.with-0.slash", packet.Bucket) assert.Equal(t, int64(4), packet.Value.(int64)) assert.Equal(t, "c", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) d = []byte("a.key.with@#*&%$^_0.garbage:4|c") packet = parseLine(d) assert.Equal(t, "a.key.with_0.garbage", packet.Bucket) assert.Equal(t, int64(4), packet.Value.(int64)) assert.Equal(t, "c", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) flag.Set("prefix", "test.") d = []byte("prefix:4|c") packet = parseLine(d) assert.Equal(t, "test.prefix", packet.Bucket) assert.Equal(t, int64(4), packet.Value.(int64)) assert.Equal(t, "c", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) flag.Set("prefix", "") d = []byte("counter0:11|c|@0.001\na.key.with-0.dash:4|c\ngauge:3|g\ncounter:10|c|@0.01") parser := NewParser(bytes.NewBuffer(d), true) packet, more := parser.Next() assert.Equal(t, more, true) assert.Equal(t, "counter0", packet.Bucket) assert.Equal(t, int64(11), packet.Value.(int64)) assert.Equal(t, "c", packet.Modifier) assert.Equal(t, float32(0.001), packet.Sampling) packet, more = parser.Next() assert.Equal(t, more, true) assert.Equal(t, "a.key.with-0.dash", packet.Bucket) assert.Equal(t, int64(4), packet.Value.(int64)) assert.Equal(t, "c", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) packet, more = parser.Next() assert.Equal(t, more, true) assert.Equal(t, "gauge", packet.Bucket) assert.Equal(t, GaugeData{false, false, 3}, packet.Value) assert.Equal(t, "g", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) packet, more = parser.Next() assert.Equal(t, more, false) assert.Equal(t, "counter", packet.Bucket) assert.Equal(t, int64(10), packet.Value.(int64)) assert.Equal(t, "c", packet.Modifier) assert.Equal(t, float32(0.01), packet.Sampling) d = []byte("a.key.with-0.dash:4\ngauge3|g") packet = parseLine(d) if packet != nil { t.Fail() } d = []byte("a.key.with-0.dash:4") packet = parseLine(d) if packet != nil { t.Fail() } d = []byte("gorets:5m") packet = parseLine(d) if packet != nil { t.Fail() } d = []byte("gorets") packet = parseLine(d) if packet != nil { t.Fail() } d = []byte("gorets:") packet = parseLine(d) if packet != nil { t.Fail() } d = []byte("gorets:5|mg") packet = parseLine(d) if packet != nil { t.Fail() } d = []byte("gorets:5|ms|@") packet = parseLine(d) if packet != nil { t.Fail() } d = []byte("") packet = parseLine(d) if packet != nil { t.Fail() } d = []byte("gorets:xxx|c") packet = parseLine(d) if packet != nil { t.Fail() } d = []byte("gaugor:xxx|g") packet = parseLine(d) if packet != nil { t.Fail() } d = []byte("gaugor:xxx|z") packet = parseLine(d) if packet != nil { t.Fail() } d = []byte("deploys.test.myservice4:100|t") packet = parseLine(d) if packet != nil { t.Fail() } d = []byte("up-to-colon:") packet = parseLine(d) if packet != nil { t.Fail() } d = []byte("up-to-pipe:1|") packet = parseLine(d) if packet != nil { t.Fail() } }