mirror of
https://github.com/imjasonh/git-k8s
synced 2026-07-15 18:05:37 +00:00
Add unit tests and GitRepoSync e2e test
Add unit tests for all packages that previously had zero test coverage: - pkg/apis/git/v1alpha1: defaults, deepcopy, scheme registration, constants - pkg/client: toUnstructured/fromUnstructured round-trips, context injection - pkg/reconciler/push: splitKey, nestedFieldNoCopy, unstructuredNestedStringMap, base64 decoding - pkg/reconciler/sync: splitKey - pkg/reconciler/resolver: splitKey, changeName Add e2e test exercising the sync controller: - Creates second Gitea repo and GitRepository CR - Creates GitBranch CRs with headCommit set via status subresource patch - Creates GitRepoSync CR and verifies the sync controller processes it https://claude.ai/code/session_01QfFzqKQUsxxBsiZUhuJ3pG
This commit is contained in:
parent
3bbfe8b4d4
commit
4e4f5f923f
7 changed files with 1116 additions and 1 deletions
54
pkg/reconciler/sync/sync_test.go
Normal file
54
pkg/reconciler/sync/sync_test.go
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
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