2019-01-08 00:37:16 +00:00
|
|
|
package influxdb_test
|
2018-07-19 15:21:06 +00:00
|
|
|
|
2018-07-19 16:15:14 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
2018-07-20 10:24:07 +00:00
|
|
|
|
2020-04-03 17:39:20 +00:00
|
|
|
platform "github.com/influxdata/influxdb/v2"
|
2021-08-30 22:27:11 +00:00
|
|
|
platform2 "github.com/influxdata/influxdb/v2/kit/platform"
|
2020-04-03 17:39:20 +00:00
|
|
|
platformtesting "github.com/influxdata/influxdb/v2/testing"
|
2018-07-19 16:15:14 +00:00
|
|
|
)
|
2018-07-19 15:21:06 +00:00
|
|
|
|
|
|
|
func TestDBRPMapping_Validate(t *testing.T) {
|
|
|
|
type fields struct {
|
2018-07-31 01:36:22 +00:00
|
|
|
Database string
|
|
|
|
RetentionPolicy string
|
2018-07-19 15:21:06 +00:00
|
|
|
Default bool
|
2021-03-30 18:10:02 +00:00
|
|
|
OrganizationID platform2.ID
|
|
|
|
BucketID platform2.ID
|
2018-07-19 15:21:06 +00:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "mapping requires a database",
|
|
|
|
fields: fields{
|
|
|
|
Database: "",
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mapping requires an rp",
|
|
|
|
fields: fields{
|
|
|
|
Database: "telegraf",
|
|
|
|
RetentionPolicy: "",
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mapping requires an orgid",
|
|
|
|
fields: fields{
|
|
|
|
Database: "telegraf",
|
|
|
|
RetentionPolicy: "autogen",
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mapping requires a bucket id",
|
|
|
|
fields: fields{
|
|
|
|
Database: "telegraf",
|
|
|
|
RetentionPolicy: "autogen",
|
2018-10-10 19:39:09 +00:00
|
|
|
OrganizationID: platformtesting.MustIDBase16("debac1e0deadbeef"),
|
2018-07-19 15:21:06 +00:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "db cannot have non-letters/numbers/_/./-",
|
|
|
|
fields: fields{
|
2018-07-31 01:36:22 +00:00
|
|
|
Database: string([]byte{0x0D}),
|
2018-07-19 15:21:06 +00:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
2018-07-19 16:15:14 +00:00
|
|
|
name: "rp cannot have non-printable characters",
|
2018-07-19 15:21:06 +00:00
|
|
|
fields: fields{
|
|
|
|
Database: "telegraf",
|
2018-07-31 01:36:22 +00:00
|
|
|
RetentionPolicy: string([]byte{0x0D}),
|
2018-07-19 15:21:06 +00:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "dash accepted as valid database",
|
|
|
|
fields: fields{
|
|
|
|
Database: "howdy-doody",
|
|
|
|
RetentionPolicy: "autogen",
|
2018-10-10 19:39:09 +00:00
|
|
|
OrganizationID: platformtesting.MustIDBase16("debac1e0deadbeef"),
|
|
|
|
BucketID: platformtesting.MustIDBase16("5ca1ab1edeadbea7"),
|
2018-07-19 15:21:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2018-07-20 10:24:07 +00:00
|
|
|
m := platform.DBRPMapping{
|
2018-07-19 15:21:06 +00:00
|
|
|
Database: tt.fields.Database,
|
|
|
|
RetentionPolicy: tt.fields.RetentionPolicy,
|
|
|
|
Default: tt.fields.Default,
|
|
|
|
OrganizationID: tt.fields.OrganizationID,
|
|
|
|
BucketID: tt.fields.BucketID,
|
|
|
|
}
|
2018-07-20 10:24:07 +00:00
|
|
|
|
2018-07-19 15:21:06 +00:00
|
|
|
if err := m.Validate(); (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("DBRPMapping.Validate() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|