chore(pkger): ensure sorting is done by PkgName for all parser resource summaries

pull/17981/head
Johnny Steenbergen 2020-05-06 11:06:39 -07:00 committed by Johnny Steenbergen
parent 9bde937c54
commit 9ab4447617
3 changed files with 46 additions and 46 deletions

View File

@ -530,7 +530,7 @@ func (p *Pkg) buckets() []*bucket {
buckets = append(buckets, b)
}
sort.Slice(buckets, func(i, j int) bool { return buckets[i].Name() < buckets[j].Name() })
sort.Slice(buckets, func(i, j int) bool { return buckets[i].PkgName() < buckets[j].PkgName() })
return buckets
}
@ -541,7 +541,7 @@ func (p *Pkg) checks() []*check {
checks = append(checks, c)
}
sort.Slice(checks, func(i, j int) bool { return checks[i].Name() < checks[j].Name() })
sort.Slice(checks, func(i, j int) bool { return checks[i].PkgName() < checks[j].PkgName() })
return checks
}
@ -574,7 +574,7 @@ func (p *Pkg) notificationEndpoints() []*notificationEndpoint {
sort.Slice(endpoints, func(i, j int) bool {
ei, ej := endpoints[i], endpoints[j]
if ei.kind == ej.kind {
return ei.Name() < ej.Name()
return ei.PkgName() < ej.PkgName()
}
return ei.kind < ej.kind
})
@ -586,7 +586,7 @@ func (p *Pkg) notificationRules() []*notificationRule {
for _, r := range p.mNotificationRules {
rules = append(rules, r)
}
sort.Slice(rules, func(i, j int) bool { return rules[i].Name() < rules[j].Name() })
sort.Slice(rules, func(i, j int) bool { return rules[i].PkgName() < rules[j].PkgName() })
return rules
}
@ -618,7 +618,7 @@ func (p *Pkg) tasks() []*task {
tasks = append(tasks, t)
}
sort.Slice(tasks, func(i, j int) bool { return tasks[i].Name() < tasks[j].Name() })
sort.Slice(tasks, func(i, j int) bool { return tasks[i].PkgName() < tasks[j].PkgName() })
return tasks
}
@ -630,7 +630,7 @@ func (p *Pkg) telegrafs() []*telegraf {
teles = append(teles, t)
}
sort.Slice(teles, func(i, j int) bool { return teles[i].Name() < teles[j].Name() })
sort.Slice(teles, func(i, j int) bool { return teles[i].PkgName() < teles[j].PkgName() })
return teles
}
@ -641,7 +641,7 @@ func (p *Pkg) variables() []*variable {
vars = append(vars, v)
}
sort.Slice(vars, func(i, j int) bool { return vars[i].Name() < vars[j].Name() })
sort.Slice(vars, func(i, j int) bool { return vars[i].PkgName() < vars[j].PkgName() })
return vars
}

View File

@ -1199,7 +1199,7 @@ func (s sortedLabels) Len() int {
}
func (s sortedLabels) Less(i, j int) bool {
return s[i].Name() < s[j].Name()
return s[i].PkgName() < s[j].PkgName()
}
func (s sortedLabels) Swap(i, j int) {

View File

@ -27,19 +27,19 @@ func TestParse(t *testing.T) {
actual := buckets[0]
expectedBucket := SummaryBucket{
PkgName: "rucket-22",
Name: "display name",
Description: "bucket 2 description",
PkgName: "rucket-11",
Name: "rucket-11",
Description: "bucket 1 description",
RetentionPeriod: time.Hour,
LabelAssociations: []SummaryLabel{},
}
assert.Equal(t, expectedBucket, actual)
actual = buckets[1]
expectedBucket = SummaryBucket{
PkgName: "rucket-11",
Name: "rucket-11",
Description: "bucket 1 description",
RetentionPeriod: time.Hour,
PkgName: "rucket-22",
Name: "display name",
Description: "bucket 2 description",
LabelAssociations: []SummaryLabel{},
}
assert.Equal(t, expectedBucket, actual)
@ -160,19 +160,7 @@ spec:
labels := pkg.Summary().Labels
require.Len(t, labels, 3)
expectedLabel0 := SummaryLabel{
PkgName: "label-3",
Name: "display name",
Properties: struct {
Color string `json:"color"`
Description string `json:"description"`
}{
Description: "label 3 description",
},
}
assert.Equal(t, expectedLabel0, labels[0])
expectedLabel1 := SummaryLabel{
expectedLabel := SummaryLabel{
PkgName: "label-1",
Name: "label-1",
Properties: struct {
@ -183,9 +171,9 @@ spec:
Description: "label 1 description",
},
}
assert.Equal(t, expectedLabel1, labels[1])
assert.Equal(t, expectedLabel, labels[0])
expectedLabel2 := SummaryLabel{
expectedLabel = SummaryLabel{
PkgName: "label-2",
Name: "label-2",
Properties: struct {
@ -196,7 +184,19 @@ spec:
Description: "label 2 description",
},
}
assert.Equal(t, expectedLabel2, labels[2])
assert.Equal(t, expectedLabel, labels[1])
expectedLabel = SummaryLabel{
PkgName: "label-3",
Name: "display name",
Properties: struct {
Color string `json:"color"`
Description string `json:"description"`
}{
Description: "label 3 description",
},
}
assert.Equal(t, expectedLabel, labels[2])
})
})
@ -3669,6 +3669,21 @@ spec:
assert.Equal(t, vals, v.Arguments.Values)
}
// validates we support all known variable types
varEquals(t,
"var-const-3",
"constant",
influxdb.VariableConstantValues([]string{"first val"}),
sum.Variables[0],
)
varEquals(t,
"var-map-4",
"map",
influxdb.VariableMapValues{"k1": "v1"},
sum.Variables[1],
)
varEquals(t,
"query var",
"query",
@ -3676,21 +3691,6 @@ spec:
Query: `buckets() |> filter(fn: (r) => r.name !~ /^_/) |> rename(columns: {name: "_value"}) |> keep(columns: ["_value"])`,
Language: "flux",
},
sum.Variables[0],
)
// validates we support all known variable types
varEquals(t,
"var-const-3",
"constant",
influxdb.VariableConstantValues([]string{"first val"}),
sum.Variables[1],
)
varEquals(t,
"var-map-4",
"map",
influxdb.VariableMapValues{"k1": "v1"},
sum.Variables[2],
)