Files
Oliver BählerandCopilot Autofix powered by AI 4b07463705 fix: metric recorders for all conditionals (#1998)
* fix(controller): decode old object for delete requests

Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>

* chore: modernize golang

Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>

* chore: modernize golang

Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>

* chore: modernize golang

Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>

* fix: preserve ca-bundles injected from external providers

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>

* feat: add metadata enforcement

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>

* feat: add metadata enforcement

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>

* fix: add resourcepoolclaim validation

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>

* fix: add resourcepoolclaim validation

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>

* fix: add resourcepoolclaim validation

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix: add resourcepoolclaim validation

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>

* fix: wave of fixes

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>

* fix: wave of fixes

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>

* fix: wave of fixes

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>

* fix: wave of fixes

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>

* fix: wave of fixes

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>

* fix: wave of fixes

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>

---------

Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-07-03 14:38:41 +02:00

84 lines
1.9 KiB
Go

// Copyright 2020-2026 Project Capsule Authors
// SPDX-License-Identifier: Apache-2.0
package tenantresource
import (
"reflect"
"testing"
capsulev1beta2 "github.com/projectcapsule/capsule/api/v1beta2"
"github.com/projectcapsule/capsule/pkg/api/meta"
"github.com/projectcapsule/capsule/pkg/runtime/gvk"
)
func TestCreatedItemsIndexersUseAdmissionKeyForClusterScopedItems(t *testing.T) {
t.Parallel()
item := meta.ObjectReferenceStatus{
ResourceID: gvk.ResourceID{
Group: "rbac.authorization.k8s.io",
Version: "v1",
Kind: "ClusterRole",
Namespace: "tenant-a",
Name: "example",
},
ObjectReferenceStatusCondition: meta.ObjectReferenceStatusCondition{
Created: true,
ClusterScoped: true,
},
}
want := []string{
gvk.ResourceID{
Group: "rbac.authorization.k8s.io",
Version: "v1",
Kind: "ClusterRole",
Name: "example",
}.GetGVKKey(""),
}
t.Run("global", func(t *testing.T) {
t.Parallel()
idx := GlobalCreatedItems{}
obj := &capsulev1beta2.GlobalTenantResource{}
obj.Status.ProcessedItems = meta.ProcessedItems{item}
if got := idx.Func()(obj); !reflect.DeepEqual(got, want) {
t.Fatalf("unexpected keys\nwant=%#v\ngot =%#v", want, got)
}
})
t.Run("namespaced", func(t *testing.T) {
t.Parallel()
idx := NamespacedCreatedItems{}
obj := &capsulev1beta2.TenantResource{}
obj.Status.ProcessedItems = meta.ProcessedItems{item}
if got := idx.Func()(obj); !reflect.DeepEqual(got, want) {
t.Fatalf("unexpected keys\nwant=%#v\ngot =%#v", want, got)
}
})
}
func TestProcessedItemKeyKeepsNamespaceForNamespacedItems(t *testing.T) {
t.Parallel()
item := meta.ObjectReferenceStatus{
ResourceID: gvk.ResourceID{
Version: "v1",
Kind: "Secret",
Namespace: "tenant-a",
Name: "example",
},
}
want := item.GetGVKKey("")
if got := processedItemKey(item); got != want {
t.Fatalf("unexpected key: want %q, got %q", want, got)
}
}