parent
82185dd434
commit
bb270f1145
|
@ -8486,10 +8486,15 @@ components:
|
||||||
type: string
|
type: string
|
||||||
name:
|
name:
|
||||||
type: string
|
type: string
|
||||||
|
properties:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
color:
|
||||||
|
type: string
|
||||||
description:
|
description:
|
||||||
type: string
|
type: string
|
||||||
retentionPeriod:
|
envReferences:
|
||||||
type: string
|
$ref: "#/components/schemas/PkgEnvReferences"
|
||||||
PkgChart:
|
PkgChart:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|
|
@ -597,6 +597,7 @@ type SummaryLabel struct {
|
||||||
Color string `json:"color"`
|
Color string `json:"color"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
} `json:"properties"`
|
} `json:"properties"`
|
||||||
|
EnvReferences []SummaryReference `json:"envReferences"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SummaryLabelMapping provides a summary of a label mapped with a single resource.
|
// SummaryLabelMapping provides a summary of a label mapped with a single resource.
|
||||||
|
|
|
@ -1134,6 +1134,7 @@ func (l *label) summarize() SummaryLabel {
|
||||||
Color: l.Color,
|
Color: l.Color,
|
||||||
Description: l.Description,
|
Description: l.Description,
|
||||||
},
|
},
|
||||||
|
EnvReferences: l.identity.summarizeReferences(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -189,46 +189,38 @@ spec:
|
||||||
labels := pkg.Summary().Labels
|
labels := pkg.Summary().Labels
|
||||||
require.Len(t, labels, 3)
|
require.Len(t, labels, 3)
|
||||||
|
|
||||||
expectedLabel := SummaryLabel{
|
expectedLabel := sumLabelGen("label-1", "label-1", "#FFFFFF", "label 1 description")
|
||||||
PkgName: "label-1",
|
|
||||||
Name: "label-1",
|
|
||||||
Properties: struct {
|
|
||||||
Color string `json:"color"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
}{
|
|
||||||
Color: "#FFFFFF",
|
|
||||||
Description: "label 1 description",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
assert.Equal(t, expectedLabel, labels[0])
|
assert.Equal(t, expectedLabel, labels[0])
|
||||||
|
|
||||||
expectedLabel = SummaryLabel{
|
expectedLabel = sumLabelGen("label-2", "label-2", "#000000", "label 2 description")
|
||||||
PkgName: "label-2",
|
|
||||||
Name: "label-2",
|
|
||||||
Properties: struct {
|
|
||||||
Color string `json:"color"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
}{
|
|
||||||
Color: "#000000",
|
|
||||||
Description: "label 2 description",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
assert.Equal(t, expectedLabel, labels[1])
|
assert.Equal(t, expectedLabel, labels[1])
|
||||||
|
|
||||||
expectedLabel = SummaryLabel{
|
expectedLabel = sumLabelGen("label-3", "display name", "", "label 3 description")
|
||||||
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])
|
assert.Equal(t, expectedLabel, labels[2])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("with env refs should be valid", func(t *testing.T) {
|
||||||
|
testfileRunner(t, "testdata/label_ref.yml", func(t *testing.T, pkg *Pkg) {
|
||||||
|
actual := pkg.Summary().Labels
|
||||||
|
require.Len(t, actual, 1)
|
||||||
|
|
||||||
|
expected := sumLabelGen("env-meta-name", "env-spec-name", "", "",
|
||||||
|
SummaryReference{
|
||||||
|
Field: "metadata.name",
|
||||||
|
EnvRefKey: "meta-name",
|
||||||
|
DefaultValue: "env-meta-name",
|
||||||
|
},
|
||||||
|
SummaryReference{
|
||||||
|
Field: "spec.name",
|
||||||
|
EnvRefKey: "spec-name",
|
||||||
|
DefaultValue: "env-spec-name",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert.Contains(t, actual, expected)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("with missing label name should error", func(t *testing.T) {
|
t.Run("with missing label name should error", func(t *testing.T) {
|
||||||
tests := []testPkgResourceError{
|
tests := []testPkgResourceError{
|
||||||
{
|
{
|
||||||
|
@ -3659,14 +3651,7 @@ spec:
|
||||||
sum := pkg.Summary()
|
sum := pkg.Summary()
|
||||||
|
|
||||||
labels := []SummaryLabel{
|
labels := []SummaryLabel{
|
||||||
{
|
sumLabelGen("label-1", "label-1", "#eee888", "desc_1"),
|
||||||
PkgName: "label-1",
|
|
||||||
Name: "label-1",
|
|
||||||
Properties: struct {
|
|
||||||
Color string `json:"color"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
}{Color: "#eee888", Description: "desc_1"},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
assert.Equal(t, labels, sum.Labels)
|
assert.Equal(t, labels, sum.Labels)
|
||||||
|
|
||||||
|
@ -4142,6 +4127,24 @@ func testfileRunner(t *testing.T, path string, testFn func(t *testing.T, pkg *Pk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sumLabelGen(pkgName, name, color, desc string, envRefs ...SummaryReference) SummaryLabel {
|
||||||
|
if envRefs == nil {
|
||||||
|
envRefs = make([]SummaryReference, 0)
|
||||||
|
}
|
||||||
|
return SummaryLabel{
|
||||||
|
PkgName: pkgName,
|
||||||
|
Name: name,
|
||||||
|
Properties: struct {
|
||||||
|
Color string `json:"color"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
}{
|
||||||
|
Color: color,
|
||||||
|
Description: desc,
|
||||||
|
},
|
||||||
|
EnvReferences: envRefs,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func strPtr(s string) *string {
|
func strPtr(s string) *string {
|
||||||
return &s
|
return &s
|
||||||
}
|
}
|
||||||
|
|
|
@ -678,33 +678,15 @@ func TestService(t *testing.T) {
|
||||||
sum := impact.Summary
|
sum := impact.Summary
|
||||||
require.Len(t, sum.Labels, 3)
|
require.Len(t, sum.Labels, 3)
|
||||||
|
|
||||||
assert.Contains(t, sum.Labels, SummaryLabel{
|
expectedLabel := sumLabelGen("label-1", "label-1", "#FFFFFF", "label 1 description")
|
||||||
ID: 1,
|
expectedLabel.ID = 1
|
||||||
OrgID: SafeID(orgID),
|
expectedLabel.OrgID = SafeID(orgID)
|
||||||
PkgName: "label-1",
|
assert.Contains(t, sum.Labels, expectedLabel)
|
||||||
Name: "label-1",
|
|
||||||
Properties: struct {
|
|
||||||
Color string `json:"color"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
}{
|
|
||||||
Color: "#FFFFFF",
|
|
||||||
Description: "label 1 description",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
assert.Contains(t, sum.Labels, SummaryLabel{
|
expectedLabel = sumLabelGen("label-2", "label-2", "#000000", "label 2 description")
|
||||||
ID: 2,
|
expectedLabel.ID = 2
|
||||||
OrgID: SafeID(orgID),
|
expectedLabel.OrgID = SafeID(orgID)
|
||||||
PkgName: "label-2",
|
assert.Contains(t, sum.Labels, expectedLabel)
|
||||||
Name: "label-2",
|
|
||||||
Properties: struct {
|
|
||||||
Color string `json:"color"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
}{
|
|
||||||
Color: "#000000",
|
|
||||||
Description: "label 2 description",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -736,7 +718,6 @@ func TestService(t *testing.T) {
|
||||||
|
|
||||||
stubExisting := func(name string, id influxdb.ID) *influxdb.Label {
|
stubExisting := func(name string, id influxdb.ID) *influxdb.Label {
|
||||||
pkgLabel := pkg.mLabels[name]
|
pkgLabel := pkg.mLabels[name]
|
||||||
fmt.Println(name, pkgLabel)
|
|
||||||
return &influxdb.Label{
|
return &influxdb.Label{
|
||||||
// makes all pkg changes same as they are on the existing
|
// makes all pkg changes same as they are on the existing
|
||||||
ID: id,
|
ID: id,
|
||||||
|
@ -785,33 +766,15 @@ func TestService(t *testing.T) {
|
||||||
sum := impact.Summary
|
sum := impact.Summary
|
||||||
require.Len(t, sum.Labels, 3)
|
require.Len(t, sum.Labels, 3)
|
||||||
|
|
||||||
assert.Contains(t, sum.Labels, SummaryLabel{
|
expectedLabel := sumLabelGen("label-1", "label-1", "#FFFFFF", "label 1 description")
|
||||||
ID: 1,
|
expectedLabel.ID = 1
|
||||||
OrgID: SafeID(orgID),
|
expectedLabel.OrgID = SafeID(orgID)
|
||||||
PkgName: "label-1",
|
assert.Contains(t, sum.Labels, expectedLabel)
|
||||||
Name: "label-1",
|
|
||||||
Properties: struct {
|
|
||||||
Color string `json:"color"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
}{
|
|
||||||
Color: "#FFFFFF",
|
|
||||||
Description: "label 1 description",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
assert.Contains(t, sum.Labels, SummaryLabel{
|
expectedLabel = sumLabelGen("label-2", "label-2", "#000000", "label 2 description")
|
||||||
ID: 2,
|
expectedLabel.ID = 2
|
||||||
OrgID: SafeID(orgID),
|
expectedLabel.OrgID = SafeID(orgID)
|
||||||
PkgName: "label-2",
|
assert.Contains(t, sum.Labels, expectedLabel)
|
||||||
Name: "label-2",
|
|
||||||
Properties: struct {
|
|
||||||
Color string `json:"color"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
}{
|
|
||||||
Color: "#000000",
|
|
||||||
Description: "label 2 description",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
assert.Equal(t, 1, fakeLabelSVC.CreateLabelCalls.Count()) // only called for second label
|
assert.Equal(t, 1, fakeLabelSVC.CreateLabelCalls.Count()) // only called for second label
|
||||||
})
|
})
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
apiVersion: influxdata.com/v2alpha1
|
||||||
|
kind: Label
|
||||||
|
metadata:
|
||||||
|
name:
|
||||||
|
envRef:
|
||||||
|
key: meta-name
|
||||||
|
spec:
|
||||||
|
name:
|
||||||
|
envRef:
|
||||||
|
key: spec-name
|
Loading…
Reference in New Issue