mirror of
https://github.com/imjasonh/git-k8s
synced 2026-07-08 06:45:12 +00:00
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
69 lines
1.5 KiB
Go
69 lines
1.5 KiB
Go
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)
|
|
}
|
|
})
|
|
}
|
|
}
|