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

Function TestScanReturnsRepoChanges

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

Source from the content-addressed store, hash-verified

120}
121
122func TestScanReturnsRepoChanges(t *testing.T) {
123 t.Parallel()
124
125 repoDir := initTestRepo(t)
126 logger := slogtest.Make(t, nil)
127
128 h := agentgit.NewHandler(logger)
129
130 // Create a dirty file.
131 require.NoError(t, os.WriteFile(filepath.Join(repoDir, "new.go"), []byte("package main\n"), 0o600))
132
133 h.Subscribe([]string{filepath.Join(repoDir, "new.go")})
134
135 ctx := context.Background()
136 msg := h.Scan(ctx)
137 require.NotNil(t, msg)
138 require.Equal(t, codersdk.WorkspaceAgentGitServerMessageTypeChanges, msg.Type)
139 require.Len(t, msg.Repositories, 1)
140
141 repo := msg.Repositories[0]
142 require.Equal(t, repoDir, repo.RepoRoot)
143 require.NotEmpty(t, repo.Branch)
144 require.NotEmpty(t, repo.UnifiedDiff)
145
146 // Verify the new file appears in the unified diff.
147 require.Contains(t, repo.UnifiedDiff, "new.go")
148}
149
150func TestScanRespectsGitignore(t *testing.T) {
151 t.Parallel()

Callers

nothing calls this directly

Calls 9

SubscribeMethod · 0.95
ScanMethod · 0.95
NewHandlerFunction · 0.92
initTestRepoFunction · 0.85
NotEmptyMethod · 0.80
WriteFileMethod · 0.65
EqualMethod · 0.45
LenMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected