(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func TestListPluginCandidates(t *testing.T) { |
| 18 | // Populate a selection of directories with various shadowed and bogus/obscure plugin candidates. |
| 19 | // For the purposes of this test no contents is required and permissions are irrelevant. |
| 20 | dir := fs.NewDir(t, t.Name(), |
| 21 | fs.WithDir( |
| 22 | "plugins1", |
| 23 | fs.WithFile("docker-plugin1", ""), // This appears in each directory |
| 24 | fs.WithFile("not-a-plugin", ""), // Should be ignored |
| 25 | fs.WithFile("docker-symlinked1", ""), // This and ... |
| 26 | fs.WithSymlink("docker-symlinked2", "docker-symlinked1"), // ... this should both appear |
| 27 | fs.WithDir("ignored1"), // A directory should be ignored |
| 28 | ), |
| 29 | fs.WithDir( |
| 30 | "plugins2", |
| 31 | fs.WithFile("docker-plugin1", ""), |
| 32 | fs.WithFile("also-not-a-plugin", ""), |
| 33 | fs.WithFile("docker-hardlink1", ""), // This and ... |
| 34 | fs.WithHardlink("docker-hardlink2", "docker-hardlink1"), // ... this should both appear |
| 35 | fs.WithDir("ignored2"), |
| 36 | ), |
| 37 | fs.WithDir( |
| 38 | "plugins3-target", // Will be referenced as a symlink from below |
| 39 | fs.WithFile("docker-plugin1", ""), |
| 40 | fs.WithDir("ignored3"), |
| 41 | fs.WithSymlink("docker-brokensymlink", "broken"), // A broken symlink is ignored |
| 42 | fs.WithFile("non-plugin-symlinked", ""), // This shouldn't appear, but ... |
| 43 | fs.WithSymlink("docker-symlinked", "non-plugin-symlinked"), // ... this link to it should. |
| 44 | ), |
| 45 | fs.WithSymlink("plugins3", "plugins3-target"), |
| 46 | fs.WithFile("/plugins4", ""), |
| 47 | fs.WithSymlink("plugins5", "plugins5-nonexistent-target"), |
| 48 | ) |
| 49 | defer dir.Remove() |
| 50 | |
| 51 | dirs := make([]string, 0, 6) |
| 52 | for _, d := range []string{"plugins1", "nonexistent", "plugins2", "plugins3", "plugins4", "plugins5"} { |
| 53 | dirs = append(dirs, dir.Join(d)) |
| 54 | } |
| 55 | |
| 56 | candidates := listPluginCandidates(dirs) |
| 57 | exp := map[string][]string{ |
| 58 | "plugin1": { |
| 59 | dir.Join("plugins1", "docker-plugin1"), |
| 60 | dir.Join("plugins2", "docker-plugin1"), |
| 61 | dir.Join("plugins3", "docker-plugin1"), |
| 62 | }, |
| 63 | "symlinked1": { |
| 64 | dir.Join("plugins1", "docker-symlinked1"), |
| 65 | }, |
| 66 | "symlinked2": { |
| 67 | dir.Join("plugins1", "docker-symlinked2"), |
| 68 | }, |
| 69 | "hardlink1": { |
| 70 | dir.Join("plugins2", "docker-hardlink1"), |
| 71 | }, |
| 72 | "hardlink2": { |
| 73 | dir.Join("plugins2", "docker-hardlink2"), |
| 74 | }, |
nothing calls this directly
no test coverage detected
searching dependent graphs…