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

Function TestPullRepo

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

Source from the content-addressed store, hash-verified

319}
320
321func TestPullRepo(t *testing.T) {
322 r := &SourceRepositoryReconciler{}
323 ctx := context.Background()
324
325 t.Run("rejects invalid url before touching git", func(t *testing.T) {
326 err := r.pullRepo(ctx, newSourceRepo("file:///etc", ""), t.TempDir(), nil)
327 if err == nil || !strings.Contains(err.Error(), "repository URL must use") {
328 t.Fatalf("expected URL validation error, got %v", err)
329 }
330 })
331
332 t.Run("fetch failure on a non-repo directory", func(t *testing.T) {
333 err := r.pullRepo(ctx, newSourceRepo("https://example.com/repo.git", "main"), t.TempDir(), nil)
334 if err == nil || !strings.Contains(err.Error(), "git fetch") {
335 t.Fatalf("expected git fetch error, got %v", err)
336 }
337 })
338
339 t.Run("fetches and resets from origin", func(t *testing.T) {
340 origin := newLocalGitRepo(t)
341 work := t.TempDir()
342 runGit(t, work, "-c", "init.defaultBranch=main", "init")
343 // file:// (instead of a bare path) forces the smart transport,
344 // which supports the shallow fetch pullRepo performs.
345 runGit(t, work, "remote", "add", "origin", "file://"+origin)
346
347 // Branch defaulting: empty Spec.Branch must resolve to main.
348 repo := newSourceRepo("https://example.com/repo.git", "")
349 if err := r.pullRepo(ctx, repo, work, nil); err != nil {
350 t.Fatalf("pullRepo: %v", err)
351 }
352 if _, err := os.Stat(filepath.Join(work, "main.go")); err != nil {
353 t.Errorf("expected main.go after reset --hard origin/main: %v", err)
354 }
355 })
356}
357
358func TestCloneRepo(t *testing.T) {
359 r := &SourceRepositoryReconciler{}

Callers

nothing calls this directly

Calls 7

pullRepoMethod · 0.95
newSourceRepoFunction · 0.85
newLocalGitRepoFunction · 0.85
runGitFunction · 0.85
ErrorfMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected