加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tag_test.go 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
package influxdb_test
import (
"github.com/influxdata/influxdb/v2/kit/platform/errors"
"testing"
"github.com/influxdata/influxdb/v2"
influxTesting "github.com/influxdata/influxdb/v2/testing"
)
func TestTagValid(t *testing.T) {
cases := []struct {
name string
src influxdb.TagRule
err error
}{
{
name: "regular status rule",
src: influxdb.TagRule{
Tag: influxdb.Tag{Key: "k1", Value: "v1"},
Operator: influxdb.Equal,
},
},
{
name: "empty",
src: influxdb.TagRule{},
err: &errors.Error{
Code: errors.EInvalid,
Msg: "tag must contain a key and a value",
},
},
{
name: "empty key",
src: influxdb.TagRule{
Tag: influxdb.Tag{Value: "v1"},
},
err: &errors.Error{
Code: errors.EInvalid,
Msg: "tag must contain a key and a value",
},
},
{
name: "empty value",
src: influxdb.TagRule{
Tag: influxdb.Tag{Key: "k1"},
},
err: &errors.Error{
Code: errors.EInvalid,
Msg: "tag must contain a key and a value",
},
},
{
name: "invalid operator",
src: influxdb.TagRule{
Tag: influxdb.Tag{Key: "k1", Value: "v1"},
Operator: influxdb.Operator(-1),
},
err: &errors.Error{
Code: errors.EInvalid,
Msg: "Operator is invalid",
},
},
}
for _, c := range cases {
err := c.src.Valid()
influxTesting.ErrorsEqual(t, err, c.err)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化