| 70 | } |
| 71 | |
| 72 | func TestPatternMatch(t *testing.T) { |
| 73 | for testNumber, test := range []struct { |
| 74 | // input |
| 75 | root string |
| 76 | itemPath string |
| 77 | isFile bool |
| 78 | // expected output |
| 79 | wantMatch []string |
| 80 | wantPrefix string |
| 81 | wantPattern *dirPattern |
| 82 | }{ |
| 83 | { |
| 84 | root: "", |
| 85 | itemPath: "", |
| 86 | isFile: false, |
| 87 | wantMatch: []string{""}, |
| 88 | wantPrefix: "", |
| 89 | wantPattern: &patterns[0], |
| 90 | }, |
| 91 | { |
| 92 | root: "", |
| 93 | itemPath: "", |
| 94 | isFile: true, |
| 95 | wantMatch: nil, |
| 96 | wantPrefix: "", |
| 97 | wantPattern: nil, |
| 98 | }, |
| 99 | { |
| 100 | root: "upload", |
| 101 | itemPath: "", |
| 102 | isFile: false, |
| 103 | wantMatch: []string{"upload", ""}, |
| 104 | wantPrefix: "", |
| 105 | wantPattern: &patterns[1], |
| 106 | }, |
| 107 | { |
| 108 | root: "upload/dir", |
| 109 | itemPath: "", |
| 110 | isFile: false, |
| 111 | wantMatch: []string{"upload/dir", "dir"}, |
| 112 | wantPrefix: "", |
| 113 | wantPattern: &patterns[1], |
| 114 | }, |
| 115 | { |
| 116 | root: "upload/file.jpg", |
| 117 | itemPath: "", |
| 118 | isFile: true, |
| 119 | wantMatch: []string{"upload/file.jpg", "file.jpg"}, |
| 120 | wantPrefix: "", |
| 121 | wantPattern: &patterns[2], |
| 122 | }, |
| 123 | { |
| 124 | root: "media", |
| 125 | itemPath: "", |
| 126 | isFile: false, |
| 127 | wantMatch: []string{"media"}, |
| 128 | wantPrefix: "", |
| 129 | wantPattern: &patterns[3], |