2019-10-26 04:54:28 +00:00
|
|
|
package pkger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/influxdata/influxdb"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPkg(t *testing.T) {
|
|
|
|
t.Run("Summary", func(t *testing.T) {
|
|
|
|
t.Run("buckets returned in asc order by name", func(t *testing.T) {
|
|
|
|
pkg := Pkg{
|
|
|
|
mBuckets: map[string]*bucket{
|
|
|
|
"buck_2": {
|
2019-11-22 18:41:08 +00:00
|
|
|
id: influxdb.ID(2),
|
|
|
|
OrgID: influxdb.ID(100),
|
|
|
|
Description: "desc2",
|
2020-02-05 00:15:20 +00:00
|
|
|
name: &references{val: "name2"},
|
2019-11-22 18:41:08 +00:00
|
|
|
RetentionRules: retentionRules{newRetentionRule(2 * time.Hour)},
|
2019-10-26 04:54:28 +00:00
|
|
|
},
|
|
|
|
"buck_1": {
|
2019-11-22 18:41:08 +00:00
|
|
|
id: influxdb.ID(1),
|
|
|
|
OrgID: influxdb.ID(100),
|
2020-02-05 00:15:20 +00:00
|
|
|
name: &references{val: "name1"},
|
2019-11-22 18:41:08 +00:00
|
|
|
Description: "desc1",
|
|
|
|
RetentionRules: retentionRules{newRetentionRule(time.Hour)},
|
2019-10-26 04:54:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
summary := pkg.Summary()
|
|
|
|
|
|
|
|
require.Len(t, summary.Buckets, len(pkg.mBuckets))
|
|
|
|
for i := 1; i <= len(summary.Buckets); i++ {
|
|
|
|
buck := summary.Buckets[i-1]
|
2019-12-12 19:09:32 +00:00
|
|
|
assert.Equal(t, SafeID(i), buck.ID)
|
|
|
|
assert.Equal(t, SafeID(100), buck.OrgID)
|
2019-10-26 04:54:28 +00:00
|
|
|
assert.Equal(t, "desc"+strconv.Itoa(i), buck.Description)
|
|
|
|
assert.Equal(t, "name"+strconv.Itoa(i), buck.Name)
|
|
|
|
assert.Equal(t, time.Duration(i)*time.Hour, buck.RetentionPeriod)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("labels returned in asc order by name", func(t *testing.T) {
|
|
|
|
pkg := Pkg{
|
|
|
|
mLabels: map[string]*label{
|
|
|
|
"2": {
|
2019-10-30 17:55:13 +00:00
|
|
|
id: influxdb.ID(2),
|
2019-10-26 04:54:28 +00:00
|
|
|
OrgID: influxdb.ID(100),
|
2019-12-03 02:05:10 +00:00
|
|
|
name: "name2",
|
2019-10-26 04:54:28 +00:00
|
|
|
Description: "desc2",
|
|
|
|
Color: "blurple",
|
|
|
|
},
|
|
|
|
"1": {
|
2019-10-30 17:55:13 +00:00
|
|
|
id: influxdb.ID(1),
|
2019-10-26 04:54:28 +00:00
|
|
|
OrgID: influxdb.ID(100),
|
2019-12-03 02:05:10 +00:00
|
|
|
name: "name1",
|
2019-10-26 04:54:28 +00:00
|
|
|
Description: "desc1",
|
|
|
|
Color: "peru",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
summary := pkg.Summary()
|
|
|
|
|
|
|
|
require.Len(t, summary.Labels, len(pkg.mLabels))
|
|
|
|
label1 := summary.Labels[0]
|
2019-12-12 19:09:32 +00:00
|
|
|
assert.Equal(t, SafeID(1), label1.ID)
|
|
|
|
assert.Equal(t, SafeID(100), label1.OrgID)
|
2019-10-26 04:54:28 +00:00
|
|
|
assert.Equal(t, "name1", label1.Name)
|
2019-12-12 19:09:32 +00:00
|
|
|
assert.Equal(t, "desc1", label1.Properties.Description)
|
|
|
|
assert.Equal(t, "peru", label1.Properties.Color)
|
2019-10-26 04:54:28 +00:00
|
|
|
|
|
|
|
label2 := summary.Labels[1]
|
2019-12-12 19:09:32 +00:00
|
|
|
assert.Equal(t, SafeID(2), label2.ID)
|
|
|
|
assert.Equal(t, SafeID(100), label2.OrgID)
|
|
|
|
assert.Equal(t, "desc2", label2.Properties.Description)
|
2019-10-26 04:54:28 +00:00
|
|
|
assert.Equal(t, "name2", label2.Name)
|
2019-12-12 19:09:32 +00:00
|
|
|
assert.Equal(t, "blurple", label2.Properties.Color)
|
2019-10-26 04:54:28 +00:00
|
|
|
})
|
2019-10-30 17:55:13 +00:00
|
|
|
|
|
|
|
t.Run("label mappings returned in asc order by name", func(t *testing.T) {
|
|
|
|
bucket1 := &bucket{
|
|
|
|
id: influxdb.ID(20),
|
2020-02-05 00:15:20 +00:00
|
|
|
name: &references{val: "b1"},
|
2019-10-30 17:55:13 +00:00
|
|
|
}
|
|
|
|
label1 := &label{
|
|
|
|
id: influxdb.ID(2),
|
|
|
|
OrgID: influxdb.ID(100),
|
2019-12-03 02:05:10 +00:00
|
|
|
name: "name2",
|
2019-10-30 17:55:13 +00:00
|
|
|
Description: "desc2",
|
|
|
|
Color: "blurple",
|
2019-11-07 00:45:00 +00:00
|
|
|
associationMapping: associationMapping{
|
2019-12-06 00:53:00 +00:00
|
|
|
mappings: map[assocMapKey][]assocMapVal{
|
2019-11-07 00:45:00 +00:00
|
|
|
assocMapKey{
|
|
|
|
resType: influxdb.BucketsResourceType,
|
2019-12-03 02:05:10 +00:00
|
|
|
name: bucket1.Name(),
|
2019-12-06 00:53:00 +00:00
|
|
|
}: {{
|
2019-11-07 00:45:00 +00:00
|
|
|
v: bucket1,
|
2019-12-06 00:53:00 +00:00
|
|
|
}},
|
2019-10-30 17:55:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
bucket1.labels = append(bucket1.labels, label1)
|
|
|
|
|
|
|
|
pkg := Pkg{
|
2019-12-03 02:05:10 +00:00
|
|
|
mBuckets: map[string]*bucket{bucket1.Name(): bucket1},
|
|
|
|
mLabels: map[string]*label{label1.Name(): label1},
|
2019-10-30 17:55:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
summary := pkg.Summary()
|
|
|
|
|
|
|
|
require.Len(t, summary.LabelMappings, 1)
|
|
|
|
mapping1 := summary.LabelMappings[0]
|
2019-12-12 19:09:32 +00:00
|
|
|
assert.Equal(t, SafeID(bucket1.id), mapping1.ResourceID)
|
2019-12-03 02:05:10 +00:00
|
|
|
assert.Equal(t, bucket1.Name(), mapping1.ResourceName)
|
2019-10-30 17:55:13 +00:00
|
|
|
assert.Equal(t, influxdb.BucketsResourceType, mapping1.ResourceType)
|
2019-12-12 19:09:32 +00:00
|
|
|
assert.Equal(t, SafeID(label1.id), mapping1.LabelID)
|
2019-12-03 02:05:10 +00:00
|
|
|
assert.Equal(t, label1.Name(), mapping1.LabelName)
|
2019-10-30 17:55:13 +00:00
|
|
|
})
|
2019-10-26 04:54:28 +00:00
|
|
|
})
|
|
|
|
}
|