MCPcopy Index your code
hub / github.com/jetify-com/devbox / TestFindError

Function TestFindError

internal/devconfig/config_test.go:191–282  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

189}
190
191func TestFindError(t *testing.T) {
192 t.Run("NotExist", func(t *testing.T) {
193 root, _, _ := mkNestedDirs(t)
194 if _, err := Init(root); err != nil {
195 t.Fatalf("Init(%q) error: %v", root, err)
196 }
197
198 path := filepath.Join(root, "notafile.json")
199 cfg, err := Find(path)
200 if err == nil {
201 t.Fatalf("Find(%q) = %q, want error", path, cfg.Root.AbsRootPath)
202 }
203 if !errors.Is(err, fs.ErrNotExist) {
204 t.Error("errors.Is(err, fs.ErrNotExist) = false, want true")
205 }
206 if errors.Is(err, ErrNotFound) {
207 t.Error("errors.Is(err, ErrNotFound) = true, want false")
208 }
209 })
210 t.Run("NotFound", func(t *testing.T) {
211 root, child, _ := mkNestedDirs(t)
212 if _, err := Init(child); err != nil {
213 t.Fatalf("Init(%q) error: %v", root, err)
214 }
215
216 cfg, err := Find(root)
217 if err == nil {
218 t.Fatalf("Find(%q) = %q, want error", root, cfg.Root.AbsRootPath)
219 }
220 if !errors.Is(err, ErrNotFound) {
221 t.Error("errors.Is(err, ErrNotFound) = false, want true")
222 }
223 })
224 t.Run("Permissions", func(t *testing.T) {
225 root, child, _ := mkNestedDirs(t)
226 if _, err := Init(root); err != nil {
227 t.Fatalf("Init(%q) error: %v", root, err)
228 }
229 if _, err := Init(child); err != nil {
230 t.Fatalf("Init(%q) error: %v", child, err)
231 }
232 path := filepath.Join(child, "devbox.json")
233 if err := os.Chmod(path, 0o000); err != nil {
234 t.Fatalf("os.Chmod(%q, 0o000) error: %v", path, err)
235 }
236 t.Cleanup(func() { _ = os.Chmod(path, 0o666) })
237
238 cfg, err := Find(child)
239 if err == nil {
240 t.Fatalf("Find(%q) = %q, want error", child, cfg.Root.AbsRootPath)
241 }
242 if !errors.Is(err, fs.ErrPermission) {
243 t.Error("errors.Is(err, fs.ErrPermission) = false, want true")
244 }
245 })
246 t.Run("ExactFileBadSyntax", func(t *testing.T) {
247 root, _, _ := mkNestedDirs(t)
248

Callers

nothing calls this directly

Calls 6

mkNestedDirsFunction · 0.85
InitFunction · 0.85
FindFunction · 0.85
IsMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected