(t *testing.T)
| 149 | } |
| 150 | |
| 151 | func TestCmdWorkdirScanFindsRepos(t *testing.T) { |
| 152 | setupArchiveTestEnv(t) |
| 153 | // Layout: |
| 154 | // scanRoot/ |
| 155 | // a/.git/config (depth 1) |
| 156 | // b/c/.git/config (depth 2) |
| 157 | // d/e/f/.git/config (depth 3) |
| 158 | // g/h/i/j/.git/config (depth 4 — should NOT be found) |
| 159 | scanRoot := t.TempDir() |
| 160 | paths := map[string]int{ |
| 161 | filepath.Join(scanRoot, "a"): 1, |
| 162 | filepath.Join(scanRoot, "b", "c"): 2, |
| 163 | filepath.Join(scanRoot, "d", "e", "f"): 3, |
| 164 | filepath.Join(scanRoot, "g", "h", "i", "j"): 4, |
| 165 | } |
| 166 | for p := range paths { |
| 167 | writeFakeGitConfig(t, p, "git@github.com:x/"+filepath.Base(p)+".git") |
| 168 | } |
| 169 | |
| 170 | found, err := scanForGitRepos(scanRoot, 3) |
| 171 | if err != nil { |
| 172 | t.Fatalf("scan: %v", err) |
| 173 | } |
| 174 | foundSet := map[string]bool{} |
| 175 | for _, p := range found { |
| 176 | foundSet[p] = true |
| 177 | } |
| 178 | for p, depth := range paths { |
| 179 | want := depth <= 3 |
| 180 | got := foundSet[p] |
| 181 | if want != got { |
| 182 | t.Errorf("path %s (depth %d): want found=%v, got found=%v", p, depth, want, got) |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | func TestCmdWorkdirScanNoAdd(t *testing.T) { |
| 188 | setupArchiveTestEnv(t) |
nothing calls this directly
no test coverage detected