|
@@ -7,9 +7,13 @@ import (
|
|
|
|
|
|
|
|
func TestGenerateKey(t *testing.T) {
|
|
func TestGenerateKey(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
+ customOwnerLabelConfig := NewLabelConfig()
|
|
|
|
|
+ customOwnerLabelConfig.OwnerLabel = "example_com_project"
|
|
|
|
|
+
|
|
|
cases := map[string]struct {
|
|
cases := map[string]struct {
|
|
|
aggregate []string
|
|
aggregate []string
|
|
|
allocationProps *AllocationProperties
|
|
allocationProps *AllocationProperties
|
|
|
|
|
+ labelConfig *LabelConfig
|
|
|
expected string
|
|
expected string
|
|
|
}{
|
|
}{
|
|
|
"aggregate by owner without owner labels": {
|
|
"aggregate by owner without owner labels": {
|
|
@@ -75,6 +79,15 @@ func TestGenerateKey(t *testing.T) {
|
|
|
},
|
|
},
|
|
|
expected: "product-label/owner-label",
|
|
expected: "product-label/owner-label",
|
|
|
},
|
|
},
|
|
|
|
|
+ "user test": {
|
|
|
|
|
+ aggregate: []string{"owner"},
|
|
|
|
|
+ allocationProps: &AllocationProperties{
|
|
|
|
|
+ Labels: map[string]string{"app_kubernetes_io_name": "x-mongo", "example_com_service_owner": "x", "component": "primary", "controller_revision_hash": "x-mongo-primary-x", "kubernetes_io_metadata_name": "app-microservices", "name": "app-microservices", "statefulset_kubernetes_io_pod_name": "x-mongo-primary-0"},
|
|
|
|
|
+ Annotations: map[string]string{"example_com_project": "redacted"},
|
|
|
|
|
+ },
|
|
|
|
|
+ labelConfig: customOwnerLabelConfig,
|
|
|
|
|
+ expected: "redacted",
|
|
|
|
|
+ },
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range cases {
|
|
for name, tc := range cases {
|
|
@@ -82,6 +95,10 @@ func TestGenerateKey(t *testing.T) {
|
|
|
|
|
|
|
|
lc := NewLabelConfig()
|
|
lc := NewLabelConfig()
|
|
|
|
|
|
|
|
|
|
+ if tc.labelConfig != nil {
|
|
|
|
|
+ lc = tc.labelConfig
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
result := tc.allocationProps.GenerateKey(tc.aggregate, lc)
|
|
result := tc.allocationProps.GenerateKey(tc.aggregate, lc)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(result, tc.expected) {
|
|
if !reflect.DeepEqual(result, tc.expected) {
|