--- resolveAuth ---
(t *testing.T)
| 415 | // --- resolveAuth --- |
| 416 | |
| 417 | func TestResolveAuth_SSHKey(t *testing.T) { |
| 418 | secret := &corev1.Secret{ |
| 419 | ObjectMeta: metav1.ObjectMeta{Name: "git-creds", Namespace: "default"}, |
| 420 | Data: map[string][]byte{"ssh-key": []byte("fake-key-material")}, |
| 421 | } |
| 422 | c := fake.NewClientBuilder().WithScheme(newScheme()).WithObjects(secret).Build() |
| 423 | r := &SourceRepositoryReconciler{Client: c} |
| 424 | |
| 425 | repo := newSourceRepo("git@github.com:org/repo.git", "main") |
| 426 | repo.Name = "ssh-auth-test-repo" |
| 427 | repo.Spec.AuthType = platformv1alpha1.SourceRepoAuthSSH |
| 428 | repo.Spec.SecretRef = "git-creds" |
| 429 | keyFile := filepath.Join(sourceRepoBaseDir, ".ssh", repo.Name) |
| 430 | t.Cleanup(func() { _ = os.Remove(keyFile) }) |
| 431 | |
| 432 | env, err := r.resolveAuth(context.Background(), repo) |
| 433 | if err != nil { |
| 434 | t.Fatalf("resolveAuth: %v", err) |
| 435 | } |
| 436 | found := false |
| 437 | for _, e := range env { |
| 438 | if strings.HasPrefix(e, "GIT_SSH_COMMAND=") && strings.Contains(e, keyFile) { |
| 439 | found = true |
| 440 | } |
| 441 | } |
| 442 | if !found { |
| 443 | t.Errorf("GIT_SSH_COMMAND with key file not present in env: %v", env) |
| 444 | } |
| 445 | data, err := os.ReadFile(keyFile) |
| 446 | if err != nil || string(data) != "fake-key-material" { |
| 447 | t.Errorf("key file not written correctly: %v / %q", err, data) |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | // --- Reconcile cleanup path --- |
| 452 |
nothing calls this directly
no test coverage detected