mirror of
https://github.com/imjasonh/git-k8s
synced 2026-07-09 07:06:52 +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
126
.github/workflows/ci.yaml
vendored
126
.github/workflows/ci.yaml
vendored
|
|
@ -306,10 +306,134 @@ jobs:
|
|||
echo ""
|
||||
echo "Branch feature-test verified on git server!"
|
||||
|
||||
# --- GitRepoSync e2e test ---
|
||||
# Create a second repo on Gitea to test sync between two repos.
|
||||
- name: Create second test repository on Gitea
|
||||
run: |
|
||||
kubectl exec -n git-system deploy/gitea -- \
|
||||
curl -sf -X POST http://localhost:3000/api/v1/user/repos \
|
||||
-H 'Content-Type: application/json' \
|
||||
-u testadmin:testpassword123 \
|
||||
-d '{"name":"test-repo-b","auto_init":true,"default_branch":"main"}'
|
||||
echo ""
|
||||
echo "Second test repository created"
|
||||
|
||||
- name: Create second GitRepository CR
|
||||
run: |
|
||||
cat <<'EOF' | kubectl apply -f -
|
||||
apiVersion: git-k8s.imjasonh.com/v1alpha1
|
||||
kind: GitRepository
|
||||
metadata:
|
||||
name: test-repo-b
|
||||
namespace: default
|
||||
spec:
|
||||
url: http://gitea.git-system.svc.cluster.local:3000/testadmin/test-repo-b.git
|
||||
defaultBranch: main
|
||||
auth:
|
||||
secretRef:
|
||||
name: gitea-creds
|
||||
EOF
|
||||
|
||||
- name: Create GitBranch CRs for sync test
|
||||
run: |
|
||||
# Get the head commit from each repo via Gitea API
|
||||
COMMIT_A=$(kubectl exec -n git-system deploy/gitea -- \
|
||||
curl -sf http://localhost:3000/api/v1/repos/testadmin/test-repo/branches/main \
|
||||
-u testadmin:testpassword123 | python3 -c "import sys,json; print(json.load(sys.stdin)['commit']['id'])")
|
||||
echo "Repo A main commit: $COMMIT_A"
|
||||
|
||||
COMMIT_B=$(kubectl exec -n git-system deploy/gitea -- \
|
||||
curl -sf http://localhost:3000/api/v1/repos/testadmin/test-repo-b/branches/main \
|
||||
-u testadmin:testpassword123 | python3 -c "import sys,json; print(json.load(sys.stdin)['commit']['id'])")
|
||||
echo "Repo B main commit: $COMMIT_B"
|
||||
|
||||
# Create GitBranch CRs
|
||||
cat <<'EOF' | kubectl apply -f -
|
||||
apiVersion: git-k8s.imjasonh.com/v1alpha1
|
||||
kind: GitBranch
|
||||
metadata:
|
||||
name: test-repo-main
|
||||
namespace: default
|
||||
spec:
|
||||
repositoryRef: test-repo
|
||||
branchName: main
|
||||
EOF
|
||||
|
||||
cat <<'EOF' | kubectl apply -f -
|
||||
apiVersion: git-k8s.imjasonh.com/v1alpha1
|
||||
kind: GitBranch
|
||||
metadata:
|
||||
name: test-repo-b-main
|
||||
namespace: default
|
||||
spec:
|
||||
repositoryRef: test-repo-b
|
||||
branchName: main
|
||||
EOF
|
||||
|
||||
# Set headCommit via status subresource patch
|
||||
kubectl patch gitbranch test-repo-main -n default \
|
||||
--type=merge --subresource=status \
|
||||
-p "{\"status\":{\"headCommit\":\"${COMMIT_A}\"}}"
|
||||
|
||||
kubectl patch gitbranch test-repo-b-main -n default \
|
||||
--type=merge --subresource=status \
|
||||
-p "{\"status\":{\"headCommit\":\"${COMMIT_B}\"}}"
|
||||
|
||||
kubectl get gitbranches -A -o wide
|
||||
|
||||
- name: Create GitRepoSync
|
||||
run: |
|
||||
cat <<'EOF' | kubectl apply -f -
|
||||
apiVersion: git-k8s.imjasonh.com/v1alpha1
|
||||
kind: GitRepoSync
|
||||
metadata:
|
||||
name: test-sync
|
||||
namespace: default
|
||||
spec:
|
||||
repoA:
|
||||
name: test-repo
|
||||
repoB:
|
||||
name: test-repo-b
|
||||
branchName: main
|
||||
EOF
|
||||
kubectl get gitreposyncs -A
|
||||
|
||||
- name: Wait for sync controller to process
|
||||
run: |
|
||||
echo "Waiting for GitRepoSync to be processed..."
|
||||
for i in $(seq 1 30); do
|
||||
PHASE=$(kubectl get gitreposync test-sync -n default \
|
||||
-o jsonpath='{.status.phase}' 2>/dev/null)
|
||||
MSG=$(kubectl get gitreposync test-sync -n default \
|
||||
-o jsonpath='{.status.message}' 2>/dev/null)
|
||||
echo " attempt ${i}: phase=${PHASE:-empty} message=${MSG:-empty}"
|
||||
if [ -n "$PHASE" ]; then
|
||||
echo "Sync controller has set phase: $PHASE"
|
||||
break
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
|
||||
- name: Verify GitRepoSync status
|
||||
run: |
|
||||
echo "=== GitRepoSync status ==="
|
||||
kubectl get gitreposync test-sync -n default -o yaml
|
||||
|
||||
PHASE=$(kubectl get gitreposync test-sync -n default \
|
||||
-o jsonpath='{.status.phase}')
|
||||
echo "Phase: $PHASE"
|
||||
# The sync controller should have processed this - phase should be set
|
||||
if [ -z "$PHASE" ]; then
|
||||
echo "FAIL: sync controller did not set a phase"
|
||||
kubectl logs -n git-system deploy/sync-controller --tail=100
|
||||
exit 1
|
||||
fi
|
||||
echo "GitRepoSync e2e test passed! Phase: $PHASE"
|
||||
|
||||
- name: Collect diagnostics
|
||||
if: ${{ failure() }}
|
||||
uses: chainguard-dev/actions/kind-diag@main
|
||||
with:
|
||||
artifact-name: kind-logs
|
||||
cluster-resources: nodes,namespaces,crds
|
||||
namespace-resources: pods,deployments,services,gitrepositories,gitbranches,gitpushtransactions
|
||||
namespace-resources: pods,deployments,services,gitrepositories,gitbranches,gitpushtransactions,gitreposyncs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue