| 60 | } |
| 61 | |
| 62 | func TestSearch(t *testing.T) { |
| 63 | t.Parallel() |
| 64 | |
| 65 | wd, err := os.Getwd() |
| 66 | require.NoError(t, err) |
| 67 | |
| 68 | tests := []struct { |
| 69 | name string |
| 70 | entrypoint string |
| 71 | dir string |
| 72 | possibleFilenames []string |
| 73 | expectedEntrypoint string |
| 74 | }{ |
| 75 | { |
| 76 | name: "find foo.txt using relative entrypoint", |
| 77 | entrypoint: "./testdata/foo.txt", |
| 78 | possibleFilenames: []string{"foo.txt"}, |
| 79 | expectedEntrypoint: filepath.Join(wd, "testdata", "foo.txt"), |
| 80 | }, |
| 81 | { |
| 82 | name: "find foo.txt using absolute entrypoint", |
| 83 | entrypoint: filepath.Join(wd, "testdata", "foo.txt"), |
| 84 | possibleFilenames: []string{"foo.txt"}, |
| 85 | expectedEntrypoint: filepath.Join(wd, "testdata", "foo.txt"), |
| 86 | }, |
| 87 | { |
| 88 | name: "find foo.txt using relative dir", |
| 89 | dir: "./testdata", |
| 90 | possibleFilenames: []string{"foo.txt"}, |
| 91 | expectedEntrypoint: filepath.Join(wd, "testdata", "foo.txt"), |
| 92 | }, |
| 93 | { |
| 94 | name: "find foo.txt using absolute dir", |
| 95 | dir: filepath.Join(wd, "testdata"), |
| 96 | possibleFilenames: []string{"foo.txt"}, |
| 97 | expectedEntrypoint: filepath.Join(wd, "testdata", "foo.txt"), |
| 98 | }, |
| 99 | { |
| 100 | name: "find foo.txt using relative dir and relative entrypoint", |
| 101 | entrypoint: "./testdata/foo.txt", |
| 102 | dir: "./testdata/some/other/dir", |
| 103 | possibleFilenames: []string{"foo.txt"}, |
| 104 | expectedEntrypoint: filepath.Join(wd, "testdata", "foo.txt"), |
| 105 | }, |
| 106 | { |
| 107 | name: "find fs.go using no entrypoint or dir", |
| 108 | entrypoint: "", |
| 109 | dir: "", |
| 110 | possibleFilenames: []string{"fs.go"}, |
| 111 | expectedEntrypoint: filepath.Join(wd, "fs.go"), |
| 112 | }, |
| 113 | { |
| 114 | name: "find ../../Taskfile.yml using no entrypoint or dir by walking", |
| 115 | entrypoint: "", |
| 116 | dir: "", |
| 117 | possibleFilenames: []string{"Taskfile.yml"}, |
| 118 | expectedEntrypoint: filepath.Join(wd, "..", "..", "Taskfile.yml"), |
| 119 | }, |