2019-01-08 00:37:16 +00:00
|
|
|
package influxdb_test
|
2018-12-03 16:07:08 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-04-03 17:39:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2"
|
2021-09-13 19:12:35 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/kit/platform"
|
2020-04-03 17:39:20 +00:00
|
|
|
influxtest "github.com/influxdata/influxdb/v2/testing"
|
2019-03-19 06:58:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
orgOneID = "020f755c3c083000"
|
2018-12-03 16:07:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLabelValidate(t *testing.T) {
|
|
|
|
type fields struct {
|
2019-03-19 06:58:42 +00:00
|
|
|
Name string
|
2021-03-30 18:10:02 +00:00
|
|
|
OrgID platform.ID
|
2018-12-03 16:07:08 +00:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "valid label",
|
|
|
|
fields: fields{
|
2019-03-19 06:58:42 +00:00
|
|
|
Name: "iot",
|
|
|
|
OrgID: influxtest.MustIDBase16(orgOneID),
|
2018-12-03 16:07:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-03-19 06:58:42 +00:00
|
|
|
name: "label requires a name",
|
|
|
|
fields: fields{
|
|
|
|
OrgID: influxtest.MustIDBase16(orgOneID),
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "label requires an organization ID",
|
|
|
|
fields: fields{
|
|
|
|
Name: "iot",
|
|
|
|
},
|
2018-12-03 16:07:08 +00:00
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2019-08-22 02:08:51 +00:00
|
|
|
m := influxdb.Label{
|
2019-04-11 22:50:02 +00:00
|
|
|
Name: tt.fields.Name,
|
|
|
|
OrgID: tt.fields.OrgID,
|
2018-12-03 16:07:08 +00:00
|
|
|
}
|
|
|
|
if err := m.Validate(); (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("Label.Validate() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|