func TestParsePointNoFields(t *testing.T) { _, err := tsdb.ParsePointsString("cpu_load_short,host=server01,region=us-west") if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, "cpu_load_short,host=server01,region=us-west") } _, err = tsdb.ParsePointsString("cpu") if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, "cpu") } _, err = tsdb.ParsePointsString("cpu,") if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, "cpu,") } _, err = tsdb.ParsePointsString("cpu, value=1") if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, "cpu, value=1") } _, err = tsdb.ParsePointsString("cpu,,, value=1") if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, "cpu,,, value=1") } }
func TestParsePointMissingFieldValue(t *testing.T) { _, err := tsdb.ParsePointsString(`cpu,host=serverA,region=us-west value=`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west value=`) } _, err = tsdb.ParsePointsString(`cpu,host=serverA,region=us-west value= 1000000000`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west value= 1000000000`) } _, err = tsdb.ParsePointsString(`cpu,host=serverA,region=us-west value=,value2=1`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west value=,value2=1`) } _, err = tsdb.ParsePointsString(`cpu,host=server01,region=us-west 1434055562000000000`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=server01,region=us-west 1434055562000000000`) } _, err = tsdb.ParsePointsString(`cpu,host=server01,region=us-west value=1,b`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=server01,region=us-west value=1,b`) } }
func TestParsePointMissingTagValue(t *testing.T) { _, err := tsdb.ParsePointsString(`cpu,host value=1`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host value=1`) } _, err = tsdb.ParsePointsString(`cpu,host=serverA,region value=1`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region value=1`) } _, err = tsdb.ParsePointsString(`cpu,host=serverA,region= value=1`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region= value=1`) } }
func TestParsePointFloatMultipleDecimals(t *testing.T) { _, err := tsdb.ParsePointsString(`cpu,host=serverA,region=us-west value=1.1.1`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west value=1.1.1`) } println(err.Error()) }
func TestParsePointFloatScientific(t *testing.T) { _, err := tsdb.ParsePointsString(`cpu,host=serverA,region=us-west value=1.0e4`) if err != nil { t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=1.0e4`, err) } pts, err := tsdb.ParsePointsString(`cpu,host=serverA,region=us-west value=1e4`) if err != nil { t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=1.0e4`, err) } if pts[0].Fields()["value"] != 1e4 { t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=1e4`, err) } }
func TestParsePointMinInt64(t *testing.T) { // out of range _, err := tsdb.ParsePointsString(`cpu,host=serverA,region=us-west value=-9223372036854775809`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west value=-9223372036854775809`) } // min int _, err = tsdb.ParsePointsString(`cpu,host=serverA,region=us-west value=-9223372036854775808`) if err != nil { t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=-9223372036854775808`, err) } // leading zeros _, err = tsdb.ParsePointsString(`cpu,host=serverA,region=us-west value=-0009223372036854775808`) if err != nil { t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=-0009223372036854775808`, err) } }
func TestParsePointMaxFloat64(t *testing.T) { // out of range _, err := tsdb.ParsePointsString(fmt.Sprintf(`cpu,host=serverA,region=us-west value=%s`, "1"+string(maxFloat64))) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west value=...`) } // max float _, err = tsdb.ParsePointsString(fmt.Sprintf(`cpu,host=serverA,region=us-west value=%s`, string(maxFloat64))) if err != nil { t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=9223372036854775807`, err) } // leading zeros _, err = tsdb.ParsePointsString(fmt.Sprintf(`cpu,host=serverA,region=us-west value=%s`, "0000"+string(maxFloat64))) if err != nil { t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=0009223372036854775807`, err) } }
func TestParsePointMinFloat64(t *testing.T) { // out of range _, err := tsdb.ParsePointsString(fmt.Sprintf(`cpu,host=serverA,region=us-west value=%s`, "-1"+string(minFloat64)[1:])) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west value=...`) } // min float _, err = tsdb.ParsePointsString(fmt.Sprintf(`cpu,host=serverA,region=us-west value=%s`, string(minFloat64))) if err != nil { t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=...`, err) } // leading zeros _, err = tsdb.ParsePointsString(fmt.Sprintf(`cpu,host=serverA,region=us-west value=%s`, "-0000000"+string(minFloat64)[1:])) if err != nil { t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=...`, err) } }
func TestParsePointNoValue(t *testing.T) { pts, err := tsdb.ParsePointsString("") if err != nil { t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, "", err) } if exp := 0; len(pts) != exp { t.Errorf(`ParsePoints("%s") len mismatch. got %v, exp %vr`, "", len(pts), exp) } }
func TestParsePointMissingTagName(t *testing.T) { _, err := tsdb.ParsePointsString(`cpu,host=serverA,=us-east value=1`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,=us-east value=1`) } _, err = tsdb.ParsePointsString(`cpu,host=serverAa\,,=us-east value=1`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverAa\,,=us-east value=1`) } _, err = tsdb.ParsePointsString(`cpu,host=serverA\,,=us-east value=1`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA\,,=us-east value=1`) } _, err = tsdb.ParsePointsString(`cpu,host=serverA,\ =us-east value=1`) if err != nil { t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,\ =us-east value=1`, err) } }
func TestParsePointMissingFieldName(t *testing.T) { _, err := tsdb.ParsePointsString(`cpu,host=serverA,region=us-west =`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west =`) } _, err = tsdb.ParsePointsString(`cpu,host=serverA,region=us-west =123`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west =123`) } _, err = tsdb.ParsePointsString(`cpu,host=serverA,region=us-west a\ =123`) if err != nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west a\ =123`) } _, err = tsdb.ParsePointsString(`cpu,host=serverA,region=us-west value=123,=456`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west value=123,=456`) } }
func TestParsePointBooleanInvalid(t *testing.T) { _, err := tsdb.ParsePointsString(`cpu,host=serverA,region=us-west value=a`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west value=a`) } }
func TestParsePointFloatNegativeScientific(t *testing.T) { _, err := tsdb.ParsePointsString(`cpu,host=serverA,region=us-west value=-1.0e-4`) if err != nil { t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=-1.0e-4`, err) } }
func TestParsePointMissingQuote(t *testing.T) { _, err := tsdb.ParsePointsString(`cpu,host=serverA value="test`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, "cpu") } }
func TestParsePointFloatNoLeadingDigit(t *testing.T) { _, err := tsdb.ParsePointsString(`cpu,host=serverA,region=us-west value=.1`) if err != nil { t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=-1.0`, err) } }
func TestParsePointNegativeInteger(t *testing.T) { _, err := tsdb.ParsePointsString(`cpu,host=serverA,region=us-west value=-1`) if err != nil { t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=-1`, err) } }
func TestParsePointNegativeWrongPlace(t *testing.T) { _, err := tsdb.ParsePointsString(`cpu,host=serverA,region=us-west value=0.-1`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west value=0.-1`) } }
func TestParsePointNumberNonNumeric(t *testing.T) { _, err := tsdb.ParsePointsString(`cpu,host=serverA,region=us-west value=.1a`) if err == nil { t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west value=.1a`) } }