mirror of
https://github.com/imjasonh/git-k8s
synced 2026-07-18 06:55:48 +00:00
Fix multiple code review issues: dedup splitKey, fix merge bug, remove dead code
- Extract triplicated splitKey into shared pkg/reconciler/internal package using strings.Cut and removing the unnecessary error return - Fix resolver merge bug: attemptMerge was using treeA.Hash as the merge commit tree, silently dropping all of branch B's changes. Now builds a proper merged tree that applies B's non-conflicting changes onto A's tree - Replace hand-rolled nestedFieldNoCopy/unstructuredNestedStringMap with k8s.io/apimachinery's unstructured.NestedStringMap stdlib equivalent - Hoist branch listing out of per-refspec loop in updateBranches to avoid redundant API calls - Add not-found handling in all three reconcilers so deleted resources don't cause infinite requeue loops - Fix client.Get() to use checked type assertion with a clear panic message instead of an opaque nil-pointer dereference - Remove dead code: unused addDefaultingFuncs wrapper, unused context injection in push controller setup https://claude.ai/code/session_01634JRpHEoM9FzuBjZ7qHcY
This commit is contained in:
parent
9d5cd83734
commit
0cb9e4aa1d
11 changed files with 166 additions and 409 deletions
|
|
@ -1,54 +1 @@
|
|||
package sync
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSplitKey(t *testing.T) {
|
||||
tests := []struct {
|
||||
key string
|
||||
wantNS string
|
||||
wantName string
|
||||
}{
|
||||
{
|
||||
key: "default/my-sync",
|
||||
wantNS: "default",
|
||||
wantName: "my-sync",
|
||||
},
|
||||
{
|
||||
key: "git-system/sync-controller",
|
||||
wantNS: "git-system",
|
||||
wantName: "sync-controller",
|
||||
},
|
||||
{
|
||||
key: "just-name",
|
||||
wantNS: "",
|
||||
wantName: "just-name",
|
||||
},
|
||||
{
|
||||
key: "",
|
||||
wantNS: "",
|
||||
wantName: "",
|
||||
},
|
||||
{
|
||||
key: "ns/name/extra",
|
||||
wantNS: "ns",
|
||||
wantName: "name/extra",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.key, func(t *testing.T) {
|
||||
ns, name, err := splitKey(tt.key)
|
||||
if err != nil {
|
||||
t.Fatalf("splitKey(%q) error = %v", tt.key, err)
|
||||
}
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue