(t *testing.T)
| 120 | } |
| 121 | |
| 122 | func 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 | |
| 150 | func TestScanRespectsGitignore(t *testing.T) { |
| 151 | t.Parallel() |
nothing calls this directly
no test coverage detected