MCPcopy Index your code
hub / github.com/coder/coder / TestSubscribeNestedGitRepos

Function TestSubscribeNestedGitRepos

agent/agentgit/agentgit_test.go:439–477  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

437}
438
439func TestSubscribeNestedGitRepos(t *testing.T) {
440 t.Parallel()
441
442 // Create an outer repo.
443 outerDir := initTestRepo(t)
444
445 // Create an inner repo nested inside the outer one.
446 innerDir := filepath.Join(outerDir, "subproject")
447 require.NoError(t, os.MkdirAll(innerDir, 0o700))
448
449 gitCmd(t, innerDir, "init")
450 gitCmd(t, innerDir, "config", "user.name", "Test")
451 gitCmd(t, innerDir, "config", "user.email", "test@test.com")
452
453 // Commit a file in the inner repo so it has HEAD.
454 innerFile := filepath.Join(innerDir, "inner.go")
455 require.NoError(t, os.WriteFile(innerFile, []byte("package inner\n"), 0o600))
456 gitCmd(t, innerDir, "add", "inner.go")
457 gitCmd(t, innerDir, "commit", "-m", "inner commit")
458
459 // Now create a dirty file in the inner repo.
460 dirtyFile := filepath.Join(innerDir, "dirty.go")
461 require.NoError(t, os.WriteFile(dirtyFile, []byte("package inner\n"), 0o600))
462
463 logger := slogtest.Make(t, nil)
464 h := agentgit.NewHandler(logger)
465
466 // Subscribe with the path inside the inner repo.
467 added := h.Subscribe([]string{dirtyFile})
468 require.True(t, added)
469
470 msg := h.Scan(context.Background())
471 require.NotNil(t, msg)
472 require.Len(t, msg.Repositories, 1, "should track only one repo")
473
474 // The tracked repo should be the inner repo, not the outer one.
475 require.Equal(t, innerDir, msg.Repositories[0].RepoRoot,
476 "should track the inner (nearest) repo, not the outer one")
477}
478
479func TestScanDeletedRepoEmitsRemoved(t *testing.T) {
480 t.Parallel()

Callers

nothing calls this directly

Calls 9

SubscribeMethod · 0.95
ScanMethod · 0.95
NewHandlerFunction · 0.92
initTestRepoFunction · 0.85
gitCmdFunction · 0.85
MkdirAllMethod · 0.80
WriteFileMethod · 0.65
LenMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected