|
15 | 15 | package types |
16 | 16 |
|
17 | 17 | import ( |
| 18 | + "fmt" |
18 | 19 | "reflect" |
19 | 20 | "testing" |
20 | 21 |
|
@@ -248,6 +249,120 @@ func TestConfigValidation(t *testing.T) { |
248 | 249 | }, |
249 | 250 | }, |
250 | 251 | }, |
| 252 | + |
| 253 | + // test 7: file path conflicts with another file path, should error |
| 254 | + { |
| 255 | + in: Config{ |
| 256 | + Storage: Storage{ |
| 257 | + Files: []File{ |
| 258 | + {Node: Node{Path: "/foo/bar"}}, |
| 259 | + {Node: Node{Path: "/foo/bar/baz"}}, |
| 260 | + }, |
| 261 | + }, |
| 262 | + }, |
| 263 | + out: fmt.Errorf("invalid entry at path /foo/bar/baz: %w", errors.ErrMissLabeledDir), |
| 264 | + at: path.New("json", "storage", "files", 1, "path"), |
| 265 | + }, |
| 266 | + // test 8: file path conflicts with link path, should error |
| 267 | + { |
| 268 | + in: Config{ |
| 269 | + Storage: Storage{ |
| 270 | + Files: []File{ |
| 271 | + {Node: Node{Path: "/foo/bar"}}, |
| 272 | + }, |
| 273 | + Links: []Link{ |
| 274 | + {Node: Node{Path: "/foo/bar/baz"}}, |
| 275 | + }, |
| 276 | + }, |
| 277 | + }, |
| 278 | + out: fmt.Errorf("invalid entry at path /foo/bar/baz: %w", errors.ErrMissLabeledDir), |
| 279 | + at: path.New("json", "storage", "links", 0, "path"), |
| 280 | + }, |
| 281 | + |
| 282 | + // test 9: file path conflicts with directory path, should error |
| 283 | + { |
| 284 | + in: Config{ |
| 285 | + Storage: Storage{ |
| 286 | + Files: []File{ |
| 287 | + {Node: Node{Path: "/foo/bar"}}, |
| 288 | + }, |
| 289 | + Directories: []Directory{ |
| 290 | + {Node: Node{Path: "/foo/bar/baz"}}, |
| 291 | + }, |
| 292 | + }, |
| 293 | + }, |
| 294 | + out: fmt.Errorf("invalid entry at path /foo/bar/baz: %w", errors.ErrMissLabeledDir), |
| 295 | + at: path.New("json", "storage", "directories", 0, "path"), |
| 296 | + }, |
| 297 | + |
| 298 | + // test 10: non-conflicting scenarios with same parent directory, should not error |
| 299 | + { |
| 300 | + in: Config{ |
| 301 | + Storage: Storage{ |
| 302 | + Files: []File{ |
| 303 | + {Node: Node{Path: "/foo/bar/baz"}}, |
| 304 | + }, |
| 305 | + Directories: []Directory{ |
| 306 | + {Node: Node{Path: "/foo/bar"}}, |
| 307 | + }, |
| 308 | + }, |
| 309 | + }, |
| 310 | + }, |
| 311 | + // test 11: non-conflicting scenarios with a link, should not error |
| 312 | + { |
| 313 | + in: Config{ |
| 314 | + Storage: Storage{ |
| 315 | + Files: []File{ |
| 316 | + {Node: Node{Path: "/foo/bar"}}, |
| 317 | + }, |
| 318 | + Links: []Link{ |
| 319 | + {Node: Node{Path: "/baz/qux"}}, |
| 320 | + }, |
| 321 | + }, |
| 322 | + }, |
| 323 | + }, |
| 324 | + // test 12: deep path conflict - file conflicts with deeper nested path, should error |
| 325 | + { |
| 326 | + in: Config{ |
| 327 | + Storage: Storage{ |
| 328 | + Files: []File{ |
| 329 | + {Node: Node{Path: "/foo/bar"}}, |
| 330 | + {Node: Node{Path: "/foo/bar/baz/deep/file"}}, |
| 331 | + }, |
| 332 | + }, |
| 333 | + }, |
| 334 | + out: fmt.Errorf("invalid entry at path /foo/bar/baz/deep/file: %w", errors.ErrMissLabeledDir), |
| 335 | + at: path.New("json", "storage", "files", 1, "path"), |
| 336 | + }, |
| 337 | + // test 13: multiple levels with directories, should not error |
| 338 | + { |
| 339 | + in: Config{ |
| 340 | + Storage: Storage{ |
| 341 | + Directories: []Directory{ |
| 342 | + {Node: Node{Path: "/foo"}}, |
| 343 | + {Node: Node{Path: "/foo/bar"}}, |
| 344 | + }, |
| 345 | + Files: []File{ |
| 346 | + {Node: Node{Path: "/foo/bar/baz"}}, |
| 347 | + }, |
| 348 | + }, |
| 349 | + }, |
| 350 | + }, |
| 351 | + // test 14: link conflicts with file parent, should error |
| 352 | + { |
| 353 | + in: Config{ |
| 354 | + Storage: Storage{ |
| 355 | + Links: []Link{ |
| 356 | + {Node: Node{Path: "/foo/bar"}}, |
| 357 | + }, |
| 358 | + Files: []File{ |
| 359 | + {Node: Node{Path: "/foo/bar/child"}}, |
| 360 | + }, |
| 361 | + }, |
| 362 | + }, |
| 363 | + out: fmt.Errorf("invalid entry at path /foo/bar/child: %w", errors.ErrMissLabeledDir), |
| 364 | + at: path.New("json", "storage", "files", 0, "path"), |
| 365 | + }, |
251 | 366 | } |
252 | 367 | for i, test := range tests { |
253 | 368 | r := test.in.Validate(path.New("json")) |
|
0 commit comments