influxdb/tag_test.go

69 lines
1.3 KiB
Go
Raw Normal View History

2019-09-23 16:00:03 +00:00
package influxdb_test
2019-07-19 09:42:01 +00:00
import (
"testing"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
influxTesting "github.com/influxdata/influxdb/v2/testing"
2019-07-19 09:42:01 +00:00
)
func TestTagValid(t *testing.T) {
cases := []struct {
name string
2019-09-23 16:00:03 +00:00
src influxdb.TagRule
2019-07-19 09:42:01 +00:00
err error
}{
{
name: "regular status rule",
2019-09-23 16:00:03 +00:00
src: influxdb.TagRule{
Tag: influxdb.Tag{Key: "k1", Value: "v1"},
2019-09-23 16:00:03 +00:00
Operator: influxdb.Equal,
2019-07-19 09:42:01 +00:00
},
},
{
name: "empty",
2019-09-23 16:00:03 +00:00
src: influxdb.TagRule{},
err: &errors.Error{
Code: errors.EInvalid,
2019-07-19 09:42:01 +00:00
Msg: "tag must contain a key and a value",
},
},
{
name: "empty key",
2019-09-23 16:00:03 +00:00
src: influxdb.TagRule{
Tag: influxdb.Tag{Value: "v1"},
2019-07-19 09:42:01 +00:00
},
err: &errors.Error{
Code: errors.EInvalid,
2019-07-19 09:42:01 +00:00
Msg: "tag must contain a key and a value",
},
},
{
name: "empty value",
2019-09-23 16:00:03 +00:00
src: influxdb.TagRule{
Tag: influxdb.Tag{Key: "k1"},
2019-07-19 09:42:01 +00:00
},
err: &errors.Error{
Code: errors.EInvalid,
2019-07-19 09:42:01 +00:00
Msg: "tag must contain a key and a value",
},
},
{
name: "invalid operator",
2019-09-23 16:00:03 +00:00
src: influxdb.TagRule{
2019-10-14 21:33:50 +00:00
Tag: influxdb.Tag{Key: "k1", Value: "v1"},
Operator: influxdb.Operator(-1),
2019-07-19 09:42:01 +00:00
},
err: &errors.Error{
Code: errors.EInvalid,
2019-10-14 21:33:50 +00:00
Msg: "Operator is invalid",
2019-07-19 09:42:01 +00:00
},
},
}
for _, c := range cases {
err := c.src.Valid()
influxTesting.ErrorsEqual(t, err, c.err)
}
}