|
| 1 | +import { assertEquals } from "@std/assert/equals" |
| 2 | +import { hiddenPathPattern, shouldIncludeFile } from "./upload.ts" |
| 3 | + |
| 4 | +Deno.test("hiddenPathPattern matches hidden files/dirs in subpaths", () => { |
| 5 | + assertEquals(hiddenPathPattern.test("derivatives/.git/config"), true) |
| 6 | + assertEquals(hiddenPathPattern.test("derivatives/.git/annex/objects/xx/yy/key"), true) |
| 7 | + assertEquals(hiddenPathPattern.test("derivatives/.datalad/config"), true) |
| 8 | + assertEquals(hiddenPathPattern.test("a/.git/b"), true) |
| 9 | + assertEquals(hiddenPathPattern.test("sub/.gitignore"), true) |
| 10 | + // Should not match dotfiles at root (no leading slash) |
| 11 | + assertEquals(hiddenPathPattern.test(".git/config"), false) |
| 12 | + assertEquals(hiddenPathPattern.test(".bidsignore"), false) |
| 13 | + // Should not match files that just contain a dot in name |
| 14 | + assertEquals(hiddenPathPattern.test("my.gitconfig"), false) |
| 15 | + assertEquals(hiddenPathPattern.test("file.nii.gz"), false) |
| 16 | +}) |
| 17 | + |
| 18 | +Deno.test("shouldIncludeFile() includes regular dataset files", () => { |
| 19 | + assertEquals(shouldIncludeFile("dataset_description.json"), true) |
| 20 | + assertEquals(shouldIncludeFile("sub-01/anat/sub-01_T1w.nii.gz"), true) |
| 21 | + assertEquals(shouldIncludeFile("derivatives/sub-01/func/bold.nii.gz"), true) |
| 22 | +}) |
| 23 | + |
| 24 | +Deno.test("shouldIncludeFile() includes .bidsignore", () => { |
| 25 | + assertEquals(shouldIncludeFile(".bidsignore"), true) |
| 26 | +}) |
| 27 | + |
| 28 | +Deno.test("shouldIncludeFile() skips root hidden files and directories", () => { |
| 29 | + assertEquals(shouldIncludeFile(".git/config"), false) |
| 30 | + assertEquals(shouldIncludeFile(".git/annex/objects/abc/def/SHA256--xyz"), false) |
| 31 | + assertEquals(shouldIncludeFile(".datalad/config"), false) |
| 32 | + assertEquals(shouldIncludeFile(".gitattributes"), false) |
| 33 | +}) |
| 34 | + |
| 35 | +Deno.test("shouldIncludeFile() skips hidden files/dirs in submodules", () => { |
| 36 | + // .git directories |
| 37 | + assertEquals( |
| 38 | + shouldIncludeFile("derivatives/.git/annex/objects/abc/def/SHA256--xyz"), |
| 39 | + false, |
| 40 | + ) |
| 41 | + assertEquals(shouldIncludeFile("derivatives/.git/config"), false) |
| 42 | + assertEquals(shouldIncludeFile("sourcedata/.git/HEAD"), false) |
| 43 | + assertEquals( |
| 44 | + shouldIncludeFile("derivatives/preprocessing/.git/annex/objects/xx/yy/key"), |
| 45 | + false, |
| 46 | + ) |
| 47 | + // Deeper nested paths |
| 48 | + assertEquals( |
| 49 | + shouldIncludeFile("derivatives/qa/.git/annex/objects/Xk/Mx/SHA256--abc"), |
| 50 | + false, |
| 51 | + ) |
| 52 | + assertEquals( |
| 53 | + shouldIncludeFile("derivatives/fmriprep/sub-01/.datalad/config"), |
| 54 | + false, |
| 55 | + ) |
| 56 | + // .datalad directories |
| 57 | + assertEquals(shouldIncludeFile("derivatives/.datalad/config"), false) |
| 58 | + assertEquals(shouldIncludeFile("sourcedata/.datalad/metadata/aggregate_v1.json"), false) |
| 59 | + // Other hidden files in submodules |
| 60 | + assertEquals(shouldIncludeFile("derivatives/.gitattributes"), false) |
| 61 | + assertEquals(shouldIncludeFile("sourcedata/.gitignore"), false) |
| 62 | +}) |
| 63 | + |
| 64 | +Deno.test("shouldIncludeFile() includes symlinks in submodules", () => { |
| 65 | + // Symlinks themselves don't have .git in their path |
| 66 | + // They point to .git/annex/objects but the path we check is the symlink location |
| 67 | + assertEquals(shouldIncludeFile("derivatives/sub-01/anat/sub-01_T1w.nii.gz"), true) |
| 68 | +}) |
0 commit comments