(t *testing.T)
| 356 | } |
| 357 | |
| 358 | func 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 | |
| 392 | func TestApplyTokenAuth(t *testing.T) { |
| 393 | r := &SourceRepositoryReconciler{} |
nothing calls this directly
no test coverage detected