1
0
Fork 0
mirror of https://github.com/imjasonh/git-k8s synced 2026-07-12 00:19:47 +00:00
git-k8s/pkg/reconciler/internal/key_test.go
Claude b122fb297f
Refactor reconcilers to use Knative ReconcileKind pattern
Move the key-splitting, resource-fetching, and not-found handling into a
generic internal.NewReconciler wrapper so that each reconciler only
implements ReconcileKind(ctx, *TypedResource) — matching the Knative
generated reconciler convention. The controller setup wraps the
reconciler with internal.NewReconciler, which bridges Reconcile(ctx, key)
to ReconcileKind(ctx, *T).

This removes duplicated boilerplate from all three reconcilers (push,
sync, resolver), eliminates their Reconcile/LeaderAware methods, and
makes splitKey an unexported implementation detail.

https://claude.ai/code/session_01Eu3LyxX3G1KCcw4aDzmHvp
2026-02-28 05:06:22 +00:00

51 lines
879 B
Go

package internal
import (
"testing"
)
func TestSplitKey(t *testing.T) {
tests := []struct {
key string
wantNS string
wantName string
}{
{
key: "default/my-resource",
wantNS: "default",
wantName: "my-resource",
},
{
key: "kube-system/controller",
wantNS: "kube-system",
wantName: "controller",
},
{
key: "no-namespace",
wantNS: "",
wantName: "no-namespace",
},
{
key: "ns/name/with/slashes",
wantNS: "ns",
wantName: "name/with/slashes",
},
{
key: "",
wantNS: "",
wantName: "",
},
}
for _, tt := range tests {
t.Run(tt.key, func(t *testing.T) {
ns, name := splitKey(tt.key)
if ns != tt.wantNS {
t.Errorf("namespace = %q, want %q", ns, tt.wantNS)
}
if name != tt.wantName {
t.Errorf("name = %q, want %q", name, tt.wantName)
}
})
}
}