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

Function TestCloneRepo

operator/controllers/source_controller_test.go:358–390  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

356}
357
358func TestCloneRepo(t *testing.T) {
359 r := &SourceRepositoryReconciler{}
360 ctx := context.Background()
361
362 t.Run("rejects invalid url before running git", func(t *testing.T) {
363 err := r.cloneRepo(ctx, newSourceRepo("-oProxyCommand=evil", "main"), filepath.Join(t.TempDir(), "clone"), nil)
364 if err == nil || !strings.Contains(err.Error(), "unsupported repository URL") {
365 t.Fatalf("expected URL validation error, got %v", err)
366 }
367 })
368
369 t.Run("surfaces parent dir creation failure", func(t *testing.T) {
370 blocker := filepath.Join(t.TempDir(), "blocker")
371 writeTestFile(t, blocker, "not a directory\n")
372 err := r.cloneRepo(ctx, newSourceRepo("https://example.com/repo.git", "main"),
373 filepath.Join(blocker, "sub", "clone"), nil)
374 if err == nil || !strings.Contains(err.Error(), "creating clone parent dir") {
375 t.Fatalf("expected mkdir error, got %v", err)
376 }
377 })
378
379 t.Run("surfaces git clone failure", func(t *testing.T) {
380 cloneCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
381 defer cancel()
382 // Port 1 is reserved and never listening: the clone fails fast
383 // with a connection error instead of touching the network.
384 err := r.cloneRepo(cloneCtx, newSourceRepo("https://127.0.0.1:1/repo.git", "main"),
385 filepath.Join(t.TempDir(), "clone"), nil)
386 if err == nil || !strings.Contains(err.Error(), "git clone failed") {
387 t.Fatalf("expected git clone error, got %v", err)
388 }
389 })
390}
391
392func TestApplyTokenAuth(t *testing.T) {
393 r := &SourceRepositoryReconciler{}

Callers

nothing calls this directly

Calls 5

cloneRepoMethod · 0.95
newSourceRepoFunction · 0.85
writeTestFileFunction · 0.70
RunMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected