mirror of
https://github.com/imjasonh/git-k8s
synced 2026-07-17 06:23:00 +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
69
pkg/apis/git/v1alpha1/defaults_test.go
Normal file
69
pkg/apis/git/v1alpha1/defaults_test.go
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
package v1alpha1
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSetDefaults_GitRepository(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
repo *GitRepository
|
||||
wantBranch string
|
||||
}{
|
||||
{
|
||||
name: "empty default branch gets set to main",
|
||||
repo: &GitRepository{},
|
||||
wantBranch: "main",
|
||||
},
|
||||
{
|
||||
name: "explicit default branch is preserved",
|
||||
repo: &GitRepository{
|
||||
Spec: GitRepositorySpec{
|
||||
DefaultBranch: "develop",
|
||||
},
|
||||
},
|
||||
wantBranch: "develop",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
SetDefaults_GitRepository(tt.repo)
|
||||
if got := tt.repo.Spec.DefaultBranch; got != tt.wantBranch {
|
||||
t.Errorf("DefaultBranch = %q, want %q", got, tt.wantBranch)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaults_GitPushTransaction(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
txn *GitPushTransaction
|
||||
wantPhase TransactionPhase
|
||||
}{
|
||||
{
|
||||
name: "empty phase gets set to Pending",
|
||||
txn: &GitPushTransaction{},
|
||||
wantPhase: TransactionPhasePending,
|
||||
},
|
||||
{
|
||||
name: "existing phase is preserved",
|
||||
txn: &GitPushTransaction{
|
||||
Status: GitPushTransactionStatus{
|
||||
Phase: TransactionPhaseSucceeded,
|
||||
},
|
||||
},
|
||||
wantPhase: TransactionPhaseSucceeded,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
SetDefaults_GitPushTransaction(tt.txn)
|
||||
if got := tt.txn.Status.Phase; got != tt.wantPhase {
|
||||
t.Errorf("Phase = %q, want %q", got, tt.wantPhase)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue