MCPcopy Create free account
hub / github.com/diillson/chatcli / TestResolveAuth_SSHKey

Function TestResolveAuth_SSHKey

operator/controllers/source_controller_test.go:417–449  ·  view source on GitHub ↗

--- resolveAuth ---

(t *testing.T)

Source from the content-addressed store, hash-verified

415// --- resolveAuth ---
416
417func 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

Callers

nothing calls this directly

Calls 6

resolveAuthMethod · 0.95
newSchemeFunction · 0.85
newSourceRepoFunction · 0.85
ErrorfMethod · 0.80
RemoveMethod · 0.65
CleanupMethod · 0.45

Tested by

no test coverage detected